Rspec::Shell::Expectations
Run your shell script in a mocked environment to test its behaviour using RSpec.
Installation
Add this line to your application's Gemfile:
gem 'rspec-shell-expectations'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rspec-shell-expectations
Usage
see specs in spec/
folder:
Running script through stubbed env:
require 'English'
describe 'my shell script' do
include Rspec::Shell::Expectations
let(:stubbed_env) { create_stubbed_env }
it 'runs the script' do
stubbed_env.execute 'my-shell-script.sh'
expect($CHILD_STATUS.exitstatus).to eq 0
end
end
Stubbing commands:
require 'English'
describe 'my shell script' do
include Rspec::Shell::Expectations
let(:stubbed_env) { create_stubbed_env }
before do
stubbed_env.stub_command('rake')
end
it 'runs the script' do
stubbed_env.execute 'my-shell-script.sh'
expect($CHILD_STATUS.exitstatus).to eq 0
end
end
Contributing
- Fork it ( https://github.com/matthijsgroen/rspec-shell-expectations/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request