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_fail ⇒ Object
- #and_output(output) ⇒ Object
- #and_return(output) ⇒ Object
- #and_succeed ⇒ Object
-
#initialize(command) ⇒ CommandStub
constructor
A new instance of CommandStub.
- #ran ⇒ Object
- #runs ⇒ Object
- #to_oneliner ⇒ Object
- #with_env(env) ⇒ Object
- #with_options(options) ⇒ Object
Constructor Details
#initialize(command) ⇒ CommandStub
Returns a new instance of CommandStub.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/shell_mock/command_stub.rb', line 7 def initialize(command) @command = command @side_effect = proc {} @reader, @writer = IO.pipe with_env({}) ({}) and_output(nil) and_succeed end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
5 6 7 |
# File 'lib/shell_mock/command_stub.rb', line 5 def command @command end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
5 6 7 |
# File 'lib/shell_mock/command_stub.rb', line 5 def env @env end |
#exitstatus ⇒ Object (readonly)
Returns the value of attribute exitstatus.
5 6 7 |
# File 'lib/shell_mock/command_stub.rb', line 5 def exitstatus @exitstatus end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/shell_mock/command_stub.rb', line 5 def end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
5 6 7 |
# File 'lib/shell_mock/command_stub.rb', line 5 def output @output end |
#side_effect ⇒ Object (readonly)
Returns the value of attribute side_effect.
5 6 7 |
# File 'lib/shell_mock/command_stub.rb', line 5 def side_effect @side_effect end |
Instance Method Details
#and_exit(exitstatus) ⇒ Object
43 44 45 46 47 |
# File 'lib/shell_mock/command_stub.rb', line 43 def and_exit(exitstatus) @exitstatus = exitstatus self end |
#and_fail ⇒ Object
53 54 55 |
# File 'lib/shell_mock/command_stub.rb', line 53 def and_fail and_exit(1) end |
#and_output(output) ⇒ Object
31 32 33 34 35 |
# File 'lib/shell_mock/command_stub.rb', line 31 def and_output(output) @output = output self end |
#and_return(output) ⇒ Object
37 38 39 40 41 |
# File 'lib/shell_mock/command_stub.rb', line 37 def and_return(output) self. and_output(output). and_exit(0) end |
#and_succeed ⇒ Object
49 50 51 |
# File 'lib/shell_mock/command_stub.rb', line 49 def and_succeed and_exit(0) end |
#ran ⇒ Object
72 73 74 |
# File 'lib/shell_mock/command_stub.rb', line 72 def ran writer.write("R") end |
#runs ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/shell_mock/command_stub.rb', line 57 def runs @runs ||= 0 loop do begin reader.read_nonblock(1) @runs += 1 rescue IO::WaitReadable break end end @runs end |
#to_oneliner ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/shell_mock/command_stub.rb', line 76 def to_oneliner if output "echo '#{output}' && exit #{exitstatus}" else "exit #{exitstatus}" end end |
#with_env(env) ⇒ Object
19 20 21 22 23 |
# File 'lib/shell_mock/command_stub.rb', line 19 def with_env(env) @env = env self end |
#with_options(options) ⇒ Object
25 26 27 28 29 |
# File 'lib/shell_mock/command_stub.rb', line 25 def () = self end |