下面是主项目的 rspec 中的控制器代码。
坦率地说,我对 Ruby 很陌生,对编码有一点了解。
require 'spec_helper'
describe PayrollItemsController , "with valid params" do
before(:each) do
@payroll_item = mock_model(PayrollItem, :update_attributes => true)
PayrollItem.stub!(:find).with("1").and_return(@payroll_item)
end
it "should find PayrollItem and return object" do
PayrollItem.should_receive(:find).with("0").and_return(@payroll_item)
end
it "should update the PayrollItem object's attributes" do
@payroll_item.should_receive(:update_attributes).and_return(true)
end
end
当我运行控制器代码时,显示以下错误:
(Mock "PayrollItem_1001").update_attributes(any args)
expected: 1 time
received: 0 times
./payroll_items_controller_spec.rb:18:in `block (2 levels) in '