Bridge RSpec and Aruba/ArubaDoubles to test command-line tools
Ruby
Switch branches/tags
Clone or download
Latest commit 1a3e598 Jun 12, 2014
Permalink
Failed to load latest commit information.
lib/aruba 1.0.1 Jun 12, 2014
spec Include real exit status in have_exit_status_matcher Jun 12, 2014
.gitignore
.rspec Initial commit Nov 22, 2013
Gemfile Add pry Jan 3, 2014
Guardfile Add guard Jan 3, 2014
LICENSE.txt Initial commit Nov 22, 2013
README.md
Rakefile Initial commit Nov 22, 2013
aruba-rspec.gemspec Fix rspec deprecations, require rspec >= 3 Jun 4, 2014

README.md

Aruba::RSpec

Aruba and ArubaDoubles are tools for testing command-line programs using Cucumber. They allow for setting up command stubs, then testing expectations on those stubs. This gem helps to integrate the two directly in RSpec.

Installation

Add this line to your application's Gemfile:

group :test do
  gem 'aruba-rspec'
end

Usage

Add aruba-rspec to your spec_helper.rb file as follows:

require 'aruba/rspec'

RSpec.configure do |config|
  config.include ArubaDoubles

  config.before :each do
    Aruba::RSpec.setup
  end

  config.after :each do
    Aruba::RSpec.teardown
  end
end

Note that ArubaDoubles needs to be included into your RSpec configuration. This allows command doubles to be used.

Command doubles

This comes out of ArubaDoubles:

describe 'Using doubles' do
  before do
    double_cmd('which', puts: '/some/path')
    double_cmd('sudo', warn: 'No!', exit: 1)
  end

  it 'can run a command that succeeds' do
    expect(`which thing`).to eq('/some/path')
    expect($?.exitstatus).to eq(0)
  end

  it 'can run a command that fails' do
    expect(`sudo do soemthing`).to be nil
    expect($?.exitstatus).to eq(1)
  end
end

Matchers

:shellout

describe MyThing do
  it 'calls out to an external command' do
    double_cmd('thing')
    expect {
	  `thing --with --options`
    }.to shellout('thing --with --options')
  end
end

:have_exit_status

it 'exits 50' do
  double_cmd('thing', exit: 50)
  expect {
    `thing 1 2 3`
  }.to have_exit_status(50)

References

  • https://github.com/cucumber/aruba
  • https://github.com/bjoernalbers/aruba-doubles

Contributing

  1. Fork it ( http://github.com//aruba-rspec/fork )
  2. Use feature branches
  3. Write tests for any changes