How to output the current RSpec example

Here’s a snippet you can add to your rspec config to print out the name of the method being run:

config.before do |example|
 24     puts "----- state ----"
 25     puts example.metadata[:full_description]
 26     puts "inline: #{Sidekiq::Testing.inline?}"
 27     puts "fake: #{Sidekiq::Testing.fake?}"
 28     puts "----------------"
 29     puts
 30   end

Why on earth would you wan to do this? Sometimes you are working with something like Sidekiq where state can bleed between tests (for example changing from inline to fake); this little snippet helps you figure out where it’s happening without having to investigate all your test files.