Skip to content

Instantly share code, notes, and snippets.

@mkb
Created November 16, 2012 20:15
Show Gist options
  • Save mkb/4090511 to your computer and use it in GitHub Desktop.
Save mkb/4090511 to your computer and use it in GitHub Desktop.
Avoid printing directly to stdout to make testing easier.
class Foo
def bar(outstream)
outstream.puts "BAZ"
end
end
$: << '.'
require 'foo'
describe Foo do
let(:foo) { Foo.new }
let(:outstream) { StringIO.new }
it 'outputs bar' do
foo.bar(outstream)
outstream.string.should match(/baz/i)
end
end
#!/usr/bin/env ruby
$: << '.'
require 'foo'
foo = Foo.new
foo.bar(STDOUT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment