2014-04-03 40 views
2

我正在使用Cucumber和Aruba測試寫在GLI之上的Ruby命令行應用程序。爲了防止測試影響生產數據,我更新了ENV['HOME']以指向測試目錄。我想檢查ENV['HOME']目錄中是否存在文件。我想爲此使用Aruba,但我一直無法讓ENV['HOME']正常展開。使用Ruby,Cucumber和Aruba檢查測試主目錄中的文件

例如:

Scenario: Testing config files are found 
    Given I switch ENV['HOME'] to be "set_a" of test_arena 
    Then a file named "#{ENV['HOME']}/config.xml" should exist 

是否有可能通過ENV [ 'HOME']阿魯巴的Then a file named "" should exist step_definition,並已擴大到全路徑?

回答

2

我仍然有興趣瞭解是否可以用Cucumber/Aruba本地進行此操作。與此同時,這裏有什麼我做了削減例如:

features/app_name.feature文件中,定義了以下場景:

Scenario: Testing config files are found 
    Given I switch ENV['HOME'] to be "test_arenas/set_a" 
    Then a test_arena file named "config.xml" should exist 

然後,在features/step_definitions/app_name.rb文件中定義的步驟:

Given(/^I switch ENV\['HOME'\] to be "(.*?)"$/) do |testing_dir| 
    ENV['HOME'] = File.join(File.expand_path(File.dirname(__FILE__)), 
    '..','..', testing_dir) 
end 

Then(/^a test_arena file named "(.*?)" should exist$/) do |file_name| 
    file_path = "#{ENV['HOME']}/#{file_name}" 
    expect(File.exists?(file_path)).to be_truthy 
end 

這並不像Aruba的check_file_presence那樣穩健,但它完成了基本的工作。


對於多一點的背景下,這種做法背後的想法是有一個test_arenas目錄坐在應用程序的目錄結構的根。對於每個測試,將創建一個包含必要文件的個人test_arenas/set_X目錄。在每次測試之前,將ENV ['HOME']指向各自的test_arenas/set_X目錄。

相關問題