summaryrefslogtreecommitdiff
path: root/test/tc_simulator.rb
blob: a34f63a6201ec86f3400fe7f94f0385e20f96a94 (plain)
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
require 'test/unit'
require 'highline/import'
require 'highline/simulate'

class SimulatorTest < Test::Unit::TestCase
  def setup
    input     = StringIO.new
    output    = StringIO.new
    $terminal = HighLine.new(input, output)
  end

  def test_simulator
    HighLine::Simulate.with('Bugs Bunny', '18') do
      name = ask('What is your name?')

      assert_equal 'Bugs Bunny', name

      age = ask('What is your age?')

      assert_equal '18', age
    end
  end

  def test_simulate_with_echo_and_frozen_strings
    HighLine::Simulate.with('the password'.freeze) do
      password = ask('What is your password?') do |q|
        q.echo = '*'
      end

      assert_equal 'the password', password
    end
  end
end