Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve RSpec/SubjectStub cop #770

Merged
merged 10 commits into from Jun 10, 2019

Improve offence message for SubjectStub

Addresses concerns expressed in #705
  • Loading branch information...
pirj committed May 15, 2019
commit c7d7ea7e862bca4c2878126dd9e33237f7c3ab3a
@@ -20,7 +20,7 @@ module RSpec
class SubjectStub < Cop
include RuboCop::RSpec::TopLevelDescribe

MSG = 'Do not stub your test subject.'
MSG = 'Do not stub methods of the object under test.'

# @!method subject(node)
# Find a named or unnamed subject definition
@@ -10,7 +10,7 @@
before do
allow(foo).to receive(:bar).and_return(baz)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub your test subject.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
end
it 'uses expect twice' do
@@ -27,13 +27,13 @@
before do
expect(foo).to receive(:bar).and_return(baz)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub your test subject.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
expect(foo).to receive(:bar)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub your test subject.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
expect(foo).to receive(:bar).with(1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub your test subject.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
expect(foo).to receive(:bar).with(1).and_return(2)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub your test subject.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
end
it 'uses expect twice' do
@@ -50,7 +50,7 @@
it 'uses one-line expectation syntax' do
is_expected.to receive(:bar)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub your test subject.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
end
end
RUBY
@@ -93,7 +93,7 @@
before do
allow(foo).to receive(:wow)
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub your test subject.
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
end
it 'tries to trick rubocop-rspec' do
@@ -132,7 +132,7 @@
context 'when I shake things up' do
before do
allow(foo).to receive(:wow)
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub your test subject.
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
end
it 'tries to trick rubocop-rspec' do
@@ -154,7 +154,7 @@
before do
allow(foo).to receive(:wow)
allow(bar).to receive(:wow)
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub your test subject.
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
end
it 'tries to trick rubocop-rspec' do
@@ -176,7 +176,7 @@
it 'still flags this test' do
allow(foo).to receive(:blah)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub your test subject.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
end
end
RUBY
@@ -197,7 +197,7 @@
allow(foo).to receive(:wow)
allow(bar).to receive(:wow)
allow(baz).to receive(:wow)
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub your test subject.
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
end
end
end
@@ -212,9 +212,9 @@
specify do
expect(foo).not_to receive(:bar)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub your test subject.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
expect(foo).to_not receive(:bar)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub your test subject.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
expect(foo.bar).to eq(baz)
end
end
@@ -228,7 +228,7 @@
specify do
expect(foo).to receive_messages(bar: :baz, baz: :baz)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub your test subject.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
expect(foo.bar).to eq(baz)
end
end
@@ -242,7 +242,7 @@
specify do
expect(foo).to receive_message_chain(:bar, baz: :baz)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub your test subject.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
expect(foo.bar.baz).to eq(baz)
end
end
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.