2015-06-26 27 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