diff options
Diffstat (limited to 'spec/rubocop/cop/rspec/any_instance_of_spec.rb')
-rw-r--r-- | spec/rubocop/cop/rspec/any_instance_of_spec.rb | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/spec/rubocop/cop/rspec/any_instance_of_spec.rb b/spec/rubocop/cop/rspec/any_instance_of_spec.rb index 42bb7d196a1..e7675ded25e 100644 --- a/spec/rubocop/cop/rspec/any_instance_of_spec.rb +++ b/spec/rubocop/cop/rspec/any_instance_of_spec.rb @@ -5,59 +5,51 @@ require 'fast_spec_helper' require_relative '../../../../rubocop/cop/rspec/any_instance_of' RSpec.describe RuboCop::Cop::RSpec::AnyInstanceOf do - include CopHelper - subject(:cop) { described_class.new } context 'when calling allow_any_instance_of' do let(:source) do <<~SRC - allow_any_instance_of(User).to receive(:invalidate_issue_cache_counts) + allow_any_instance_of(User).to receive(:invalidate_issue_cache_counts) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use `allow_any_instance_of` [...] SRC end let(:corrected_source) do <<~SRC - allow_next_instance_of(User) do |instance| - allow(instance).to receive(:invalidate_issue_cache_counts) - end + allow_next_instance_of(User) do |instance| + allow(instance).to receive(:invalidate_issue_cache_counts) + end SRC end - it 'registers an offence' do - inspect_source(source) - - expect(cop.offenses.size).to eq(1) - end + it 'registers an offense and corrects', :aggregate_failures do + expect_offense(source) - it 'can autocorrect the source' do - expect(autocorrect_source(source)).to eq(corrected_source) + expect_correction(corrected_source) end end context 'when calling expect_any_instance_of' do let(:source) do <<~SRC - expect_any_instance_of(User).to receive(:invalidate_issue_cache_counts).with(args).and_return(double) + expect_any_instance_of(User).to receive(:invalidate_issue_cache_counts).with(args).and_return(double) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use `expect_any_instance_of` [...] SRC end let(:corrected_source) do <<~SRC - expect_next_instance_of(User) do |instance| - expect(instance).to receive(:invalidate_issue_cache_counts).with(args).and_return(double) - end + expect_next_instance_of(User) do |instance| + expect(instance).to receive(:invalidate_issue_cache_counts).with(args).and_return(double) + end SRC end - it 'registers an offence' do - inspect_source(source) - - expect(cop.offenses.size).to eq(1) - end + it 'registers an offense and corrects', :aggregate_failures do + expect_offense(source) - it 'can autocorrect the source' do - expect(autocorrect_source(source)).to eq(corrected_source) + expect_correction(corrected_source) end end end |