Class: ShellMock::CommandStub

Inherits:
Object
  • Object
show all
Defined in:
lib/shell_mock/command_stub.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ CommandStub

Returns a new instance of CommandStub.



8
9
10
11
12
13
14
15
16
# File 'lib/shell_mock/command_stub.rb', line 8

def initialize(command)
  @command     = command
  @env         = {}
  @options     = {}
  @side_effect = proc {}
  @exitstatus  = 0

  @reader, @writer = IO.pipe
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



6
7
8
# File 'lib/shell_mock/command_stub.rb', line 6

def command
  @command
end

#envObject (readonly)

Returns the value of attribute env.



6
7
8
# File 'lib/shell_mock/command_stub.rb', line 6

def env
  @env
end

#exitstatusObject (readonly)

Returns the value of attribute exitstatus.



6
7
8
# File 'lib/shell_mock/command_stub.rb', line 6

def exitstatus
  @exitstatus
end

#expected_outputObject (readonly)

Returns the value of attribute expected_output.



6
7
8
# File 'lib/shell_mock/command_stub.rb', line 6

def expected_output
  @expected_output
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/shell_mock/command_stub.rb', line 6

def options
  @options
end

#side_effectObject (readonly)

Returns the value of attribute side_effect.



6
7
8
# File 'lib/shell_mock/command_stub.rb', line 6

def side_effect
  @side_effect
end

#writerObject (readonly)

Returns the value of attribute writer.



6
7
8
# File 'lib/shell_mock/command_stub.rb', line 6

def writer
  @writer
end

Instance Method Details

#and_exit(exitstatus) ⇒ Object



37
38
39
40
41
# File 'lib/shell_mock/command_stub.rb', line 37

def and_exit(exitstatus)
  @exitstatus = exitstatus

  self
end

#and_return(expected_output) ⇒ Object



30
31
32
33
34
35
# File 'lib/shell_mock/command_stub.rb', line 30

def and_return(expected_output)
  @expected_output = expected_output
  @exitstatus      = 0

  self
end

#called_with(env, command, options) ⇒ Object



53
54
55
56
57
# File 'lib/shell_mock/command_stub.rb', line 53

def called_with(env, command, options)
  signature = Marshal.dump([env, command, options])

  writer.puts(signature)
end

#callsObject



43
44
45
46
47
48
49
50
51
# File 'lib/shell_mock/command_stub.rb', line 43

def calls
  @calls ||= []

  marshaled_signatures.each do |marshaled_signature|
    @calls << Marshal.load(marshaled_signature)
  end

  @calls
end

#with_env(env) ⇒ Object



18
19
20
21
22
# File 'lib/shell_mock/command_stub.rb', line 18

def with_env(env)
  @env = env

  self
end

#with_option(option) ⇒ Object



24
25
26
27
28
# File 'lib/shell_mock/command_stub.rb', line 24

def with_option(option)
  @options = options

  self
end