Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.
© Copyright 2013, Eleutian Technology
E-mail
Mikel Lindsaar recently posted a tip encouraging rSpec users to not use before :each, and set up the context in every "it" specification.
I'm afraid I disagree. By pushing context setup into your specifications, you're allowing your contexts to become artificial and anemic and your specifications to become fat and more than just specifications. Ultimately, this means that your reports will read poorly and it will be easy to introduce specifications in a context that do not match the others.Mikel arrives at the following specs at the end of his post:
describe "when not logged in" do it "should redirect if we are not logged in" do get :index response.should redirect_to login_path end end describe "when logged in" do def given_a_logged_in_user session[:logged_in] = true session[:user_id] = 99 end it "should let be a success" do given_a_logged_in_user get :index response.should be_success end it "should render the index template" do given_a_logged_in_user get :index response.should render_template('people/index') end end