Skip to content

Instantly share code, notes, and snippets.

@amolpujari
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amolpujari/8851954 to your computer and use it in GitHub Desktop.
Save amolpujari/8851954 to your computer and use it in GitHub Desktop.
spec_helper.rb reading STDIO
require "#{File.dirname(__FILE__)}/../lib/transactions.rb"
include Transactions
def capture_stdout(&block)
original_stdout = $stdout
$stdout = fake = StringIO.new
begin
yield
ensure
$stdout = original_stdout
end
fake.string
end
class TransactionInput
def initialize output
@output = output
end
def should_output output
@output.split("\n").should == output.split("\n")[1..-2].collect{|line| line.strip}
end
end
def transaction_input input
TransactionInput.new capture_stdout{ input.split("\n")[1..-2].each{|line| Message.new(line).process} }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment