-
-
Save cmckni3/8950218 to your computer and use it in GitHub Desktop.
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 |
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 'spec_helper' | |
describe "Transaction" do | |
it "should handle dummy numerals" do | |
transaction_input(%{ | |
x1 is I | |
x5 is V | |
x10 is X | |
x50 is L | |
x100 is C | |
x500 is D | |
x1000 is M | |
how much is x1000 x100 ? | |
how much is x1 x1 ? | |
how much is x1 x5 ? | |
} | |
).should_output(%{ | |
x1000 x100 is 1100 | |
x1 x1 is 2 | |
x1 x5 is 4 | |
}) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment