Skip to content

Instantly share code, notes, and snippets.

@mfilej
Last active November 5, 2021 09:16
Show Gist options
  • Save mfilej/5466144 to your computer and use it in GitHub Desktop.
Save mfilej/5466144 to your computer and use it in GitHub Desktop.
RSpec hook to show current spec in process name

Our suite would sometimes randomly hang when running a certain spec, but we weren't able to tell which one. With the below RSpec around filter you can see the spec that is currently running by inspecting the process name.

$ rspec spec_spec.rb &
[2] 64968
$ ps | grep rspec
64968 ttys005    0:00.24 rspec /Users/miha/spec_spec.rb:10 "Dummy spec waits for 100 seconds"
RSpec.configure do |c|
c.around :each do |example|
title = example.metadata[:full_description]
source = example.metadata[:example_group_block].source_location.join ":"
$0 = %{rspec #{source} "#{title}"}
example.run
end
end
describe "Dummy spec" do
it "waits for 100 seconds" do
sleep 100
end
end
@jgonzalezd
Copy link

Thanks a lot! It worked perfectly.
Just one thing metadata[:example_group_block] is deprecated. Use metadata[:block] instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment