Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example of expect(response).to have_http_status(:status_code_name) #10

Closed
eliotsykes opened this issue Dec 12, 2014 · 6 comments
Closed

Comments

@eliotsykes
Copy link
Owner

Example of using have_http_status method

# Rails `:symbolized` status codes at end of each status code page at http://httpstatus.es/
expect(response).to have_http_status(:success) # 200
expect(response).to have_http_status(:forbidden) # 403

Source: RSpec Controller Specs cheatsheet

@eliotsykes
Copy link
Owner Author

Try to get this syntax or similar into request specs too so they're not full of magic numbers

@eliotsykes
Copy link
Owner Author

Consider adding expect(page).to have_http_status(:success) to a feature spec. rspec-rails supports this according to README.

@dideler
Copy link

dideler commented Apr 19, 2015

Neat, I didn't know about have_http_status 🙇

Some other options you can consider for controller and request specs to avoid magic numbers

  • assert_response :ok # From Rails' Action Controller
  • expect(response).to be_forbidden # Also from Rails' Action Controller
  • it { should respond_with(:unauthorized) } # From Shoulda Matchers

@eliotsykes
Copy link
Owner Author

Thanks for the tips @dideler - especially like should respond_with(...) 👍

@vinhnglx vinhnglx mentioned this issue Oct 7, 2015
@eliotsykes
Copy link
Owner Author

WIP: have_http_status(...) appearing in #96

@eliotsykes
Copy link
Owner Author

Closed by #96

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants