Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Bridge RSpec and Aruba/ArubaDoubles to test command-line tools
Ruby
Branch: master

1.0.1

latest commit 1a3e59896b
@sax sax authored

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
Something went wrong with that request. Please try again.