Run your own code before specific RSpec examples
You probably know about the possibility to tag scenarios in Cucumber to run your own piece of code before the actual scenario is run which looks like that:
@foo
Scenario: Do something
...
and you place the following snippet into support/env.rb
:
Before('@foo') do
puts "This is run every time a @foo tagged scenario is hit"
end
You can tag RSpec examples like this:
it 'does something', :foo => true do
...
end
What you need is the following within the RSpec.configure do |config|
block within spec_helper.rb
config.before(:each, :foo => true) do
puts "This is run every time a tagged rspec example is hit"
end