-
-
Save tenderlove/231428 to your computer and use it in GitHub Desktop.
This file contains 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
class Fancy | |
def self.test | |
puts "Ask me a question:" | |
t = gets | |
puts "You said: #{t}" | |
puts "What about this other thing?" | |
t2 = gets | |
puts "Now you said: #{t2}" | |
end | |
end | |
require 'test/unit' | |
require 'stringio' | |
require 'rubygems' | |
require 'minitest/autorun' | |
class FancyTest < MiniTest::Unit::TestCase | |
def preload_stdin(*values) | |
orig_stdin = $stdin.dup | |
fake_stdin = StringIO.new(values.join("\n")) | |
$stdin = fake_stdin | |
yield | |
ensure | |
$stdin = orig_stdin | |
end | |
def test_can_provide_input | |
output,err = capture_io do | |
preload_stdin("Some text","Some other text") do | |
Fancy.test | |
end | |
end | |
assert_match /You said: Some text/, output | |
assert_match /Now you said: Some other text/, output | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment