Skip to content

Instantly share code, notes, and snippets.

@fabiokr
Created July 9, 2012 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiokr/3078157 to your computer and use it in GitHub Desktop.
Save fabiokr/3078157 to your computer and use it in GitHub Desktop.
# Current version
# - before block runs before each example
# - isolated examples
describe "GET show" do
before do
@customer = create_customer
get :show, id: @customer.id
end
it { should respond_with(:success) }
it { should render_template(:show) }
it { should assign_to(:customer).with(@customer) }
end
# Proposal
# - before block runs once - for customer controller spec
# time went from 8 to 3 seconds
describe "GET show" do
before do
@customer = create_customer
get :show, id: @customer.id
end
it "is successfull" do
subject.should respond_with(:success)
subject.should render_template(:show)
subject.should assign_to(:customer).with(@customer)
end
end
@tfwright
Copy link

tfwright commented Jul 9, 2012

I don't like this. Having multiple assertions speeds up tests, but it also makes fixing fails/error more difficult, because they cascade and mix state

@jmazzi
Copy link

jmazzi commented Jul 9, 2012

I prefer the format of the top example. There would need to be a > 30% average speed increase for me to really consider changing everything.

@itspriddle
Copy link

I agree with @tfwright and @jmazzi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment