# https://relishapp.com/rspec/rspec-core/v/3-7/docs/hooks/before-and-after-hooks
RSpec.configure do |config|
config.before :context do
puts 'before context'
end
config.before :example do
puts 'before example'
end
# Note: the :example and :context scopes are also available as :each and :all, respectively. Use whichever you prefer.
# Same as context
config.before :all do
puts 'before all'
end
# Same as example
config.before :each do
puts 'before each'
end
end
RSpec.describe do
subject { true }
describe do
it { is_expected.to be true }
it { is_expected.to be true }
end
describe do
it { is_expected.to be true }
it { is_expected.to be true }
end
end
$ bundle exec rspec -fd rspec/before_hooks.rb
before context
before all
before example
before each
should equal true
before example
before each
should equal true
before example
before each
should equal true
before example
before each
should equal true
Finished in 0.00986 seconds (files took 0.29761 seconds to load)
4 examples, 0 failures
- ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
- rspec-core 3.7.1