debian-mirror-gitlab/spec/rubocop/cop/rspec/any_instance_of_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
1.6 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2020-07-28 23:09:34 +05:30
require 'fast_spec_helper'
2019-12-26 22:10:19 +05:30
require_relative '../../../../rubocop/cop/rspec/any_instance_of'
2021-03-08 18:12:59 +05:30
RSpec.describe RuboCop::Cop::RSpec::AnyInstanceOf do
2019-12-26 22:10:19 +05:30
subject(:cop) { described_class.new }
context 'when calling allow_any_instance_of' do
let(:source) do
<<~SRC
2021-03-11 19:13:27 +05:30
allow_any_instance_of(User).to receive(:invalidate_issue_cache_counts)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use `allow_any_instance_of` [...]
2019-12-26 22:10:19 +05:30
SRC
end
2020-10-24 23:57:45 +05:30
2019-12-26 22:10:19 +05:30
let(:corrected_source) do
<<~SRC
2021-03-11 19:13:27 +05:30
allow_next_instance_of(User) do |instance|
allow(instance).to receive(:invalidate_issue_cache_counts)
end
2019-12-26 22:10:19 +05:30
SRC
end
2021-03-11 19:13:27 +05:30
it 'registers an offense and corrects', :aggregate_failures do
expect_offense(source)
2019-12-26 22:10:19 +05:30
2021-03-11 19:13:27 +05:30
expect_correction(corrected_source)
2019-12-26 22:10:19 +05:30
end
end
context 'when calling expect_any_instance_of' do
let(:source) do
<<~SRC
2021-03-11 19:13:27 +05:30
expect_any_instance_of(User).to receive(:invalidate_issue_cache_counts).with(args).and_return(double)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use `expect_any_instance_of` [...]
2019-12-26 22:10:19 +05:30
SRC
end
2020-10-24 23:57:45 +05:30
2019-12-26 22:10:19 +05:30
let(:corrected_source) do
<<~SRC
2021-03-11 19:13:27 +05:30
expect_next_instance_of(User) do |instance|
expect(instance).to receive(:invalidate_issue_cache_counts).with(args).and_return(double)
end
2019-12-26 22:10:19 +05:30
SRC
end
2021-03-11 19:13:27 +05:30
it 'registers an offense and corrects', :aggregate_failures do
expect_offense(source)
2019-12-26 22:10:19 +05:30
2021-03-11 19:13:27 +05:30
expect_correction(corrected_source)
2019-12-26 22:10:19 +05:30
end
end
end