【发布时间】:2015-04-13 15:15:24
【问题描述】:
如何从我的 Rspec 测试中获取 JSON 格式的数据?比如,有多少测试失败等等。
我知道如果我从 ruby 运行 Rspec,我可以得到它,如 here 所述 为方便起见,我将代码粘贴在这里。
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
有没有办法在 Rspec 测试套件运行时将此 json 输出写入文件?
【问题讨论】: