我要訪問命令行通過如何在RSpec的before(:suite)/ before(:all)鉤子中訪問標籤過濾器?
命令行
rspec --tag use_ff
RSpec的配置
RSpec.configure do |config|
config.before :suite, type: :feature do
# how do I check if use_ff filter was specified in the command line?
if filter[:use_ff]
use_selenium
else
use_poltergeist
end
end
end
標籤過濾器在before(:suite)
鉤我要訪問的標籤過濾器在命令行中指定的過濾器。
根據rspec核心代碼庫,包含標記過濾器存儲在RSpec.configuration的inclusion_filter中。從理論上講,我應該能夠訪問它們如下:
RSpec.configure do |config|
config.before :suite, type: :feature do
if config.filter[:use_ff] # filter is an alias for inclusion_filter
use_selenium
else
use_poltergeist
end
end
end
但是,出於某種原因,我得到一個空的哈希值,甚至當我在命令行中傳遞的標籤。
這看起來有趣的是,你能否也請分享任何額外的信息;一些錯誤消息或期望與您獲得信息。 – vee 2014-09-28 02:00:14
我確定你已經閱讀['--tag option'](https://www.relishapp.com/rspec/rspec-core/v/2-4/docs/command-line/tag-option )。 – vee 2014-09-28 02:01:30
@vee,實質上我需要訪問命令行中指定的標記過濾器。我希望可以從上下文中提取過濾器,或者從之前的鉤子獲取塊參數。 – 2014-09-28 05:00:50