Class: Rspec::Bash::StubbedCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/bash/stubbed_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, dir) ⇒ StubbedCommand

Returns a new instance of StubbedCommand.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rspec/bash/stubbed_command.rb', line 6

def initialize(command, dir)
  @path = create_stub_file(command, dir)
  @arguments = []
  @call_configuration = CallConfiguration.new(
    Pathname.new(dir).join("#{command}_stub.yml"),
    command
  )
  @call_log = CallLog.new(
    Pathname.new(dir).join("#{command}_calls.yml")
  )
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



4
5
6
# File 'lib/rspec/bash/stubbed_command.rb', line 4

def arguments
  @arguments
end

#call_logObject (readonly)

Returns the value of attribute call_log.



4
5
6
# File 'lib/rspec/bash/stubbed_command.rb', line 4

def call_log
  @call_log
end

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/rspec/bash/stubbed_command.rb', line 4

def path
  @path
end

Instance Method Details

#call_count(*arg) ⇒ Object



35
36
37
# File 'lib/rspec/bash/stubbed_command.rb', line 35

def call_count(*arg)
  @call_log.call_count(*arg)
end

#called?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/rspec/bash/stubbed_command.rb', line 23

def called?
  @call_log.exist? && @call_log.called_with_args?(*@args)
end

#called_with_args?(*args) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/rspec/bash/stubbed_command.rb', line 31

def called_with_args?(*args)
  @call_log.called_with_args?(*args)
end

#called_with_no_args?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/rspec/bash/stubbed_command.rb', line 27

def called_with_no_args?
  @call_log.called_with_no_args?
end

#commandObject



39
40
41
# File 'lib/rspec/bash/stubbed_command.rb', line 39

def command
  @call_configuration.command
end

#inspectObject



57
58
59
60
61
62
63
64
# File 'lib/rspec/bash/stubbed_command.rb', line 57

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

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



48
49
50
51
# File 'lib/rspec/bash/stubbed_command.rb', line 48

def outputs(contents, to: :stdout)
  @call_configuration.add_output(contents, to, @arguments)
  self
end

#returns_exitstatus(exitcode) ⇒ Object



43
44
45
46
# File 'lib/rspec/bash/stubbed_command.rb', line 43

def returns_exitstatus(exitcode)
  @call_configuration.set_exitcode(exitcode, @arguments)
  self
end

#stdinObject



53
54
55
# File 'lib/rspec/bash/stubbed_command.rb', line 53

def stdin
  @call_log.stdin_for_args(*@arguments) if @call_log.exist?
end

#with_args(*args) ⇒ Object



18
19
20
21
# File 'lib/rspec/bash/stubbed_command.rb', line 18

def with_args(*args)
  @arguments = args
  self
end