2014-01-21 86 views
0

我目前正在计划使用RSpec来持续监视我们的一些服务。计划是创建一些测试,定期运行它们,并在发现错误时自动发出警报。由于许多产品使用相同的服务器,因此会创建连接一次,然后对所有测试使用相同的连接。RSpec中的全局设置

我不使用轨道,只是红宝石和RSpec:

-- spec_helper.rb # Setup server connections, handle errors. 
    -- test1_spec.rb # Specific tests for product one, uses server connection from spec_helper. 
    -- test2_spec.rb # Tests for product two, uses same connection as one. 
    -- test3_spec.rb 

基本上,我可以创造一个before :all,并适用于所有的文件测试,或者我需要重复我在每个连接after :all测试文件(或将所有测试放在一个大文件中)?

因此,使用@ CDub的有用的评论
+0

你以前签出'?也许这就是你要找的 – CDub

回答

0

我把它加入

RSpec.configure do |config| 
    config.before(:suite) {$x = 'my_variable'} 
end 

到spec_helper文件工作。

注意变量必须是全球性的,并且每个使用变量文件必须导入rspec_helper:(:套件)`require_relative 'spec_helper'