Checking the Response

Rack::Test provides the last_response method for checking HTTP responses. Add the following line inside your spec, right after the post request:

 expect​(last_response.status).to eq(200)

You’ve encountered code like this before, in Your First Spec. It’s an expectation fulfilling the role an assertion method would play in other test frameworks.

Together, expect() and to() check a result in order to signal success or failure. They compare a value—in this case, the HTTP status code returned by last_response.status—using a matcher. Here, we create a matcher using the eq method, which indicates whether or not the value wrapped by expect equals ...

Get Effective Testing with RSpec 3 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.