jdunphy (owner)

Forks

Revisions

gist: 231420 Download_button fork
public
Public Clone URL: git://gist.github.com/231420.git
Embed All Files: show embed
input-test-two.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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