【问题标题】:Is there a Ruby Cucumber test hook for at_start?at_start 是否有 Ruby Cucumber 测试挂钩?
【发布时间】:2016-07-26 07:11:28
【问题描述】:

at_start 是否有 Ruby Cucumber 测试挂钩?我尝试了at_start,但没有成功。

我在support/hooks.rb 中有类似的内容,我想在任何测试开始之前打印一条全局消息:

Before do
  print '.'
end

at_exit do
  puts ''
  puts 'All Cucumber tests finished.'
end

如果他们有一个at_exit 钩子,他们似乎也应该有一个before-start 钩子,对吧?

【问题讨论】:

    标签: ruby cucumber


    【解决方案1】:

    https://github.com/cucumber/cucumber/wiki/Hooks 有一些关于“全局挂钩”的文档

    您不需要用任何特殊的方法包装它,例如Beforeat_exit。您只需在features/support 目录中包含的任何文件的根级别执行代码,例如env.rb。复制并粘贴他们给出的示例:

    # these following lines are executed at the root scope, 
    # accomplishing the same thing that an "at_start" block might. 
    my_heavy_object = HeavyObject.new
    my_heavy_object.do_it
    
    # other hooks can be defined in the same file
    at_exit do
      my_heavy_object.undo_it
    end
    

    他们还举例说明了如何编写一个只执行一次的Before 块。如果定义了一些全局变量,基本上你有这个块退出。第一次运行该块时,会定义全局变量以防止它被多次执行。请参阅我链接的那个页面上的“只运行一次之前的钩子”部分。

    【讨论】:

      猜你喜欢
      • 2014-02-09
      • 1970-01-01
      • 1970-01-01
      • 2012-03-13
      • 1970-01-01
      • 1970-01-01
      • 2019-08-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多