Skip to content
This repository has been archived by the owner on Oct 27, 2024. It is now read-only.

Bridge RSpec and Aruba/ArubaDoubles to test command-line tools

License

Notifications You must be signed in to change notification settings

livinginthepast/aruba-rspec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Bridge RSpec and Aruba/ArubaDoubles to test command-line tools

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages