No commit activity in last 3 years
No release in over 3 years
Tools for testing standard inputs & outputs
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Tools for testing with $stdin, $stdout, and $stderr.

Build Status Code Climate

Use

Stderr & Stdout

By running code in a block passed to Catch::stdout or Catch::stderr, any output passed to the associated output stream will be returned.

require 'catch_and_release'

out = CatchAndRelease::Catch.stdout do
  print 'hello world'
end

out
# => "hello world"
require 'catch_and_release'

err = CatchAndRelease::Catch.stderr do
  $stderr.print 'hello world'
end

err
# => 'hello world'

Stdin

The Release::stdin will replay the passed arguments to stdin. To test code with a specific input, run it inside a block passed to ::stdin.

require 'catch_and_release'

CatchAndRelease::Release.stdin 'hello', 'world' do
  $stdin.gets.chomp
  # => 'hello'

  $stdin.gets.chomp
  # => 'world'
end

With Rspec

By including the CatchAndRelease::RSpec module in RSpec.config you can shortcut to any class method by calling #{class.downcase}_#{method}.

# spec/spec_helper.rb
require 'catch_and_release'
require 'catch_and_release/rspec'

RSpec.configure do |config|
  config.include CatchAndRelease::RSpec
end

describe "included" do
  it "has method #catch_stdout" do
    out = catch_stdout do
      print 'hello world'
    end

    expect( out ).to eq 'hello world'
  end
end

Testing

$ rspec

Contributing

If there is any thing you'd like to contribute or fix, please:

  • Fork the repo
  • Add tests for any new functionality
  • Make your changes
  • Verify all new &existing tests pass
  • Make a pull request

License

The catch_and_release gem is distributed under the MIT License.