2014-04-03 2 views
2

나는 오키와 아루바를 사용하여 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 

는 아루바의 Then a file named "" should exist step_definition에 ENV [ '홈'] 통과하고 전체 경로로 확장 한 수 있습니까?

답변

2

Cucumber/Aruba를 사용하여이 작업을 수행 할 수 있는지 여부는 여전히 궁금합니다.

다음 features/step_definitions/app_name.rb 파일의 단계를 정의

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/app_name.feature 년을, 다음과 같은 시나리오를 정의 : 그 동안, 여기에 내가 무슨 일을하고있어의 삭감 예제

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 

이것은 아루바의 check_file_presence에서 강력한 것은 아니지만 기본 작업을 완료합니다. 좀 더 배경에 대한


이 접근 방식 뒤에 아이디어는 응용 프로그램의 디렉토리 구조의 루트에 앉아 test_arenas 디렉토리를하는 것입니다. 각 테스트마다 필요한 파일이 들어있는 개별 test_arenas/set_X 디렉토리가 만들어집니다. 각 테스트 이전에 ENV [ 'HOME']는 test_arenas/set_X 디렉토리를 가리 킵니다.