Sha256: f0362d4604efe69bbad03c53a272dd34dc4b78af87ca5c325b8831a92e597ae4

Contents?: true

Size: 1.23 KB

Versions: 26

Compression:

Stored size: 1.23 KB

Contents

# simulate.rb
#
#  Created by Andy Rossmeissl on 2012-04-29.
#  Copyright 2005 Gray Productions. All rights reserved.
#
#  This is Free Software.  See LICENSE and COPYING for details.
#
# adapted from https://gist.github.com/194554
class HighLine

  # Simulates Highline input for use in tests.
  class Simulate

    # Creates a simulator with an array of Strings as a script
    def initialize(strings)
      @strings = strings
    end
    
    # Simulate StringIO#gets by shifting a string off of the script
    def gets
      @strings.shift
    end

    # Simulate StringIO#getbyte by shifting a single character off of the next line of the script
    def getbyte
      line = gets
      if line.length > 0
        char = line.slice! 0
        @strings.unshift line
        char
      end
    end

    # The simulator handles its own EOF
    def eof?
      false
    end

    # A wrapper method that temporarily replaces the Highline instance in $terminal with an instance of this object for the duration of the block
    def self.with(*strings)
      @input = $terminal.instance_variable_get :@input
      $terminal.instance_variable_set :@input, new(strings)
      yield
    ensure
      $terminal.instance_variable_set :@input, @input
    end
  end
end

Version data entries

26 entries across 18 versions & 4 rubygems

Version Path
challah-1.0.0.beta vendor/bundle/gems/highline-1.6.15/lib/highline/simulate.rb
challah-0.9.1.beta.3 vendor/bundle/gems/highline-1.6.15/lib/highline/simulate.rb
challah-0.9.1.beta vendor/bundle/gems/highline-1.6.15/lib/highline/simulate.rb
challah-0.9.0 vendor/bundle/gems/highline-1.6.15/lib/highline/simulate.rb
challah-rolls-0.2.0 vendor/bundle/gems/highline-1.6.15/lib/highline/simulate.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/highline-1.6.13/lib/highline/simulate.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/highline-1.6.14/lib/highline/simulate.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/highline-1.6.15/lib/highline/simulate.rb
challah-rolls-0.2.0 vendor/bundle/gems/highline-1.6.13/lib/highline/simulate.rb
challah-rolls-0.2.0 vendor/bundle/gems/highline-1.6.14/lib/highline/simulate.rb
challah-0.8.3 vendor/bundle/gems/highline-1.6.14/lib/highline/simulate.rb
challah-0.8.3 vendor/bundle/gems/highline-1.6.15/lib/highline/simulate.rb
challah-0.8.1 vendor/bundle/gems/highline-1.6.14/lib/highline/simulate.rb
highline-1.6.15 lib/highline/simulate.rb
challah-rolls-0.1.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/highline-1.6.13/lib/highline/simulate.rb
challah-rolls-0.1.0 vendor/bundle/gems/highline-1.6.14/lib/highline/simulate.rb
challah-rolls-0.1.0 vendor/bundle/gems/highline-1.6.13/lib/highline/simulate.rb
challah-0.8.0.pre vendor/bundle/gems/highline-1.6.13/lib/highline/simulate.rb
challah-0.7.1 vendor/bundle/gems/highline-1.6.13/lib/highline/simulate.rb
highline-1.6.14 lib/highline/simulate.rb