class ShellMock::CommandStub
Attributes
command[R]
env[R]
exitstatus[R]
options[R]
output[R]
reader[R]
side_effect[R]
writer[R]
Public Class Methods
new(command)
click to toggle source
# File lib/shell_mock/command_stub.rb, line 8 def initialize(command) @command = command @side_effect = proc {} @reader, @writer = IO.pipe with_env({}) with_options({}) to_output(nil) to_succeed end
Public Instance Methods
ran()
click to toggle source
# File lib/shell_mock/command_stub.rb, line 83 def ran writer.write("R") end
runs()
click to toggle source
# 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)
click to toggle source
# File lib/shell_mock/command_stub.rb, line 48 def to_exit(exitstatus) @exitstatus = exitstatus self end
Also aliased as: and_exit
to_fail()
click to toggle source
# File lib/shell_mock/command_stub.rb, line 62 def to_fail to_exit(1) end
Also aliased as: and_fail
to_oneliner()
click to toggle source
# 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)
click to toggle source
# File lib/shell_mock/command_stub.rb, line 32 def to_output(output) @output = output self end
Also aliased as: and_output
to_return(output)
click to toggle source
# File lib/shell_mock/command_stub.rb, line 40 def to_return(output) self. to_output(output). to_exit(0) end
Also aliased as: and_return
to_succeed()
click to toggle source
# File lib/shell_mock/command_stub.rb, line 56 def to_succeed to_exit(0) end
Also aliased as: and_succeed
with_env(env)
click to toggle source
# File lib/shell_mock/command_stub.rb, line 20 def with_env(env) @env = env self end
with_options(options)
click to toggle source
# File lib/shell_mock/command_stub.rb, line 26 def with_options(options) @options = options self end