Easy output capture for testing command line tools.
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
test
.gitignore
Gemfile
README.textile
Rakefile
fakeout.gemspec

README.textile

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.