0

我正在尝试通过更新操作手动更新用户。

我在 spec/requests/user_request_spec.rb 中尝试了以下代码行:

user = create(:user, username: "username", password: "secret", password_confirmation: "secret") #Factory Girl
attr = { username: "newusername" }
put :update, :id => user.id, :user => attr

我收到以下错误:

Failure/Error: put :update, :id => user.id, :user => attr
ArgumentError:
  bad argument (expected URI object or URI string)
# ./spec/requests/users_request_spec.rb:55:in `block (3 levels) in <top (required)>'

如何通过 rspec 发送更新用户的请求?

4

1 回答 1

0

我不确定“put”是在哪里定义的,我本来希望没有方法错误。您必须包含定义 put 的其他内容。

无论如何,Rack::Test::Methods在你的测试中,它应该提供你所追求的:

describe Foo do
  include Rack::Test::Methods # provides get, post, put, etc

  ...
end
于 2012-11-11T22:40:20.300 回答