我很确定我可以让这个测试变得更干净,我到处都在找,但就是不能破解它。测试通过了,但我想重构一下。
describe "as an authenticated user that made the offer" do
    before { log_in offering_user; }
    specify { expect { delete :destroy, id: offer.id }.to change(Offer, :count).by(-1) }
    describe "redirect and flash" do
      before { delete :destroy, id: offer.id }
      specify { response.should redirect_to item_path(offer.receiving_item) }
      specify { flash[:success].should_not be_nil }
    end
end看到我如何在规范中提出两次请求了吗?这也迫使我使用另一个describe代码块。理想情况下,我可以只在第一个before块中发出请求,并拥有类似以下内容的内容
it { should change(Offer, :count).by(-1) }有谁能给我指个方向吗?谢谢。
发布于 2013-05-29 19:12:33
为了通过lambda表示法使用隐式主题,您可以执行以下操作:
describe "as an authenticated user that made the offer" do
  before { log_in offering_user }
  subject { -> { delete :destroy, id: offer.id } }
  it { should change {Offer.count}.by(-1) }
end我还不知道如何让这个测试变得枯燥:)
https://stackoverflow.com/questions/16804547
复制相似问题