Skip to content

Instantly share code, notes, and snippets.

@jdunphy
Created November 11, 2009 00:07
Show Gist options
  • Save jdunphy/231420 to your computer and use it in GitHub Desktop.
Save jdunphy/231420 to your computer and use it in GitHub Desktop.
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 'test/zentest_assertions'
class FancyTest < Test::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 = util_capture 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