File tree Expand file tree Collapse file tree 3 files changed +17
-1
lines changed Expand file tree Collapse file tree 3 files changed +17
-1
lines changed Original file line number Diff line number Diff line change 33## Master (Unreleased)
44
55* Fix documentation rake task to support Rubocop 0.75. ([ @nickcampbell18 ] [ ] )
6+ * Fix ` RSpec/SubjectStub ` to detect implicit subjects stubbed. ([ @QQism ] [ ] )
67
78## 1.36.0 (2019-09-27)
89
@@ -455,3 +456,4 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
455456[ @nc-holodakg ] : https://github.com/nc-holodakg
456457[ @onumis ] : https://github.com/onumis
457458[ @nickcampbell18 ] : https://github.com/nickcampbell18
459+ [ @QQism ] : https://github.com/QQism
Original file line number Diff line number Diff line change @@ -132,7 +132,10 @@ def redefines_subject?(node)
132132 # @yieldparam subject_name [Symbol] name of subject being defined
133133 # @yieldparam parent [RuboCop::Node] parent of subject definition
134134 def find_subject ( node , parent : nil , &block )
135- subject ( node ) { |name | yield ( name , parent ) }
135+ # An implicit subject is defined by RSpec when no subject is declared
136+ subject_name = subject ( node ) || :subject
137+
138+ yield ( subject_name , parent ) if parent
136139
137140 node . each_child_node do |child |
138141 find_subject ( child , parent : node , &block )
Original file line number Diff line number Diff line change 290290 end
291291 RUBY
292292 end
293+
294+ it 'flags when an implicit subject is mocked' do
295+ expect_offense ( <<-RUBY )
296+ describe Foo do
297+ it 'uses an implicit subject' do
298+ expect(subject).to receive(:bar).and_return(baz)
299+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
300+ end
301+ end
302+ RUBY
303+ end
293304end
You can’t perform that action at this time.
0 commit comments