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
end
details&.each_line do |line|
line = line.strip
next unless line_too_long?(line)
url_size = line.scan(%r((https?://\S+))).sum { |(url)| url.length }
line_without_urls = line.strip.gsub(%r{https?://\S+}, '')
# 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.
next unless line_too_long?(line.length - url_size)
next unless line_too_long?(line_without_urls)
add_problem(:details_line_too_long)
break
......@@ -172,14 +168,7 @@ module Gitlab
end
def line_too_long?(line)
case line
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
def subject_too_short?
......
......@@ -64,7 +64,7 @@ module Gitlab
# - respond_to?(:gitlab)
# - respond_to?(:gitlab, true)
gitlab
rescue NoMethodError
rescue NameError
nil
end
......
......@@ -300,8 +300,10 @@ RSpec.describe Gitlab::Danger::CommitLinter do
end
end
context 'when details exceeds the max line length including a URL' do
let(:commit_message) { "A B C\n\nhttps://gitlab.com" + 'D' * described_class::MAX_LINE_LENGTH }
context 'when details exceeds the max line length including URLs' do
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'
end
......
......@@ -33,6 +33,16 @@ RSpec.describe Gitlab::Danger::Helper do
expect(helper.gitlab_helper).to eq(fake_gitlab)
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
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