Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rspec 2 config :type types

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?

like image 270
Aaron Avatar asked Jun 03 '11 21:06

Aaron


2 Answers

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.

like image 156
simeonwillbanks Avatar answered Nov 03 '22 00:11

simeonwillbanks


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

config.include Devise::TestHelpers, :type => :feature
like image 37
Alter Lagos Avatar answered Nov 03 '22 01:11

Alter Lagos