2010-09-09 99 views
4
User.should_receive(:update_attributes).with({'these' => 'params'}) 

那声明是什么意思? these在任何地方都没有被实例化为任何含义。这个默认的RSpec语句是什么意思?

整个声明是这样的:

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 

这是从上述情景来..

回答

3

跟它应在0​​模型上调用方法update_attributes,在运行任何测试期间,参数为{'these' => 'params'}

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

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

这里更多:http://rspec.info/documentation/mocks/message_expectations.html

+0

对,但是这些是什么和什么是参数? – Trip 2010-09-09 00:30:10

+2

这只是一个示例散列。你可以用你的控制器所期望的来代替它。例如,你可能正在更新用户的名字,所以它会是'with({:first_name =>“something”,:last_name =>“else”})' – 2010-09-09 00:43:54

0

您不必更换哈希({ '这些'=> 'PARAMS'} )。把它看作合同。我曾经说过,当我PUT时,我的对象update_attributes模型应该会收到下面的哈希值。在下一行中,您调用更新方法并检查合同。