1

How can I get the data from my Rspec tests in JSON format? like, how many tests failed etc.

I know that I can get it if I run Rspec from ruby, as described here I'll just paste the code here for convenience.

run(paths) # runs rspec tests from ruby # source: https://stackoverflow.com/a/10412793/805156 config = RSpec.configuration formatter = RSpec::Core::Formatters::JsonFormatter.new(config.output_stream) # create reporter with json formatter reporter = RSpec::Core::Reporter.new(config) config.instance_variable_set(:@reporter, reporter) # internal hack # api may not be stable, make sure lock down Rspec version loader = config.send(:formatter_loader) notifications = loader.send(:notifications_for, RSpec::Core::Formatters::JsonFormatter) reporter.register_listener(formatter, *notifications) RSpec::Core::Runner.run(paths) formatter.output_hash end 

Is there a way to write this json output to a file whenever Rspec test suite runs?

1 Answer 1

2

Given that this just involves running with a specific formatter you can just run

rspec --format json > output.json 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.