2011-06-12 51 views
2

我有一個RSpec場景看起來像:Rspec:我如何訪問該場景中標記的場景?

scenario "some description of the scenario", :js => true, :slow => true, :wip => true do 
     sleep 60 
     ... 

但我想打電話給sleep有條件基於什麼場景被加上,是這樣的:

scenario "some description of the scenario", :js => true, :slow => true, :wip => true do 
     sleep 60 if tags[:slow] && !tags[:wip] 
     ... 

我會很感激的任何幫幫我。

回答

3

由於rspec的沒有一個scenario方法,我猜你使用capybarasteak,它實際上只是爲it的別名。在這種情況下,rspec的內部指的代碼作爲該塊「例如,」您可以訪問元數據是這樣的:

sleep 60 if example.metadata[:slow] # sleep if example is tagged with :slow => true 

你也可以把元數據的例子集團,describe塊包含各種示例。看到這個:http://relishapp.com/rspec/rspec-core/v/2-6/dir/metadata/user-defined-metadata