What to Expect in a Request Spec

My main goal in a request spec is to test behavior. I find that test-double validations work well here. If you’re interested in testing the final state after the request, in addition to testing the changes to the database, there are a few other substantive things you can test.

After the request has been made, you have access to a response variable. Since request specs wrap Rails integration tests, RSpec does render the view, though if you are testing view behavior, I recommend using system specs, where you have access to the Capybara matchers, and not just the Rails integration spec matchers as described in Chapter 12, Minitest.

After the request has been made, you have access to three special hash variables ...

Get Rails 5 Test Prescriptions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.