I have a ruby script which needs to execute rspec tests and collect results. I'm using standard rspec API to achieve this:
require 'rspec'
require 'rspec/core'
require 'rspec/core/formatters/json_formatter'
require 'json'
def run_test(test_location)
config = RSpec.configuration
json_formatter = RSpec::Core::Formatters::JsonFormatter.new(config.output)
reporter = RSpec::Core::Reporter.new(json_formatter)
config.instance_variable_set(:@reporter, reporter)
begin
::RSpec::Core::Runner.run([test_location,'--format','j'])
json_formatter.output_hash
rescue Exception => e
e.message
end
end
run_test(<PATH_TO_RSPEC_TEST_SCRIPT>)
Now, when something fails in rspec test, I can only get error message but I would like to get backtrace from the underlying rspec test that failed. Is there a way to achieve this? I've tried passing arguments: --backtrace or -b to the array that is passed to RSpec::Core::Runner.run method but didn't get much of the help with that
Thanks in advance