Skip to content

Commit

Permalink
Merge pull request #1102 from cesc1989/subjectstub-examples
Browse files Browse the repository at this point in the history
Add clearer examples for SubjectStub cop
  • Loading branch information
pirj authored Dec 1, 2020
2 parents df1fa3d + 1684470 commit 11b1fa4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
18 changes: 14 additions & 4 deletions docs/modules/ROOT/pages/cops_rspec.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3822,11 +3822,21 @@ Checks for stubbed test subjects.
[source,ruby]
----
# bad
describe Foo do
subject(:bar) { baz }
describe Article do
subject(:article) { Article.new }
before do
allow(bar).to receive(:qux?).and_return(true)
it 'indicates that the author is unknown' do
allow(article).to receive(:author).and_return(nil)
expect(article.description).to include('by an unknown author')
end
end
# good
describe Article do
subject(:article) { Article.new(author: nil) }
it 'indicates that the author is unknown' do
expect(article.description).to include('by an unknown author')
end
end
----
Expand Down
18 changes: 14 additions & 4 deletions lib/rubocop/cop/rspec/subject_stub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ module RSpec
#
# @example
# # bad
# describe Foo do
# subject(:bar) { baz }
# describe Article do
# subject(:article) { Article.new }
#
# before do
# allow(bar).to receive(:qux?).and_return(true)
# it 'indicates that the author is unknown' do
# allow(article).to receive(:author).and_return(nil)
# expect(article.description).to include('by an unknown author')
# end
# end
#
# # good
# describe Article do
# subject(:article) { Article.new(author: nil) }
#
# it 'indicates that the author is unknown' do
# expect(article.description).to include('by an unknown author')
# end
# end
#
Expand Down

0 comments on commit 11b1fa4

Please sign in to comment.