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

Add detection of negated runners

Fixes #705
  • Loading branch information...
pirj committed May 15, 2019
commit 393278c83cedf342b04779d9a1a2268b9ae08c70
@@ -65,7 +65,7 @@ class SubjectStub < Cop
(send nil? { :expect :allow } (send nil? %))
(send nil? :is_expected)
}
:to
#{Runners::ALL.node_pattern_union}
#expectation?
)
PATTERN
@@ -204,4 +204,20 @@
end
RUBY
end

it 'flags negated runners' do
expect_offense(<<-RUBY)
describe Foo do
subject(:foo) { described_class.new }
specify do
expect(foo).not_to receive(:bar)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub your test subject.
expect(foo).to_not receive(:bar)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub your test subject.
expect(foo.bar).to eq(baz)
end
end
RUBY
end
end
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.