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.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#side_effect ⇒ Object
readonly
Returns the value of attribute side_effect.
Instance Method Summary collapse
- #and_exit(exitstatus) ⇒ Object
- #and_output(output) ⇒ Object
- #and_return(output) ⇒ Object
- #called_with(env, command, options) ⇒ Object
- #calls ⇒ Object
-
#initialize(command) ⇒ CommandStub
constructor
A new instance of CommandStub.
- #to_oneliner ⇒ Object
- #with_env(env) ⇒ Object
- #with_options(options) ⇒ 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 = {} = {} @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 |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/shell_mock/command_stub.rb', line 6 def end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
6 7 8 |
# File 'lib/shell_mock/command_stub.rb', line 6 def output @output 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 |
Instance Method Details
#and_exit(exitstatus) ⇒ Object
42 43 44 45 46 |
# File 'lib/shell_mock/command_stub.rb', line 42 def and_exit(exitstatus) @exitstatus = exitstatus self end |
#and_output(output) ⇒ Object
30 31 32 33 34 |
# File 'lib/shell_mock/command_stub.rb', line 30 def and_output(output) @output = output self end |
#and_return(output) ⇒ Object
36 37 38 39 40 |
# File 'lib/shell_mock/command_stub.rb', line 36 def and_return(output) self. and_output(output). and_exit(0) end |
#called_with(env, command, options) ⇒ Object
58 59 60 |
# File 'lib/shell_mock/command_stub.rb', line 58 def called_with(env, command, ) writer.puts("called\n") end |
#calls ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/shell_mock/command_stub.rb', line 48 def calls @calls ||= 0 marshaled_signatures.each do |marshaled_signature| @calls += 1 end @calls end |
#to_oneliner ⇒ Object
62 63 64 |
# File 'lib/shell_mock/command_stub.rb', line 62 def to_oneliner "echo '#{output}' && exit #{exitstatus}" 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_options(options) ⇒ Object
24 25 26 27 28 |
# File 'lib/shell_mock/command_stub.rb', line 24 def () = self end |