Commit 19ebb829 authored by Doug Stull's avatar Doug Stull Committed by Rémy Coutable

Add danger missing test coverage

- for 100% coverage
parent a44bf93d
...@@ -114,15 +114,11 @@ module Gitlab ...@@ -114,15 +114,11 @@ module Gitlab
end end
details&.each_line do |line| details&.each_line do |line|
line = line.strip line_without_urls = line.strip.gsub(%r{https?://\S+}, '')
next unless line_too_long?(line)
url_size = line.scan(%r((https?://\S+))).sum { |(url)| url.length }
# If the line includes a URL, we'll allow it to exceed MAX_LINE_LENGTH characters, but # If the line includes a URL, we'll allow it to exceed MAX_LINE_LENGTH characters, but
# only if the line _without_ the URL does not exceed this limit. # only if the line _without_ the URL does not exceed this limit.
next unless line_too_long?(line.length - url_size) next unless line_too_long?(line_without_urls)
add_problem(:details_line_too_long) add_problem(:details_line_too_long)
break break
...@@ -172,14 +168,7 @@ module Gitlab ...@@ -172,14 +168,7 @@ module Gitlab
end end
def line_too_long?(line) def line_too_long?(line)
case line line.length > MAX_LINE_LENGTH
when String
line.length > MAX_LINE_LENGTH
when Integer
line > MAX_LINE_LENGTH
else
raise ArgumentError, "The line argument (#{line}) should be a String or an Integer! #{line.class} given."
end
end end
def subject_too_short? def subject_too_short?
......
...@@ -64,7 +64,7 @@ module Gitlab ...@@ -64,7 +64,7 @@ module Gitlab
# - respond_to?(:gitlab) # - respond_to?(:gitlab)
# - respond_to?(:gitlab, true) # - respond_to?(:gitlab, true)
gitlab gitlab
rescue NoMethodError rescue NameError
nil nil
end end
......
...@@ -300,8 +300,10 @@ RSpec.describe Gitlab::Danger::CommitLinter do ...@@ -300,8 +300,10 @@ RSpec.describe Gitlab::Danger::CommitLinter do
end end
end end
context 'when details exceeds the max line length including a URL' do context 'when details exceeds the max line length including URLs' do
let(:commit_message) { "A B C\n\nhttps://gitlab.com" + 'D' * described_class::MAX_LINE_LENGTH } let(:commit_message) do
"A B C\n\nsome message with https://example.com and https://gitlab.com" + 'D' * described_class::MAX_LINE_LENGTH
end
it_behaves_like 'a valid commit' it_behaves_like 'a valid commit'
end end
......
...@@ -33,6 +33,16 @@ RSpec.describe Gitlab::Danger::Helper do ...@@ -33,6 +33,16 @@ RSpec.describe Gitlab::Danger::Helper do
expect(helper.gitlab_helper).to eq(fake_gitlab) expect(helper.gitlab_helper).to eq(fake_gitlab)
end end
end end
context 'when danger gitlab plugin is not available' do
it 'returns nil' do
invalid_danger = Class.new do
include Gitlab::Danger::Helper
end.new
expect(invalid_danger.gitlab_helper).to be_nil
end
end
end end
describe '#release_automation?' do describe '#release_automation?' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment