Sha256: c5ab9348e683ba80c0203394424e6d801fe359a54ceacdf040b516181f466c46

Contents?: true

Size: 833 Bytes

Versions: 3

Compression:

Stored size: 833 Bytes

Contents

module StubShell
  class Command  
    attr_reader :context, :result, :match

    def initialize match, context, &block
      @match    = match
      @context = context
      @result  = Result.new

      instance_eval &block
    end

    def stub_shell &block
      raise ArgumentError, "stub_shell has already been defined for #{self}" if @stub_shell
      @stub_shell = Shell.new(self.context, &block)
    end

    def matches? input_string
      case match
      when String
        input_string == match
      when Regexp
        !!(match.match input_string)
      end
    end
    
    def current_context
      @stub_shell
    end

    def stdout output
      result.stdout = output
    end

    def stderr output
      result.stderr = output
    end

    def exitstatus code
      result.exitstatus = code
    end  
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
stub_shell-0.0.3 lib/stub_shell/command.rb
stub_shell-0.0.2 lib/stub_shell/command.rb
stub_shell-0.0.1 lib/stub_shell/command.rb