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: Requests

Controller specs: Requests - Ruby Tutorial

From the course: Ruby: Testing with RSpec

Start my 1-month free trial

Controller specs: Requests

- In this movie we'll learn about writing controller specs, and we'll begin by talking about how requests are made. Controllers are also classes, like models. You may not have thought much about it, because Rails creates a new instance of the controller class for us, and we tend to think of the methods as being actions. Controllers are a unique type of class though, because they function inside of a request/response cycle. They expect the browser to send them a request, and then they put together a response to send back. They're also in charge of rendering templates, redirecting actions, and setting values for cookies and sessions. In order to test our controllers we'll need some extra tools that can work with these controller features. RSpec gives us helpers for simulating requests, attributes for accessing values that are being assembled by the controller, and additional matchers for setting expectations on responses. First, you'll need to be able to request an action. You can…

Contents