开发者

Rspec 2 config :type types

开发者 https://www.devze.com 2023-03-10 02:41 出处:网络
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 t

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 nee开发者_StackOverflow社区ds 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?


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.


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

config.include Devise::TestHelpers, :type => :feature
0

精彩评论

暂无评论...
验证码 换一张
取 消