The Whiz of Oz
The Whiz of Oz

Reputation: 7043

Refactoring this RSpec bit of code to new syntax

How would you go with refactoring this piece of test-code using the 3.0 RSpec 'expect' syntax?

it "should destroy the micropost" do
  lambda do
    delete :destroy, :id => @micropost
    flash[:success].should =~ /deleted/i
    response.should redirect_to(root_path)
  end.should change(Micropost, :count).by(-1)
end

Upvotes: 0

Views: 43

Answers (1)

Uri Agassi
Uri Agassi

Reputation: 37409

it "destroys the micropost" do
  expect {
    delete :destroy, :id => @micropost
    expect(flash[:success]).to match /deleted/i
    expect(response).to redirect_to(root_path)
  }.to change(Micropost, :count).by(-1)
end

sources: redirect_to, match and change

Upvotes: 2

Related Questions