Search code examples
ruby-on-railsrspecrails-api

Rspec expects status code 201 but fails on code 200


I am using Rspec to test an API, one of my test expects an error code of 201 but fails because it is receiving an unexpected code of 200 the code is as follows:

it 'returns status code 201' do
      expect(response).to have_http_status(201)
end

I want all status 200's to pass the test. What methods should I use? Do I need to create a test helper to accomplish this?


Solution

  • it "have success status" do
      expect(response).to have_http_status(:success)
    end
    

    Matcher message says

       expected the response to have a success status code (2xx)