Skip to content

Commit

Permalink
Pick "use subject" rule from betterspecs
Browse files Browse the repository at this point in the history
  • Loading branch information
andreareginato authored and pirj committed Nov 7, 2018
1 parent 2e20a2f commit f13c341
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,23 @@ meant to be able to change with it.
let(:article) { FactoryBot.create(:article) }
```
* <a name="subject"></a>
When several tests relate to the same subject, use `subject` to reduce
repetition.
<sup>[[link](#subject)]</sup>
```ruby
# bad
it { expect(hero.equipment).to be_heavy }
it { expect(hero.equipment).to include 'sword' }
# good
subject(:equipment) { hero.equipment }
it { expect(equipment).to be_heavy }
it { expect(equipment).to include 'sword' }
```
* <a name="use-subject"></a>
Use named `subject` when possible. Only use anonymous subject declaration
when you don't reference it in any tests, e.g. when `is_expected` is used.
Expand Down

0 comments on commit f13c341

Please sign in to comment.