创建报告后的 rspec 钩子 [英] rspec hook after report gets created

查看:28
本文介绍了创建报告后的 rspec 钩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有在创建报告文件后运行的 rspec 挂钩?

Is there an rspec hook that runs after a report file gets created?

例如,在我的 .rspec 中,我包含了:

For example, in my .rspec, I have included:

--format json --out test_results/rspec.json

我想发布处理此文件并在其他地方发布指标.我强烈不希望创建单独的脚本,而是希望将其作为我的 bundle exec rspec 命令的一部分来执行.是否有 RSpec 挂钩可以在创建此文件后运行?

and I'd like to post process this file and publish metrics elsewhere. I would strongly prefer not to create a separate script, and would prefer to do this as part of my bundle exec rspec command. Is there an RSpec hook that would run after this file gets created?

谢谢!

推荐答案

实现此目的的一种方法是基于 JSON 格式化程序实现您自己的格式化程序.这样的事情可以工作:

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

RSpec::Core::Formatters::JsonFormatter 被标记为私有,因此它可以随时更改.您必须考虑是否要冒险在未来的 RSpec 升级中进行更改和适应.

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-formattershttps://github.com/rspec/rspec-core/blob/main/lib/rspec/core/formatters/json_formatter.rb#L56

这篇关于创建报告后的 rspec 钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆