Skip to content

Request spec (RSpec-Rails) returns "The required parameter, data, is missing." #151

@jamonholmgren

Description

@jamonholmgren

I'm trying to test my API with an RSpec-Rails request spec. Here's the spec:

    # logged_in_headers is defined above

    describe "POST /create" do
      it "creates a new campaign" do
        post "/api/v2/campaigns", { "data" => {} }, logged_in_headers
        expect(JSON.parse(response.body)).to eq({ not_sure: "what" })
      end
    end

I'm getting this error:

  1) /api/v2/campaigns logged in POST /create creates a new campaign
     Failure/Error: expect(JSON.parse(response.body)).to eq({ not_sure: "what" })

       expected: {:not_sure=>"what"}
            got: {"errors"=>[{"title"=>"Missing Parameter", "detail"=>"The required parameter, data, is missing.", "id"=>nil, "href"=>nil, "code"=>106, "path"=>nil, "links"=>nil, "status"=>"bad_request"}]}

       (compared using ==)

       Diff:
       @@ -1,2 +1,2 @@
       -:not_sure => "what"
       +"errors" => [{"title"=>"Missing Parameter", "detail"=>"The required parameter, data, is missing.", "id"=>nil, "href"=>nil, "code"=>106, "path"=>nil, "links"=>nil, "status"=>"bad_request"}]

It appears the params is not passing through when we're posting. Any ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions