我有一个控制器规范正确的参数和我获得以下失败的期望:什么是对我的存根rspec的PUT请求
Failure/Error: put :update, :id => login_user.id, :user => valid_attributes
#<User:0xbd030bc> received :update_attributes with unexpected arguments
expected: ({:name=>"changed name", :email=>"[email protected]", :password=>"secret", :password_confirmation=>"secret"})
got: ({"name"=>"Test user", "email"=>"[email protected]", "password"=>"secret", "password_confirmation"=>"secret"})
对我来说,它看起来像我传递"name" => "Test User"
和我期待:name => "test user"
我的规格如下所示:
describe 'with valid parameters' do
it 'updates the user' do
login_user = User.create!(valid_attributes)
controller.stub(:current_user).and_return(login_user)
User.any_instance.
should_receive(:update_attributes).
with(valid_attributes.merge(:email => "[email protected]",:name=>"changed name"))
put :update, :id => login_user.id, :user => valid_attributes
end
end
,我有这样的事情对我有效的属性:
def valid_attributes
{
:name => "Test user",
:email=> "[email protected]",
:password => "secret",
:password_confirmation => "secret"
}
end
那么我的参数有什么问题有什么建议吗?
我用Rails 3.0.5与2.6.0的RSpec ...
是有道理,有效......我只是期待如果我在我的put qequest中传入了我的valid_attributes,它们与我将它们传递给with方法时一样,就是这样。但你的方式工作......谢谢 – 2011-05-27 09:48:44