我有一个控制器规格,但我得到了以下失败的期望:
Failure/Error: put :update, :id => login_user.id, :user => valid_attributes
#<User:0xbd030bc> received :update_attributes with unexpected arguments
expected: ({:name=>"changed name", :email=>"changed@mail.com", :password=>"secret", :password_confirmation=>"secret"})
got: ({"name"=>"Test user", "email"=>"user@test.com", "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 => "changed@mail.com",:name=>"changed name"))
put :update, :id => login_user.id, :user => valid_attributes
end
end
我的有效属性是这样的:
def valid_attributes
{
:name => "Test user",
:email=> "user@test.com",
:password => "secret",
:password_confirmation => "secret"
}
end
那么我的参数有什么问题有什么建议吗?
我正在使用带有 rspec 2.6.0 的 Rails 3.0.5 ...