class FlexMock::CallValidator
A CallValidator checks the list of call records for a particular method name and arguments.
Public Instance Methods
received?(calls, method_name, args, options)
click to toggle source
Does the calls
list record a method named
method_name
with args
. Options include:
-
:times => n – If given, the call should match exactly
n
times. -
:and => [] – A list of argument validations to be run on each
matching invocation.
-
:on_count => n – If given, the :and validations on only run on the
nth invocation.
# File lib/flexmock/call_validator.rb, line 27 def received?(calls, method_name, args, options) count = 0 calls.each { |call_record| if call_record.matches?(method_name, args, options) count += 1 run_additional_validations(call_record, count, options) end } count_matches?(count, options[:times]) end
Private Instance Methods
additionals(options)
click to toggle source
# File lib/flexmock/call_validator.rb, line 40 def additionals(options) ands = options[:and] if ands.nil? [] elsif ands.is_a?(Proc) [ands] else ands end end
count_matches?(count, times)
click to toggle source
# File lib/flexmock/call_validator.rb, line 59 def count_matches?(count, times) if times count == times else count > 0 end end
run_additional_validations(call_record, count, options)
click to toggle source
# File lib/flexmock/call_validator.rb, line 51 def run_additional_validations(call_record, count, options) if options[:on_count].nil? || count == options[:on_count] additionals(options).each do |add| add.call(*call_record.args) end end end