Receiving error in RSpec for PUT, but not POST

☆樱花仙子☆ 提交于 2020-01-01 19:59:10

问题


In my specs, when I run the POST request below, everything works fine.

    before do
      request_payload = {
        player: {
          first_name: "Joe",
          last_name: "Carradine",
          team_id: "1"
        }
      }

      post :create, request_payload
    end

But when I run a spec for PUT:

    before do
      request_payload = {
        player: {
          first_name: "Buck",
          last_name: "Carradine",
          team_id: "1"
        }
      }

      put :update, id: 3, request_payload
    end

I get an error like this:

[filename]_spec.rb:139: syntax error, unexpected '\n', expecting tASSOC (SyntaxError)

[filename]_spec.rb:198: syntax error, unexpected $end, expecting keyword_end

Any ideas? Is there a different syntax for PUT I'm not aware of?


回答1:


To fix the syntax error, use put :update, { id: 3 }, request_payload, not put :update, id: 3, request_payload. Ruby only supports "bare" (e.g. curly-braceless) hashes as the last argument to the method, so id: 3 cannot appear in the middle of an argument list without being wrapped in curly braces.



来源:https://stackoverflow.com/questions/13024146/receiving-error-in-rspec-for-put-but-not-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!