Project

fakeout

0.0
No commit activity in last 3 years
No release in over 3 years
Fakeout captures STDOUT and STDERR for command line testing.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 2.5.0
 Project Readme

Fakeout

Fakeout is an easy way of testing the output of your command line tools and libraries.

It catches all output to $stdout and $stderr while activated so you can test the correct output is given by your library or script. It also has the nice side-effect of keeping your test results from being crapped up with non test result text and data.

Usage

To load and activate Fakeout:

require "fakeout"

Manually Activate and Deactivate

If you want to control when Fakeout starts and stops capturing output:

require "fakeout/safe"

Fakeout.activate!
# your code
Fakeout.deactivate!

Both of the approaches above work for RSpec, UnitTest, or whatever.

Helpers

Including the Fakeout::TestHelpers module into your spec or test class exposes two objects, stdout and stderr, each containing any output sent, while Fakeout is activated, to $stdout and $stderr, respectively.

it "should rawr to $stdout" do
  lion.rawr_to_stdout
  stdout.should include "RAWR!!"
end

RSpec

Fakeout::SpecHelpers will automatically activate before each example and deactivate after each one when included. It can be included into individual Example Groups:

describe "Something" do
  include Fakeout::SpecHelpers
end

or included into all Example Groups:

RSpec.config do |c|
  c.include Fakeout::SpecHelpers
end

* Note that if you use SpecHelpers with RSpec, you DO NOT need to include TestHelpers.

Test::Unit

class SomethingTest < Test::Unit::TestCase
  include Fakeout::TestHelpers
  
  def setup
    Fakeout.activate!
  end
  
  def teardown
    Fakeout.deactivate!
  end
end

Installation

$ gem install fakeout

Contribution

1. Fork Fakeout
2. Create a topic branch – git checkout -b branch_name
3. Push branch to your fork – git push origin branch_name
4. Send a pull request

Thanks

Defunkt for FakeFS, which much of Fakeout is modeled after.