A
A
Anton Ivanov2016-12-20 09:06:23
rspec
Anton Ivanov, 2016-12-20 09:06:23

How to use session in routing tests in Rspec?

Hello.
When creating a new scaffold controller, rspec automatically creates tests. Among them are routing tests, such as this:

require 'rails_helper'

RSpec.describe CommentsController, type: :routing do
  describe 'routing' do
    it 'routes to #index' do
      expect(get: '/comments').to route_to('comments#index')
    end
  end
end

in routing, I use constraints for those who are logged into the system and those who are not.
Accordingly, this test fails, as the routing sends the user to the login page.
Is it possible to pass a session here? I tried to debug the test, I saw that when receiving route parameters, only the first key from expect is used.
Tests with the 'request' type work fine (you can't transfer a session there either, but you can make a request for a login address before each test). In this test (with the routing type), this does not help

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question