Skip to content

Instantly share code, notes, and snippets.

@leandro
Created August 17, 2021 18:51
Show Gist options
  • Save leandro/5a1d4fb942a50f99a04971218f4fbf4d to your computer and use it in GitHub Desktop.
Save leandro/5a1d4fb942a50f99a04971218f4fbf4d to your computer and use it in GitHub Desktop.
A way to know which example (in any given rspec file) is being run out of total examples in the spec file
RSpec.describe 'whatever' do
around do |example|
total_examples = example.example_group.parent_groups.last.descendant_filtered_examples.size
examples_executed = example.reporter.examples.size
do_initial_thing if examples_executed == 1
example.run
do_final_thing if examples_executed == total_examples
end
# the rest of the spec file
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment