Class: Rspec::Shell::Expectations::StubbedCall

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/shell/expectations/stubbed_call.rb

Overview

A specific call with arguments on a StubbedCommand

Instance Method Summary collapse

Constructor Details

#initialize(config, call_log, args) ⇒ StubbedCall

Returns a new instance of StubbedCall.



6
7
8
# File 'lib/rspec/shell/expectations/stubbed_call.rb', line 6

def initialize(config, call_log, args)
  @config, @call_log, @args = config, call_log, args
end

Instance Method Details

#called?Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/rspec/shell/expectations/stubbed_call.rb', line 31

def called?
  return false unless @call_log.exist?
  @call_log.called_with_args?(*@args)
end

#inspectObject



36
37
38
39
40
41
42
43
# File 'lib/rspec/shell/expectations/stubbed_call.rb', line 36

def inspect
  if @args.any?
    "<Stubbed #{@config.command.inspect} " \
      "args: #{@args.join(' ').inspect}>"
  else
    "<Stubbed #{@config.command.inspect}>"
  end
end

#outputs(content, to: :stdout) ⇒ Object



20
21
22
23
24
# File 'lib/rspec/shell/expectations/stubbed_call.rb', line 20

def outputs(content, to: :stdout)
  @config.set_output(content, to, @args)
  @config.write
  self
end

#returns_exitstatus(statuscode) ⇒ Object



14
15
16
17
18
# File 'lib/rspec/shell/expectations/stubbed_call.rb', line 14

def returns_exitstatus(statuscode)
  @config.set_exitcode(statuscode, @args)
  @config.write
  self
end

#stdinObject



26
27
28
29
# File 'lib/rspec/shell/expectations/stubbed_call.rb', line 26

def stdin
  return nil unless @call_log.exist?
  @call_log.stdin_for_args(*@args)
end

#with_args(*args) ⇒ Object



10
11
12
# File 'lib/rspec/shell/expectations/stubbed_call.rb', line 10

def with_args(*args)
  StubbedCall.new(@config, @call_log, @args + args)
end