这个默认的 RSpec 语句是什么意思?
User.should_receive(:update_attributes).with({'these' => 'params'})
这句话是什么意思? 这些
没有在任何地方实例化为任何意义。
整个声明是这样的:
describe "with valid params" do
it "updates the requested user" do
User.should_receive(:find).with("37") { mock_user }
User.should_receive(:update_attributes).with({'these' => 'params'})
put :update, :id => "37", :user => {'these' => 'params'}
end
我这样说是因为我收到一个错误:
unknown attribute: these
这是来自上述场景的..
User.should_receive(:update_attributes).with({'these' => 'params'})
What does that statement mean? these
isn't instantiated anywhere as meaning anything.
The whole statement is this :
describe "with valid params" do
it "updates the requested user" do
User.should_receive(:find).with("37") { mock_user }
User.should_receive(:update_attributes).with({'these' => 'params'})
put :update, :id => "37", :user => {'these' => 'params'}
end
I say this because I'm getting an error :
unknown attribute: these
Which is coming from aforementioned scenario..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也就是说,应该在
User
模型上调用update_attributes
方法,参数为{'these' =>; 'params'}
在任何测试运行期间。基本上,在执行过程中预计会发生以下情况:
更多信息: http://rspec.info/文档/mocks/message_expectations.html
It is saying that the method
update_attributes
should be invoked on theUser
model with an argument of{'these' => 'params'}
during whatever test is being run.Basically the following is expected to happen during the execution:
More here: http://rspec.info/documentation/mocks/message_expectations.html
您不必替换散列({'这些' => 'params'})。将其视为合同。我说过,当我 PUT 时,我的对象 update_attributes 模型应该接收以下哈希。在下一行中,您调用更新方法并检查合约。
You don't have to replace the hash ({'these' => 'params'}). Think of it as a contract. I have said that when I PUT, the following hash should be received by my objects update_attributes model. In the next line, you call the update method and the contract is checked.