这个默认的 RSpec 语句是什么意思?

发布于 2024-09-18 21:11:54 字数 572 浏览 6 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鹤舞 2024-09-25 21:11:55

也就是说,应该在 User 模型上调用 update_attributes 方法,参数为 {'these' =>; 'params'} 在任何测试运行期间。

基本上,在执行过程中预计会发生以下情况:

User.update_attributes({'these' => 'params'})

更多信息: http://rspec.info/文档/mocks/message_expectations.html

It is saying that the method update_attributes should be invoked on the User model with an argument of {'these' => 'params'} during whatever test is being run.

Basically the following is expected to happen during the execution:

User.update_attributes({'these' => 'params'})

More here: http://rspec.info/documentation/mocks/message_expectations.html

反目相谮 2024-09-25 21:11:55

您不必替换散列({'这些' => '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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文