2020-07-27 08:09:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'fast_spec_helper'
|
|
|
|
require_relative '../../../rubocop/cop/avoid_becomes'
|
|
|
|
|
2021-01-07 13:10:38 -05:00
|
|
|
RSpec.describe RuboCop::Cop::AvoidBecomes do
|
2020-07-27 08:09:50 -04:00
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
|
|
|
it 'flags the use of becomes with a constant parameter' do
|
2021-01-26 13:09:30 -05:00
|
|
|
expect_offense(<<~CODE)
|
|
|
|
foo.becomes(Project)
|
|
|
|
^^^^^^^^^^^^^^^^^^^^ Avoid the use of becomes(SomeConstant), [...]
|
|
|
|
CODE
|
2020-07-27 08:09:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'flags the use of becomes with a namespaced constant parameter' do
|
2021-01-26 13:09:30 -05:00
|
|
|
expect_offense(<<~CODE)
|
|
|
|
foo.becomes(Namespace::Group)
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid the use of becomes(SomeConstant), [...]
|
|
|
|
CODE
|
2020-07-27 08:09:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'flags the use of becomes with a dynamic parameter' do
|
2021-01-26 13:09:30 -05:00
|
|
|
expect_offense(<<~CODE)
|
|
|
|
model = Namespace
|
|
|
|
project = Project.first
|
|
|
|
project.becomes(model)
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^ Avoid the use of becomes(SomeConstant), [...]
|
|
|
|
CODE
|
2020-07-27 08:09:50 -04:00
|
|
|
end
|
|
|
|
end
|