Skip to content

Commit 11b1fa4

Browse files
authored
Merge pull request #1102 from cesc1989/subjectstub-examples
Add clearer examples for SubjectStub cop
2 parents df1fa3d + 1684470 commit 11b1fa4

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

docs/modules/ROOT/pages/cops_rspec.adoc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3822,11 +3822,21 @@ Checks for stubbed test subjects.
38223822
[source,ruby]
38233823
----
38243824
# bad
3825-
describe Foo do
3826-
subject(:bar) { baz }
3825+
describe Article do
3826+
subject(:article) { Article.new }
38273827
3828-
before do
3829-
allow(bar).to receive(:qux?).and_return(true)
3828+
it 'indicates that the author is unknown' do
3829+
allow(article).to receive(:author).and_return(nil)
3830+
expect(article.description).to include('by an unknown author')
3831+
end
3832+
end
3833+
3834+
# good
3835+
describe Article do
3836+
subject(:article) { Article.new(author: nil) }
3837+
3838+
it 'indicates that the author is unknown' do
3839+
expect(article.description).to include('by an unknown author')
38303840
end
38313841
end
38323842
----

lib/rubocop/cop/rspec/subject_stub.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,21 @@ module RSpec
1313
#
1414
# @example
1515
# # bad
16-
# describe Foo do
17-
# subject(:bar) { baz }
16+
# describe Article do
17+
# subject(:article) { Article.new }
1818
#
19-
# before do
20-
# allow(bar).to receive(:qux?).and_return(true)
19+
# it 'indicates that the author is unknown' do
20+
# allow(article).to receive(:author).and_return(nil)
21+
# expect(article.description).to include('by an unknown author')
22+
# end
23+
# end
24+
#
25+
# # good
26+
# describe Article do
27+
# subject(:article) { Article.new(author: nil) }
28+
#
29+
# it 'indicates that the author is unknown' do
30+
# expect(article.description).to include('by an unknown author')
2131
# end
2232
# end
2333
#

0 commit comments

Comments
 (0)