我正在使用主要是脚手架生成的 RSpec 规范,它失败但不应该。这是规格:
describe "PUT update" do
describe "with valid params" do
it "updates the requested invoice" do
invoice = Invoice.create!
Invoice.any_instance.should_receive(:update_attributes).with({"number" => "MyString" })
put :update, {:id => invoice.id, :invoice => { "number" => "MyString" }}
end
运行规范时,会在数据库中创建一张发票,并进行适当更新。但是,我收到此消息并且失败:
RSpec::Mocks::MockExpectationError: (#<Mocha::ClassMethods::AnyInstance:0x653a9a8>).update_attributes({"number"=>"MyString"})
expected: 1 time with arguments: ({"number"=>"MyString"})
received: 0 times with arguments: ({"number"=>"MyString"})
为什么会失败?