28

In my spec_helper.rb I have

config.include Devise::TestHelpers, :type => :controller

so that I can actually test my controllers that require the user to be authenticated. However, the spec for the same class in requests needs to sign in as well or the tests will fail. I've tried

config.include Devise::TestHelpers, :type => :request

but that doesn't work either. I cannot seem to find what type options I can pass into the rspec include or extend methods. I assume :model and :view would be there but the others I'm completely unsure of. What should I be using so my requests spec can pass and is there a list of the different types for :type?

Aaron
  • 13,349
  • 11
  • 66
  • 105

2 Answers2

27

This commit should help clarify the :type option.

https://github.com/rspec/rspec-rails/commit/fc5cdbb603f0e66f9f3d19a0a60a775e124fb218

:type => :request is valid, so I'm unsure why your tests are failing.

Which directory holds your integration tests? Typically, they're located in spec/requests or possibly spec/integration.

You can use another option to specify when to include Devise::TestHelpers; the option is :example_group:

config.include Devise::TestHelpers, :example_group => {
  :file_path => config.escaped_path(%w[spec (requests|integration)])
}

Now, Devise::TestHelpers will be included into example groups whose file is within the specified paths.

Make sure to replace the array member (requests|integration) with the folder name where your integration tests are located.

simeonwillbanks
  • 1,459
  • 16
  • 18
  • Excellent. This will help include a macros file for the new spec/features directory that Capybara 2.x likes to use. – sockmonk Feb 13 '13 at 04:04
  • config.escape_path does not work in the latest rspec I've used `config.include RakeTestHelper, :example_group => { :file_path => %r(spec/api) }` – Calin May 01 '14 at 06:53
4

Maybe is too late, but for anyone who needs it, changing the type to :feature worked for me:

config.include Devise::TestHelpers, :type => :feature
Alter Lagos
  • 12,090
  • 1
  • 70
  • 92