rubycucumberaruba

How to test creation of files in home folder using Aruba


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

Solution

  • 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/