2016-07-25 35 views
0

at_start有红宝石黄瓜测试钩吗?我试过at_start,它没有工作。at_start是否有Ruby Cucumber测试钩子?

我在support/hooks.rb这样的事情,我会在任何的测试打印一个单一的全球信息开始:​​

Before do 
    print '.' 
end 

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

好像如果他们有一个at_exit挂钩,他们应该有一个before-start钩还有吧?

回答

2

有一个在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块的例子。基本上你有这个块的退出,如果一些全局变量被定义。块首次运行时,会定义全局变量,以防止它多次执行。请参阅我链接的页面上的“仅运行一次前钩子”部分。

相关问题