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.

54 lines
1.5 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2022-10-11 01:57:18 +05:30
require 'rubocop_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
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