RSpec: How to get example metadata before running suite

428 Views Asked by At

I'd like to get the metadata for the examples in my suite before running it. I want to parallelize my test suite based off of tags. Anyone know how to get this data during something like RSpec.configure?

2

There are 2 best solutions below

1
On

I don't see a way to do this while running the suite. You could conceivably create a custom formatter and run the suite with rspec --dry-run --format=MyFormatter, capture the output, extract the metadata and then do what you want with it. Unfortunately it appears the built-in JSON formatter does not output example metadata.

More info on formatters in the RSpec docs.

0
On

You can do this by inspecting,

RSpec.current_example.metadata

so for example, to detect if javascript is enabled:

def js_true?
  RSpec.current_example.metadata[:js]
end