From the course: Ruby: Testing with RSpec

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Controller specs: Responses

Controller specs: Responses - Ruby Tutorial

From the course: Ruby: Testing with RSpec

Start my 1-month free trial

Controller specs: Responses

- In the previous movie, we started working with controller specs. We learned to simulate a request and to expect the values that the controller sets. In this movie, we'll learn to write specs for controller responses. RSpec rails give us three news matchers. All of which are meant to be called on the response object. So, we have the render_template matcher. We can expect the response to render a certain template and then we can pass in the template as an argument as that. And we have the redirect_to matcher. We would expect the response to redirect to and then we'd provide the path for where it should redirect. This handles most cases. Most controllers end up doing one of two things, they either render a template or they redirect to another action. We also have a third matcher for checking the HTTP status. have_http_status. We can expect the response to have an HTTP status of and we pass in the status that it should have. The list of status codes is long but here are the most common…

Contents