class RR::Double

RR::Double is the use case for a method call. It has the ArgumentEqualityExpectation, TimesCalledExpectation, and the implementation.

Attributes

definition[R]
double_injection[R]
times_called[R]
times_called_expectation[R]

Public Class Methods

new(double_injection, definition) click to toggle source
# File lib/rr/double.rb, line 23
def initialize(double_injection, definition)
  @double_injection = double_injection
  @definition = definition
  @times_called = 0
  @times_called_expectation = Expectations::TimesCalledExpectation.new(self)
  definition.double = self
  verify_method_signature if definition.verify_method_signature?
  double_injection.register_double self
end

Public Instance Methods

attempt?() click to toggle source

Double#attempt? returns true when the TimesCalledExpectation is satisfied.

# File lib/rr/double.rb, line 47
def attempt?
  verify_times_matcher_is_set
  times_called_expectation.attempt?
end
exact_match?(*arguments) click to toggle source

Double#exact_match? returns true when the passed in arguments exactly match the ArgumentEqualityExpectation arguments.

# File lib/rr/double.rb, line 35
def exact_match?(*arguments)
  definition.exact_match?(*arguments)
end
expected_arguments() click to toggle source

The Arguments that this Double expects

# File lib/rr/double.rb, line 72
def expected_arguments
  verify_argument_expectation_is_set
  argument_expectation.expected_arguments
end
formatted_name() click to toggle source
# File lib/rr/double.rb, line 82
def formatted_name
  self.class.formatted_name(method_name, expected_arguments)
end
implementation_is_original_method?() click to toggle source
# File lib/rr/double.rb, line 94
def implementation_is_original_method?
  definition.implementation_is_original_method?
end
method_call(args) click to toggle source
# File lib/rr/double.rb, line 86
def method_call(args)
  if verbose?
    puts Double.formatted_name(method_name, args)
  end
  times_called_expectation.attempt if definition.times_matcher
  space.verify_ordered_double(self) if ordered?
end
method_name() click to toggle source

The method name that this Double is attatched to

# File lib/rr/double.rb, line 67
def method_name
  double_injection.method_name
end
terminal?() click to toggle source
# File lib/rr/double.rb, line 61
def terminal?
  verify_times_matcher_is_set
  times_called_expectation.terminal?
end
times_matcher() click to toggle source

The TimesCalledMatcher for the TimesCalledExpectation

# File lib/rr/double.rb, line 78
def times_matcher
  definition.times_matcher
end
verify() click to toggle source

Double#verify verifies the the TimesCalledExpectation is satisfied for this double. A TimesCalledError is raised if the TimesCalledExpectation is not met.

# File lib/rr/double.rb, line 55
def verify
  verify_times_matcher_is_set
  times_called_expectation.verify!
  true
end
wildcard_match?(*arguments) click to toggle source

Double#wildcard_match? returns true when the passed in arguments wildcard match the ArgumentEqualityExpectation arguments.

# File lib/rr/double.rb, line 41
def wildcard_match?(*arguments)
  definition.wildcard_match?(*arguments)
end

Protected Instance Methods

args() click to toggle source
# File lib/rr/double.rb, line 147
def args
  definition.argument_expectation.expected_arguments
end
argument_expectation() click to toggle source
# File lib/rr/double.rb, line 151
def argument_expectation
  definition.argument_expectation
end
arity_matches?() click to toggle source
# File lib/rr/double.rb, line 138
def arity_matches?
  return true if subject_accepts_only_varargs?
  if subject_accepts_varargs?
    return ((subject_arity * -1) - 1) <= args.size
  else
    return subject_arity == args.size
  end
end
ordered?() click to toggle source
# File lib/rr/double.rb, line 99
def ordered?
  definition.ordered?
end
subject_accepts_only_varargs?() click to toggle source
# File lib/rr/double.rb, line 130
def subject_accepts_only_varargs?
  subject_arity == -1
end
subject_accepts_varargs?() click to toggle source
# File lib/rr/double.rb, line 134
def subject_accepts_varargs?
  subject_arity < 0
end
subject_arity() click to toggle source
# File lib/rr/double.rb, line 126
def subject_arity
  double_injection.original_method.arity
end
verbose?() click to toggle source
# File lib/rr/double.rb, line 103
def verbose?
  definition.verbose?
end
verify_argument_expectation_is_set() click to toggle source
# File lib/rr/double.rb, line 113
def verify_argument_expectation_is_set
  unless definition.argument_expectation
    raise RR::Errors.build_error(:DoubleDefinitionError, "#definition.argument_expectation is not set")
  end
end
verify_method_signature() click to toggle source
# File lib/rr/double.rb, line 119
def verify_method_signature
  unless double_injection.subject_has_original_method?
    raise RR::Errors.build_error(:SubjectDoesNotImplementMethodError)
  end
  raise RR::Errors.build_error(:SubjectHasDifferentArityError) unless arity_matches?
end
verify_times_matcher_is_set() click to toggle source
# File lib/rr/double.rb, line 107
def verify_times_matcher_is_set
  unless definition.times_matcher
    raise RR::Errors.build_error(:DoubleDefinitionError, "#definition.times_matcher is not set")
  end
end