3

I wish to test a Ruby command line application with Aruba and Cucumber. The application has a switch to create a dot file (such as .my_app) in the current user's home folder. I prefer not to have the application create the file in the user's home folder when running the Aruba tests.

I'm looking for a method to create a temporary working directory inside the step definitions that will create the temporary folder and modify a path flag when the command line application is run. Or is there some functionality built in Aruba that already provides something like this?

A sample test:

Feature: Initialize for user
  Scenario: Create a dot file in the user's home directory
    When I run `touch ~/.my_test_file`
    Then a file named "~/.my_test_file" should exist
sutch
  • 1,225
  • 1
  • 13
  • 28

2 Answers2

3

In your env.rb:

Before do
  set_env 'HOME', File.expand_path(File.join(current_dir, 'home'))
  FileUtils.mkdir_p ENV['HOME']
end

If you use this with Aruba, aruba will use <project_root>/tmp/aruba/home. Aruba then provides you with some nice cucumber steps to verify files are created, exist, etc.

Edit: I did a full write-up on my blog: http://ariejan.net/2014/04/15/testing-home-with-cucumber-and-aruba/

Ariejan
  • 10,910
  • 6
  • 43
  • 40
  • Nice solution. Any thoughts on how to make this a cross-platform solution so that Windows users can also run the tests? – sutch Apr 17 '14 at 12:46
1

Would fakefs help? Instead of worrying about modifying your real filesystem, mock it out.

Nick Veys
  • 23,458
  • 4
  • 47
  • 64
  • FakeFS is not used by the script when the script is executed from within backticks by Cucumber/Aruba. – sutch Apr 11 '14 at 15:11