Rspec-rails: config.include usage in following manner: config.include "ModuleName", type: "Multiple tags here"

Created on 8 Apr 2015  ·  4Comments  ·  Source: rspec/rspec-rails

Environment

Rails 4.2.0
ruby-2.2.1 [ x86_64 ]
rspec-core  3.2.2
rspec-rails   3.2.1

In my /spec/rails_helper.rb I have included Devise helpers for spec files tagged with type: :controller

RSpec.configure do |config|
   ...
   ....
   config.include Devise::TestHelpers, type: :controller
end

Now I need these helpers for spec files tagged with type: :request. Is there a provision to specify multiple values to :type option? For e.g.

config.include Devise::TestHelpers, type: :controller, :request, or

config.include Devise::TestHelpers, types: [:controller, :request]

Thanks,
Jiggneshh

Most helpful comment

You will need to write the include again:

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

The metadata matches are exact. So type: [:controller, :request] would expect a spec that has the type specified as an array.

All 4 comments

You will need to write the include again:

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

The metadata matches are exact. So type: [:controller, :request] would expect a spec that has the type specified as an array.

I agree with @jiggneshhgohel seeing the following code my instinct that it was similar to rails and I could change it to types and it would all work. I do understand what you are talking about @cupakromer but it is a technical reason. The design of the interface should accommodate what the user would expect to be able to do.

At the very least, we should give a warning "Unsupported filter option types" if possible.

I just use a loop to save some keystrokes. (That way I can also include the ControllerMacros module without having to get WET.)

for type in [:controller, :request] do
  config.include Devise::Test::ControllerHelpers, type: type
  config.extend ControllerMacros, type: type
end

My aim is to have type for :controller & :model
the above suggestion does not worked in my end.
I tried to remove the type argument, and it works for both :controller & :model

Was this page helpful?
0 / 5 - 0 ratings