Is there an rspec hook that runs after a report file gets created?
For example, in my .rspec
, I have included:
--format json --out test_result
One way you could do this is by implementing your own formatter based on the JSON formatter. Something like this could work:
class CustomFormatter < RSpec::Core::Formatters::JsonFormatter
RSpec::Core::Formatters.register self, :example_started
def close(_notification)
super
# Do your post processing here...
end
end
And then you can use your custom formatter like this
rspec --require ./custom_formatter.rb --format CustomFormatter
The RSpec::Core::Formatters::JsonFormatter
is marked as private so it can change anytime. You have to think if you want to take the risk to need to change and adapt in a future RSpec upgrade.
Otherwise I would recommend to just use a custom script. It should be very simple with just &&
or |
in it like
rspec --format json | ./run_postprocessing
https://relishapp.com/rspec/rspec-core/docs/formatters/custom-formatters https://github.com/rspec/rspec-core/blob/main/lib/rspec/core/formatters/json_formatter.rb#L56