O'Reilly logo

Effective Testing with RSpec 3 by Myron Marston, Ian Dees

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required