2

I'm using Cucumber and Aruba to test a Ruby command line app written on top of GLI. To prevent tests from affecting production data, I update ENV['HOME'] to point to a testing directory. I'd like to check for the existence of a file in the testing ENV['HOME'] directory. I'd like to use Aruba for this, but I have been unable to get ENV['HOME'] to expand properly.

For example:

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

Is it possible to pass ENV['HOME'] to Aruba's Then a file named "" should exist step_definition and have it expand to the full path?

Alan W. Smith
  • 24,647
  • 4
  • 70
  • 96

1 Answers1

2

I'm still interested in seeing if it's possible to do this natively with Cucumber/Aruba. In the mean time, here's a cut down example of what I'm doing:

In features/app_name.feature file, define the following Scenario:

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

Then, in the features/step_definitions/app_name.rb file define the steps:

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

This isn't as robust at Aruba's check_file_presence but it gets the basic job done.


For a little more background, the idea behind this approach is to have a test_arenas directory sitting at the root of the app's directory structure. For each test, an individual test_arenas/set_X directory is created that contains the necessary files. Prior to each test, ENV['HOME'] is pointed to the respective test_arenas/set_X directory.

Thomas Decaux
  • 21,738
  • 2
  • 113
  • 124
Alan W. Smith
  • 24,647
  • 4
  • 70
  • 96