1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
# frozen_string_literal: true
require 'fast_spec_helper'
require 'gitlab/dangerfiles/spec_helper'
require_relative '../../../tooling/danger/outdated_todo'
RSpec.describe Tooling::Danger::OutdatedTodo, feature_category: :tooling do
let(:fake_danger) { double }
let(:filenames) { ['app/controllers/application_controller.rb'] }
let(:todos) do
[
File.join('spec', 'fixtures', 'tooling', 'danger', 'rubocop_todo', '**', '*.yml'),
File.join('spec', 'fixtures', 'tooling', 'danger', 'rspec_order_todo.yml')
]
end
subject(:plugin) { described_class.new(filenames, context: fake_danger, todos: todos, allow_fail: allow_fail) }
shared_examples 'no warning' do
it 'does not warn' do
expect(fake_danger).not_to receive(expected_method)
plugin.check
end
end
[true, false].each do |allow_failure|
context "with allow_fail set to #{allow_failure}" do
let(:allow_fail) { allow_failure }
let(:expected_method) do
allow_failure ? :fail : :warn
end
context 'when the filenames are mentioned in single todo' do
let(:filenames) { ['app/controllers/acme_challenges_controller.rb'] }
it 'warns about mentions' do
expect(fake_danger)
.to receive(expected_method)
.with <<~MESSAGE
`app/controllers/acme_challenges_controller.rb` was removed but is mentioned in:
- `spec/fixtures/tooling/danger/rubocop_todo/cop1.yml:5`
MESSAGE
plugin.check
end
end
context 'when the filenames are mentioned in multiple todos' do
let(:filenames) do
[
'app/controllers/application_controller.rb',
'app/controllers/acme_challenges_controller.rb',
'ee/app/models/epic.rb'
]
end
it 'warns about mentions' do
expect(fake_danger)
.to receive(expected_method)
.with(<<~MESSAGE)
`app/controllers/application_controller.rb` was removed but is mentioned in:
- `spec/fixtures/tooling/danger/rubocop_todo/cop1.yml:4`
- `spec/fixtures/tooling/danger/rubocop_todo/cop2.yml:4`
MESSAGE
expect(fake_danger)
.to receive(expected_method)
.with(<<~MESSAGE)
`app/controllers/acme_challenges_controller.rb` was removed but is mentioned in:
- `spec/fixtures/tooling/danger/rubocop_todo/cop1.yml:5`
MESSAGE
expect(fake_danger)
.to receive(expected_method)
.with(<<~MESSAGE)
`ee/app/models/epic.rb` was removed but is mentioned in:
- `spec/fixtures/tooling/danger/rubocop_todo/cop1.yml:6`
- `spec/fixtures/tooling/danger/rspec_order_todo.yml:3`
MESSAGE
plugin.check
end
end
context 'when EE filesnames are mentioned in multiple todos' do
let(:filenames) do
[
'app/models/epic.rb'
]
end
it_behaves_like 'no warning'
end
context 'when the filenames are not mentioned in todos' do
let(:filenames) { ['any/inexisting/file.rb'] }
it_behaves_like 'no warning'
end
context 'when there is no todos' do
let(:filenames) { ['app/controllers/acme_challenges_controller.rb'] }
let(:todos) { [] }
it_behaves_like 'no warning'
end
end
end
end
|