Reputation: 103
I have a sample_spec.rb
context 'test case', :tag => true do
end
In my spec_helper.rb I wanted to skip tests based upon tag present in context Im unable to get context metadata
RSpec.configure do |config|
config.before(:context) do |example|
// code to filter based upon tags
end
end
Upvotes: 0
Views: 580
Reputation: 6628
You can match it this way
config.before(:context, tag: true)
this should trigger the hook only if the tag was true
.
you can also access it in example.metadata
:
config.before(:context) do |example|
if example.metadata[:tag]
do_sth
else
do_sth_else
end
end
Read more on this in Hooks/filters here: https://relishapp.com/rspec/rspec-core/v/3-10/docs/hooks/filters
and metadata sections here: https://relishapp.com/rspec/rspec-core/v/3-10/docs/metadata/user-defined-metadata
Upvotes: 1