diff options
Diffstat (limited to 'spec/rubocop/cop/gitlab/finder_with_find_by_spec.rb')
-rw-r--r-- | spec/rubocop/cop/gitlab/finder_with_find_by_spec.rb | 49 |
1 files changed, 14 insertions, 35 deletions
diff --git a/spec/rubocop/cop/gitlab/finder_with_find_by_spec.rb b/spec/rubocop/cop/gitlab/finder_with_find_by_spec.rb index db3bcf1dfdb..03d7fc5e8b1 100644 --- a/spec/rubocop/cop/gitlab/finder_with_find_by_spec.rb +++ b/spec/rubocop/cop/gitlab/finder_with_find_by_spec.rb @@ -1,46 +1,31 @@ # frozen_string_literal: true require 'fast_spec_helper' - require 'rubocop' -require 'rubocop/rspec/support' require_relative '../../../../rubocop/cop/gitlab/finder_with_find_by' RSpec.describe RuboCop::Cop::Gitlab::FinderWithFindBy do - include CopHelper - subject(:cop) { described_class.new } context 'when calling execute.find' do - let(:source) do - <<~SRC - DummyFinder.new(some_args) - .execute - .find_by!(1) - SRC - end - - let(:corrected_source) do - <<~SRC - DummyFinder.new(some_args) - .find_by!(1) - SRC - end - - it 'registers an offence' do - inspect_source(source) - - expect(cop.offenses.size).to eq(1) - end - - it 'can autocorrect the source' do - expect(autocorrect_source(source)).to eq(corrected_source) + it 'registers an offense and corrects' do + expect_offense(<<~CODE) + DummyFinder.new(some_args) + .execute + .find_by!(1) + ^^^^^^^^ Don't chain finders `#execute` method with [...] + CODE + + expect_correction(<<~CODE) + DummyFinder.new(some_args) + .find_by!(1) + CODE end context 'when called within the `FinderMethods` module' do - let(:source) do - <<~SRC + it 'does not register an offense' do + expect_no_offenses(<<~SRC) module FinderMethods def find_by!(*args) execute.find_by!(args) @@ -48,12 +33,6 @@ RSpec.describe RuboCop::Cop::Gitlab::FinderWithFindBy do end SRC end - - it 'does not register an offence' do - inspect_source(source) - - expect(cop.offenses).to be_empty - end end end end |