首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Ruby/Rails/Riot以编程方式访问测试结果

Ruby/Rails/Riot以编程方式访问测试结果
EN

Stack Overflow用户
提问于 2011-10-25 20:31:12
回答 1查看 204关注 0票数 1

我正在使用Riot (https://github.com/thumblemonks/riot)进行测试,尽管我们可以使用其他的东西。

我得到这样的测试输出:

> ruby my_test_file.rb

代码语言:javascript
运行
复制
Running a test
  + something works
  + something else works
  - something failed

我想以编程方式访问这些信息。类似于:

代码语言:javascript
运行
复制
test = TestClass.load("my_test_file.rb")
result = test.run
result.errors # some array
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-13 09:14:29

回答我自己的问题。如果有人感兴趣的话,我可以贴出更详细的答案。

它的要点是评估测试文件,然后从评估的测试中获取上下文:

代码语言:javascript
运行
复制
Riot.alone! # so Riot doesn't automatically run the tests

["/path/to/test/file"].each do |test_file|
  eval(IO.read(path), binding, test_file) # load test file

  Riot.root_contexts.each do |context|
    reporter = MyReporter.new
    context.run reporter
    # do something cool with reporter results   
  end

  Riot.root_contexts.clear # clean out root_contexts so it's clean for the next run
end

其中MyReporter是处理通过/失败测试结果的实现。请参阅https://github.com/thumblemonks/riot/blob/master/lib/riot/reporter.rb

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7895493

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档