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

Relax "one expectation per example" rule #47

Merged
merged 1 commit into from
Oct 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,43 +281,46 @@ meant to be able to change with it.

## Example Structure

* <a name="one-expectation"></a>
Use only one expectation per example. There are very few scenarios where two
or more expectations in a single `it` block should be used. So, general rule
of thumb is one expectation per `it` block.
<sup>[[link](#one-expectation)]</sup>
* <a name="one-expectation"></a><a name="expectations-per-example"></a>
For examples two styles are considered acceptable. The first variant
is separate example for each expectation, which comes with a cost of
duplicated context initialization. The second variant is multiple
expectations per example with `aggregate_failures` tag set for a
group or example. Use your best judgement in each case, and apply
your strategy consistently.
<sup>[[link](#expectations-per-example)]</sup>

```ruby
# bad
# good - one expectation per example
describe ArticlesController do
#...

describe 'GET new' do
it 'assigns new article and renders the new article template' do
it 'assigns a new article' do
get :new
expect(assigns[:article]).to be_a(Article)
end

it 'renders the new article template' do
get :new
expect(response).to render_template :new
end
end

# ...
end

# good
# good - multiple expectations with aggregated failures
describe ArticlesController do
#...

describe 'GET new' do
it 'assigns a new article' do
describe 'GET new', :aggregate_failures do
it 'assigns new article and renders the new article template' do
get :new
expect(assigns[:article]).to be_a(Article)
end

it 'renders the new article template' do
get :new
expect(response).to render_template :new
end
end

# ...
end
```

Expand Down