Last active
August 29, 2015 13:56
-
-
Save amolpujari/8851954 to your computer and use it in GitHub Desktop.
spec_helper.rb reading STDIO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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