2016-07-25 68 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塊的例子。基本上你有這個塊的退出,如果一些全局變量被定義。塊首次運行時,會定義全局變量,以防止它多次執行。請參閱我鏈接的頁面上的「僅運行一次前鉤子」部分。