I'd like to define multiple types of specs for metadata, but it isn't currently possible.
I'd like to define things like:
config.when_first_matching_example_defined(types: %i(feature request)) do
# enable db support only for feature or request specs
require 'support/db'
end
# include these Helpers only into feature or request specs
config.include(Helpers, types: %i(feature request))
Currently I have to duplicate the definitions.
config.when_first_matching_example_defined(types: :feature) do
require 'support/db'
end
config.when_first_matching_example_defined(types: :request) do
require 'support/db'
end
config.include(Helpers, type: :feature)
config.include(Helpers, type: :request)
You can do this:
%i(feature request).each do |type|
config.when_first_matching_example_defined(type: type) do
# enable db support only for feature or request specs
require 'support/db'
end
# include these Helpers only into feature or request specs
config.include(Helpers, type: type)
end
Given how easy it is to do with a simple loop, I don't see a reason for us to add support for what you're asking for--particularly since it would be a very implicit, confusing way for metadata to match, IMO.
I don't think that above solution improves readability and in spec/rails_helper
. Some one-liner solution would be great for these cases. I don't think, I'm alone who would appreciate something what I proposed.
Given that currently we treat metadata values as simple values, it would really be confusing to start giving them special meaning, not to mention ambiguous!
Most helpful comment
I don't think that above solution improves readability and in
spec/rails_helper
. Some one-liner solution would be great for these cases. I don't think, I'm alone who would appreciate something what I proposed.