No commit activity in last 3 years
No release in over 3 years
The RSpec extention for describe behavier of external command
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.11
~> 10.0

Runtime

~> 3.0
 Project Readme

rspec-shell_command

Gem Version Build Status

The RSpec extention for writing a behavior of external command.

Installation

Add this line to your application's Gemfile:

gem 'rspec-shell_command'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rspec-shell_command

Usage

require 'rspec/shell_command'

describe '`echo hello; echo goodbye >&2`' do
  # Enables DSL
  include RSpec::ShellCommand::DSL

  # Check whether success or fail
  it 'successes' do
    expect(`echo hello; echo goodbye >&2`).to success
  end

  # Check the status code
  it 'exit with status code 0' do
    expect(`echo hello; echo goodbye >&2`).to exit_with(0)
  end

  # Check standard output
  # (The output matcher behaves like the builtin output)
  it 'output "hello\n" to stdout' do
    expect(`echo hello; echo goodbye >&2`).to output("hello\n").to_stdout
  end

  # Check standard error
  it 'output a some string to stderr' do
    expect(`echo hello; echo goodbye >&2`).to output.to_stderr
  end
end

# Composing matcher is supported!
describe '`echo hello; echo goodbye >&2; exit 2`' do
  include RSpec::ShellCommand::DSL

  subject { `echo hello; echo goodbye >&2; exit 2` }

  # Check the status code using a composing matcher
  it { is_expected.to exit_with(a_value_between(1, 3)) }

  # Check standard output using a Regexp
  it { is_expected.to output(/ell/).to_stdout }

  # Check standard error using a composing matcher
  it { is_expected.to output(a_string_starting_with('good')).to_stderr }
end

NOTE: When including RSpec::ShellCommand::DSL, a backquote operator returns a wrapper object of given command, instead of the standard output.

If you need to use RSpec::ShellCommand::DSL at all examples, you can write as bellow at your spec/spec_helper.rb:

require 'rspec/shell_command'

RSpec.configure do |c|
  c.include RSpec::ShellCommand::DSL
end

Author

@AuToPP

LICENSE

MIT