【问题标题】:Get Rspec test data in JSON format获取 JSON 格式的 Rspec 测试数据
【发布时间】: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 输出写入文件?

【问题讨论】:

    标签: ruby json rspec


    【解决方案1】:

    鉴于这仅涉及使用特定格式化程序运行,您可以运行

    rspec --format json > output.json
    

    【讨论】:

      猜你喜欢
      • 2013-01-14
      • 2017-02-27
      • 2017-11-04
      • 1970-01-01
      • 2018-01-25
      • 2015-05-11
      • 1970-01-01
      • 2020-11-25
      • 2019-08-31
      相关资源
      最近更新 更多