Class: StubShell::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/stub_shell/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(match, context, &block) ⇒ Command

Returns a new instance of Command.



5
6
7
8
9
10
11
# File 'lib/stub_shell/command.rb', line 5

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

  instance_eval &block
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



3
4
5
# File 'lib/stub_shell/command.rb', line 3

def context
  @context
end

#matchObject (readonly)

Returns the value of attribute match.



3
4
5
# File 'lib/stub_shell/command.rb', line 3

def match
  @match
end

#resultObject (readonly)

Returns the value of attribute result.



3
4
5
# File 'lib/stub_shell/command.rb', line 3

def result
  @result
end

Instance Method Details

#current_contextObject



27
28
29
# File 'lib/stub_shell/command.rb', line 27

def current_context
  @stub_shell
end

#exitstatus(code) ⇒ Object



39
40
41
# File 'lib/stub_shell/command.rb', line 39

def exitstatus code
  result.exitstatus = code
end

#matches?(input_string) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
# File 'lib/stub_shell/command.rb', line 18

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

#stderr(output) ⇒ Object



35
36
37
# File 'lib/stub_shell/command.rb', line 35

def stderr output
  result.stderr = output
end

#stdout(output) ⇒ Object



31
32
33
# File 'lib/stub_shell/command.rb', line 31

def stdout output
  result.stdout = output
end

#stub_shell(&block) ⇒ Object

Raises:

  • (ArgumentError)


13
14
15
16
# File 'lib/stub_shell/command.rb', line 13

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