Class: Rspec::Bash::CallLog

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCallLog

Returns a new instance of CallLog.



6
7
8
# File 'lib/rspec/bash/command/call_log.rb', line 6

def initialize
  @call_log = []
end

Instance Attribute Details

#call_logObject

Returns the value of attribute call_log.



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

def call_log
  @call_log
end

Instance Method Details

#add_log(stdin, argument_list) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/rspec/bash/command/call_log.rb', line 35

def add_log(stdin, argument_list)
  updated_log = @call_log
  updated_log << {
    args: argument_list,
    stdin: stdin
  }
end

#call_count(argument_list) ⇒ Object



16
17
18
19
# File 'lib/rspec/bash/command/call_log.rb', line 16

def call_count(argument_list)
  call_argument_list_matcher = Util::CallLogArgumentListMatcher.new(argument_list)
  call_argument_list_matcher.get_call_count(call_log)
end

#call_log_argumentsObject



43
44
45
# File 'lib/rspec/bash/command/call_log.rb', line 43

def call_log_arguments
  @call_log.map { |call_log| call_log[:args] || [] }.compact
end

#called_with_args?(argument_list) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/rspec/bash/command/call_log.rb', line 21

def called_with_args?(argument_list)
  call_argument_list_matcher = Util::CallLogArgumentListMatcher.new(argument_list)
  call_argument_list_matcher.args_match?(call_log)
end

#called_with_no_args?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
# File 'lib/rspec/bash/command/call_log.rb', line 26

def called_with_no_args?
  return false if @call_log.empty?

  @call_log.all? do |call_log|
    argument_list = call_log[:args] || []
    argument_list.empty?
  end
end

#stdin_for_args(argument_list) ⇒ Object



10
11
12
13
14
# File 'lib/rspec/bash/command/call_log.rb', line 10

def stdin_for_args(argument_list)
  call_argument_list_matcher = Util::CallLogArgumentListMatcher.new(argument_list)
  matching_call_log_list = call_argument_list_matcher.get_call_log_matches(call_log)
  matching_call_log_list.first[:stdin] unless matching_call_log_list.empty?
end