class Object
Constants
- NO_SUBJECT
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
all_instances_of(subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
Alias for: instance_of
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
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
call(method_name, *args, &handler)
click to toggle source
# File lib/rr/double_definitions/double_definition_create.rb, line 33 def call(method_name, *args, &handler) definition = DoubleDefinition.new(self) verification_strategy.call(definition, method_name, args, handler) implementation_strategy.call(definition, method_name, args, handler) double_injection_strategy.call(definition, method_name, args, handler) definition end
dont_allow(subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
click to toggle source
# File lib/rr/double_definitions/double_definition_create.rb, line 120 def dont_allow(subject=NO_SUBJECT, method_name=nil, &definition_eval_block) self.add_verification_strategy(::RR::DoubleDefinitions::Strategies::Verification::DontAllow, subject, method_name, &definition_eval_block) 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
instance_of(subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
click to toggle source
DoubleInjection Strategies
# File lib/rr/double_definitions/double_definition_create.rb, line 136 def instance_of(subject=NO_SUBJECT, method_name=nil, &definition_eval_block) self.add_double_injection_strategy(::RR::DoubleDefinitions::Strategies::DoubleInjection::AnyInstanceOf, subject, method_name, &definition_eval_block) end
Also aliased as: any_instance_of, all_instances_of
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
mock(subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
click to toggle source
# File lib/rr/double_definitions/double_definition_create.rb, line 112 def mock(subject=NO_SUBJECT, method_name=nil, &definition_eval_block) self.add_verification_strategy(::RR::DoubleDefinitions::Strategies::Verification::Mock, subject, method_name, &definition_eval_block) end
ordered?()
click to toggle source
# File lib/rr/double.rb, line 99 def ordered? definition.ordered? end
proxy(subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
click to toggle source
Implementation Strategies
# File lib/rr/double_definitions/double_definition_create.rb, line 126 def proxy(subject=NO_SUBJECT, method_name=nil, &definition_eval_block) self.add_implementation_strategy(::RR::DoubleDefinitions::Strategies::Implementation::Proxy, subject, method_name, &definition_eval_block) end
root_subject()
click to toggle source
# File lib/rr/double_definitions/double_definition_create.rb, line 41 def root_subject subject end
strong(subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
click to toggle source
# File lib/rr/double_definitions/double_definition_create.rb, line 130 def strong(subject=NO_SUBJECT, method_name=nil, &definition_eval_block) self.add_implementation_strategy(::RR::DoubleDefinitions::Strategies::Implementation::StronglyTypedReimplementation, subject, method_name, &definition_eval_block) end
stub(subject=NO_SUBJECT, method_name=nil, &definition_eval_block)
click to toggle source
# File lib/rr/double_definitions/double_definition_create.rb, line 116 def stub(subject=NO_SUBJECT, method_name=nil, &definition_eval_block) self.add_verification_strategy(::RR::DoubleDefinitions::Strategies::Verification::Stub, subject, method_name, &definition_eval_block) 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
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
verbose?()
click to toggle source
# File lib/rr/double.rb, line 103 def verbose? definition.verbose? 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
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
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