Sha256: c028dc6a602286eb3328031f647190a5a24f3e9a8ef42da2dfc50230efe22a34

Contents?: true

Size: 1.23 KB

Versions: 239

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

239 entries across 238 versions & 12 rubygems

Version Path
skylight-6.1.0.beta lib/skylight/vendor/cli/highline/simulate.rb
skylight-6.0.4 lib/skylight/vendor/cli/highline/simulate.rb
skylight-6.0.3 lib/skylight/vendor/cli/highline/simulate.rb
skylight-5.3.5 lib/skylight/vendor/cli/highline/simulate.rb
skylight-6.0.2 lib/skylight/vendor/cli/highline/simulate.rb
skylight-6.0.1 lib/skylight/vendor/cli/highline/simulate.rb
skylight-6.0.0 lib/skylight/vendor/cli/highline/simulate.rb
skylight-6.0.0.beta2 lib/skylight/vendor/cli/highline/simulate.rb
skylight-6.0.0.beta lib/skylight/vendor/cli/highline/simulate.rb
skylight-5.3.4 lib/skylight/vendor/cli/highline/simulate.rb
skylight-5.3.3 lib/skylight/vendor/cli/highline/simulate.rb
skylight-5.3.2 lib/skylight/vendor/cli/highline/simulate.rb
skylight-5.3.1 lib/skylight/vendor/cli/highline/simulate.rb
skylight-5.3.0 lib/skylight/vendor/cli/highline/simulate.rb
skylight-5.2.0 lib/skylight/vendor/cli/highline/simulate.rb
skylight-5.2.0.beta2 lib/skylight/vendor/cli/highline/simulate.rb
skylight-5.2.0.beta lib/skylight/vendor/cli/highline/simulate.rb
skylight-5.1.1 lib/skylight/vendor/cli/highline/simulate.rb
skylight-5.1.0.beta3 lib/skylight/vendor/cli/highline/simulate.rb
skylight-5.1.0.beta2 lib/skylight/vendor/cli/highline/simulate.rb