Class: ShellMock::CommandStub
- Inherits:
-
Object
- Object
- ShellMock::CommandStub
- Defined in:
- lib/shell_mock/command_stub.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#exitstatus ⇒ Object
readonly
Returns the value of attribute exitstatus.
-
#expected_output ⇒ Object
readonly
Returns the value of attribute expected_output.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#side_effect ⇒ Object
readonly
Returns the value of attribute side_effect.
-
#writer ⇒ Object
readonly
Returns the value of attribute writer.
Instance Method Summary collapse
- #and_exit(exitstatus) ⇒ Object
- #and_return(expected_output) ⇒ Object
- #called_with(env, command, options) ⇒ Object
- #calls ⇒ Object
-
#initialize(command) ⇒ CommandStub
constructor
A new instance of CommandStub.
- #with_env(env) ⇒ Object
- #with_option(option) ⇒ Object
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
#command ⇒ Object (readonly)
Returns the value of attribute command.
6 7 8 |
# File 'lib/shell_mock/command_stub.rb', line 6 def command @command end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
6 7 8 |
# File 'lib/shell_mock/command_stub.rb', line 6 def env @env end |
#exitstatus ⇒ Object (readonly)
Returns the value of attribute exitstatus.
6 7 8 |
# File 'lib/shell_mock/command_stub.rb', line 6 def exitstatus @exitstatus end |
#expected_output ⇒ Object (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 |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/shell_mock/command_stub.rb', line 6 def @options end |
#side_effect ⇒ Object (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 |
#writer ⇒ Object (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, ) signature = Marshal.dump([env, command, ]) writer.puts(signature) end |
#calls ⇒ Object
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 = self end |