2015-06-26 64 views
0

我正在使用AfterConfiguration掛鉤在我的測試開始之前運行一些設置配置,但是我面臨的問題是當我運行我的方法時,其中一個會運行一組使用反引號在Ruby方法,而這又似乎重新initialze黃瓜和重複的工藝特徵文件,所以我被困在一個循環如何在Ruby方法中處理運行黃瓜功能

AfterConfiguration do 
    EnvironmentSetup::TestUsers.create_test_users 
end 

module EnvironmentSetup 
    class TestUsers 
    def self.create_test_users 
    # other logic here 
    `cucumber "#{path_to_feature}"` # Use backticks to run cucumber scripts in a subshell 
    end 
    end 
end 

所以,當這個執行的時候又回到了起點和運行我所有的其他邏輯再次

有沒有辦法只運行一次,或忽略第二個循環的AfterConfiguration?聲明一個全局變量?

我也曾嘗試

AfterConfiguration do 
if defined? $a == nil 
    EnvironmentSetup::RedisUsers.check_redis_users 
    EnvironmentSetup::TestUsers.create_test_users 
end 

module EnvironmentSetup 
    class TestUsers 
    def self.create_test_users 
    # other logic here 
    $a = true 
    `cucumber "#{path_to_feature}"` # Use backticks to run cucumber scripts in a subshell 
    end 
    end 
end 

但即時猜測該變量設置不被跨越時進行重新初始化?

任何援助讚賞

感謝

回答

1

嘗試設置環境變量:

AfterConfiguration do 
    return if ENV['CUCUMBER_CONFIGURED'] == 'yes' 

    EnvironmentSetup::TestUsers.create_test_users 
    ENV['CUCUMBER_CONFIGURED'] = 'yes' 
end 

和運行黃瓜是這樣的:

CUCUMBER_CONFIGURED='no'; cucumber ... 
+0

這樣的作品,謝謝 – Richlewis