你会如何使用3.0 RSpec'expect'语法重构这段测试代码?
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
答案 0 :(得分:2)
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