From 92685abb758d1e6895cee835957e502a96112159 Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Thu, 25 Oct 2018 14:27:52 +0300 Subject: [PATCH] Relax "one expectation per example" rule With the [introduction of `aggregate_failures` feature in RSpec 3.3](http://rspec.info/blog/2015/06/rspec-3-3-has-been-released/) there are no strong arguments left to stick to the strict style, as the output remains the same, while context initialization costs are reduced. Closes #11 --- README.md | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 18ca676..4b66bc6 100644 --- a/README.md +++ b/README.md @@ -281,43 +281,46 @@ meant to be able to change with it. ## Example Structure - * - 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. - [[link](#one-expectation)] + * + 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. + [[link](#expectations-per-example)] ```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 ```