Question: What does specifying the type in an RSpec actually affect?

Question

What does specifying the type in an RSpec actually affect?

Answers 1
Added at 2017-09-07 19:09
Tags
Question

I have never been sure what the difference between these options are

RSpec.describe V2::DirectMessagesController, type: :controller

vs

RSpec.describe V2::DirectMessagesController, type: :request

Or where to even look to figure it out

Answers to

What does specifying the type in an RSpec actually affect?

nr: #1 dodano: 2017-09-07 20:09

Request specs provide a thin wrapper around Rails' integration tests, and are designed to drive behavior through the full stack, including routing (provided by Rails) and without stubbing (that's up to you).

A controller spec is an RSpec wrapper for a Rails functional test (ActionController::TestCase::Behavior). It allows you to simulate a single http request in each example, and then specify expected outcomes such as:

  • rendered templates
  • redirects
  • instance variables assigned in the controller to be shared with the view
  • cookies sent back with the response

Controller spec docs: https://relishapp.com/rspec/rspec-rails/docs/controller-specs

Request spec docs: https://relishapp.com/rspec/rspec-rails/docs/request-specs/request-spec

Source Show
◀ Wstecz