GithubHelp home page GithubHelp logo

isabella232 / blue-shell Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vmware-archive/blue-shell

0.0 0.0 0.0 33 KB

friendly command-line test runner and matchers for shell scripting in ruby using RSpec

License: MIT License

Ruby 100.00%

blue-shell's Introduction

BlueShell Build Status Gem Version

Friendly command-line test runner and matchers for shell scripting in ruby using RSpec.

Installation

With Bundler, add the following to your Gemfile:

group :test do
  gem "blue-shell"
end

Then require and configure BlueShell in your spec_helper.rb:

require 'blue-shell'

RSpec.configure do |c|
  c.include BlueShell::Matchers
end

Usage

Running commands

Shell commands in BlueShell get executed by creating a new runner instance BlueShell::Runner.run. Running a command by default times out after 30 seconds or raises a Timeout::Error.

BlueShell::Runner.run 'sleep 1' # success
BlueShell::Runner.run 'sleep 6' # fails with Timeout::Error

Expectations on exit codes

BlueShell::Runner.run 'false' do |runner|
  runner.should exit_with 1
  runner.should have_exit_code 1 # #exit_with and #have_exit_code are aliases
end

Expectations on STDOUT

BlueShell::Runner.run 'echo "foo bar baz"' do |runner|
  runner.should say 'foo'
  runner.should have_output 'bar' # #say and #have_output are aliases
end

By default #say and #have_output will smartly wait a maximum of 30 seconds. If you need to increase that timeout, you can do so:

BlueShell::Runner.run 'sleep 35 && echo "foo bar baz"' do |runner|
  runner.with_timeout(40) do
    runner.should have_output 'bar'
  end
end

Interacting with STDIN

BlueShell::Runner.run 'read' do |runner|
  runner.send_keys 'foo'
end

BlueShell::Runner.run 'read' do |runner|
  runner.send_return
end

About timeouts...

Within the run block you can call #wait_for_exit within #with_timeout if you want to make sure your command finishes within a certain amount of time. (The default timeout is 30 seconds.)

BlueShell::Runner.run 'sleep 6' do |runner|
  runner.with_timeout(7) do
    runner.wait_for_exit
  end
end

It is important to note the difference between calling .run 'one-off' vs passing in a block:

# raises a Timeout::Error after 30 seconds
BlueShell::Runner.run 'sleep 60'

# raises a Timeout::Error after 5 seconds
BlueShell.with_timeout(5) do
  BlueShell::Runner.run 'sleep 60'
end

# succeeds
BlueShell::Runner.run 'sleep 60' do |_|
  # unless #wait_for_exit or #have_exit_code are invoked
  # your specs do not wait for the command to exit
  # and also do not fail if it never does
end

That being said, in most cases you probably want to invoke #wait_for_exit or #have_exit_code at the end of your block to ensure the command finishes.

Credits

BlueShell is maintained and funded by Pivotal Labs. Thank you to all the contributors.

Copyright

Copyright © Pivotal Labs. See LICENSE for details.

blue-shell's People

Contributors

dmrschmidt avatar mariash avatar ry4n1m3 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.