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
-
#initialize(command) ⇒ CommandStub
constructor
A new instance of CommandStub.
- #ran ⇒ Object
- #runs ⇒ Object
- #to_exit(exitstatus) ⇒ Object (also: #and_exit)
- #to_fail ⇒ Object (also: #and_fail)
- #to_oneliner ⇒ Object
- #to_output(output) ⇒ Object (also: #and_output)
- #to_return(output) ⇒ Object (also: #and_return)
- #to_succeed ⇒ Object (also: #and_succeed)
- #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 17 18 |
# File 'lib/shell_mock/command_stub.rb', line 8 def initialize(command) @command = command @side_effect = proc {} @reader, @writer = IO.pipe with_env({}) ({}) to_output(nil) to_succeed 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 @options 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
#ran ⇒ Object
83 84 85 |
# File 'lib/shell_mock/command_stub.rb', line 83 def ran writer.write("R") end |
#runs ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/shell_mock/command_stub.rb', line 68 def runs @runs ||= 0 loop do begin reader.read_nonblock(1) @runs += 1 rescue IO::WaitReadable break end end @runs end |
#to_exit(exitstatus) ⇒ Object Also known as: and_exit
48 49 50 51 52 |
# File 'lib/shell_mock/command_stub.rb', line 48 def to_exit(exitstatus) @exitstatus = exitstatus self end |
#to_fail ⇒ Object Also known as: and_fail
62 63 64 |
# File 'lib/shell_mock/command_stub.rb', line 62 def to_fail to_exit(1) end |
#to_oneliner ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/shell_mock/command_stub.rb', line 87 def to_oneliner if output "echo '#{output}' && exit #{exitstatus}" else "exit #{exitstatus}" end end |
#to_output(output) ⇒ Object Also known as: and_output
32 33 34 35 36 |
# File 'lib/shell_mock/command_stub.rb', line 32 def to_output(output) @output = output self end |
#to_return(output) ⇒ Object Also known as: and_return
40 41 42 43 44 |
# File 'lib/shell_mock/command_stub.rb', line 40 def to_return(output) self. to_output(output). to_exit(0) end |
#to_succeed ⇒ Object Also known as: and_succeed
56 57 58 |
# File 'lib/shell_mock/command_stub.rb', line 56 def to_succeed to_exit(0) end |
#with_env(env) ⇒ Object
20 21 22 23 24 |
# File 'lib/shell_mock/command_stub.rb', line 20 def with_env(env) @env = env self end |
#with_options(options) ⇒ Object
26 27 28 29 30 |
# File 'lib/shell_mock/command_stub.rb', line 26 def () @options = self end |