我习惯于测试这样的建筑物:
describe "post to refund first time" do
it "should have 1 refund" do
post :refund
Refund.count.should == 1
end
describe "post to refund 2nd time" do
it "should have 2 refunds" do
post :refund
Refund.count.should == 1
end
end
end
除了规范2失败,Refund.count
只有1.我插入binding.pry
,确实从内存中清除了第一笔退款。这是Rspec控制器测试的正常行为还是我做错了什么?
答案 0 :(得分:0)
确实Rails和RSpec在每次运行时重置数据库。为了让你的测试工作,你必须真正击中端点2次:
describe "post to refund first time" do
it "should have 1 refund" do
post :refund
Refund.count.should == 1
end
describe "post to refund 2nd time" do
it "should have 2 refunds" do
2.times { post :refund }
Refund.count.should == 2
end
end
end