How to output the current RSpec example

Mar 13 2018

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|
  puts "----- state ----"
  puts example.metadata[:full_description]
  puts "inline: #{Sidekiq::Testing.inline?}"
  puts "fake: #{Sidekiq::Testing.fake?}"
  puts "----------------"

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.