Last active
May 20, 2019 23:12
-
-
Save pirj/810a918e74e74ff9224c471e834ab34a to your computer and use it in GitHub Desktop.
Modified version of the `lib/rubocop/cop/rspec/subject_stub.rb` cop to detect `expect(subject).to all receive(...)` syntax only
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def_node_matcher :message_expectation?, <<-PATTERN | |
(send | |
{ | |
(send nil? { :expect :allow } (send nil? %)) | |
(send nil? :is_expected) | |
} | |
#{Runners::ALL.node_pattern_union} | |
#all_matcher? | |
) | |
PATTERN | |
def_node_search :all_matcher?, <<-PATTERN | |
(send nil? :all #message_expectation_matcher?) | |
PATTERN | |
def_node_search :message_expectation_matcher?, <<-PATTERN | |
(send nil? { | |
:receive :receive_messages :receive_message_chain :have_received | |
} ... ) | |
PATTERN |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.describe 'a' do | |
subject(:a) {} | |
it { expect(a).to all receive(:b) } | |
it { expect(a).to all receive(:b).with(1) } | |
it { expect(a).to all receive(:b).with(1).and_sdfsd { 1 } } | |
it { expect(a).to receive(:c) } | |
it { expect(a).to receive(:b).with(1).and_sdfsd { 1 } } | |
end | |
spec/a_spec.rb:4:8: C: RSpec/SubjectStub: Do not stub methods of the object under test. | |
it { expect(a).to all receive(:b) } | |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
spec/a_spec.rb:5:8: C: RSpec/SubjectStub: Do not stub methods of the object under test. | |
it { expect(a).to all receive(:b).with(1) } | |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
spec/a_spec.rb:6:8: C: RSpec/SubjectStub: Do not stub methods of the object under test. | |
it { expect(a).to all receive(:b).with(1).and_sdfsd { 1 } } | |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment