4
User.should_receive(:update_attributes).with({'these' => 'params'})

那句话是什么意思?these没有在任何地方实例化为任何意义。

整个声明是这样的:

  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

这来自上述情况..

4

2 回答 2

3

update_attributes意思是应该在模型上调用该方法,并在运行任何测试期间User使用参数。{'these' => 'params'}

基本上,在执行期间预计会发生以下情况:

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

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

于 2010-09-09T00:23:31.837 回答
0

您不必替换散列 ({'these' => 'params'})。把它想象成一份合同。我说过,当我 PUT 时,我的对象 update_attributes 模型应该接收到以下哈希。在下一行中,您调用更新方法并检查合同。

于 2012-06-11T10:17:22.157 回答