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.
Add this line to your application's Gemfile:
group :test do
gem 'aruba-rspec'
end
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.
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
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
it 'exits 50' do
double_cmd('thing', exit: 50)
expect {
`thing 1 2 3`
}.to have_exit_status(50)
https://github.com/cucumber/aruba
https://github.com/bjoernalbers/aruba-doubles
- Fork it ( http://github.com//aruba-rspec/fork )
- Use feature branches
- Write tests for any changes