【问题标题】:How to call listener in Ruby rspec to generate a run time report如何在 Ruby rspec 中调用侦听器以生成运行时报告
【发布时间】:2014-04-15 11:56:40
【问题描述】:

谁能帮我看看如何用 ruby​​ 和 rspec 编写监听器代码

我想用这个监听器

class MyStoryListener 
  def run_started(number_of_scenarios); end 
  def story_started(story, narrative); end 
  def story_ended(story, narrative); end 
  def scenario_started(story, scenario); end 
  def scenario_succeeded(story, scenario); end 
  def scenario_pending(story, scenario, error); end 
  def scenario_failed(story, scenario, error); end 
  def run_ended; end 
end 

【问题讨论】:

  • 不清楚你卡在哪里了。不太可能有人有时间为您从头开始编写整个教程,所以您能否花一些时间展示您已经知道的内容,也许用一小段测试代码?然后有人回答只需给你缺少的部分
  • 我想使用这个listner class MyStoryListener def run_started(number_of_scenarios);结束 def story_started(故事,叙述); end def story_ended(故事,叙述);结束定义场景_开始(故事,场景);结束 def 场景_成功(故事,场景); end def scenario_pending(故事,场景,错误); end def scenario_failed(故事,场景,错误);结束定义运行结束;结束结束
  • 您应该编辑问题以添加这些详细信息。这次我已经为你做到了。我仍然不清楚你被困在哪里。侦听器代码看起来像有效的 Ruby。是什么阻止您使用它?
  • 其实我已经在 testNg 中实现了一个 testNGprogress 插件,这里我们使用的是 ITestListener,我需要在 ruby​​ 中用 rspec 实现同样的东西是一个 ruby​​ 的单元测试框架,所以我想告诉你如何实现一个监听器以及我在 rspec 中调用哪个监听器,因为我被 rspec 中的两种监听器困住了(MyStoryListener,类:RSpec::Core::Reporter),这就是我需要帮助的原因,如何在 rspec 中调用监听器,因为我是红宝石新手

标签: ruby rspec selenium-webdriver


【解决方案1】:

使用RSpec::Core::Reporter.register_listener(my_story_listener)

详情请见http://rdoc.info/github/rspec/rspec-core/RSpec/Core/Reporter#register_listener-instance_method

可以在 http://benmabey.com/2008/07/04/global-setup-in-rspec-or-how-to-add-logging-for-specs.html 找到更完整的教程,但请注意,这是 2008 年发布的帖子,因此 API 可能从那时起发生了变化。

【讨论】:

    猜你喜欢
    • 2021-01-22
    • 1970-01-01
    • 2014-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-23
    • 1970-01-01
    • 2017-04-25
    相关资源
    最近更新 更多