In Files

Parent

Included Modules

Class Index [+]

Quicksearch

RR::Double

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

Attributes

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

Public Class Methods

formatted_name(method_name, args) click to toggle source
    # File lib/rr/double.rb, line 7
 7:       def formatted_name(method_name, args)
 8:         formatted_errors = args.collect {|arg| arg.inspect}.join(', ')
 9:         "#{method_name}(#{formatted_errors})"
10:       end
list_message_part(doubles) click to toggle source
    # File lib/rr/double.rb, line 12
12:       def list_message_part(doubles)
13:         doubles.collect do |double|
14:           "- #{formatted_name(double.method_name, double.expected_arguments)}"
15:         end.join("\n")
16:       end
new(double_injection, definition) click to toggle source
    # File lib/rr/double.rb, line 22
22:     def initialize(double_injection, definition)
23:       @double_injection = double_injection
24:       @definition = definition
25:       @times_called = 0
26:       @times_called_expectation = Expectations::TimesCalledExpectation.new(self)
27:       definition.double = self
28:       verify_method_signature if definition.verify_method_signature?
29:       double_injection.register_double self
30:     end

Public Instance Methods

attempt?() click to toggle source

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

    # File lib/rr/double.rb, line 46
46:     def attempt?
47:       verify_times_matcher_is_set
48:       times_called_expectation.attempt?
49:     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 34
34:     def exact_match?(*arguments)
35:       definition.exact_match?(*arguments)
36:     end
expected_arguments() click to toggle source

The Arguments that this Double expects

    # File lib/rr/double.rb, line 71
71:     def expected_arguments
72:       verify_argument_expectation_is_set
73:       argument_expectation.expected_arguments
74:     end
formatted_name() click to toggle source
    # File lib/rr/double.rb, line 81
81:     def formatted_name
82:       self.class.formatted_name(method_name, expected_arguments)
83:     end
implementation_is_original_method?() click to toggle source
    # File lib/rr/double.rb, line 93
93:     def implementation_is_original_method?
94:       definition.implementation_is_original_method?
95:     end
method_call(args) click to toggle source
    # File lib/rr/double.rb, line 85
85:     def method_call(args)
86:       if verbose?
87:         puts Double.formatted_name(method_name, args)
88:       end
89:       times_called_expectation.attempt if definition.times_matcher
90:       space.verify_ordered_double(self) if ordered?
91:     end
method_name() click to toggle source

The method name that this Double is attatched to

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

The TimesCalledMatcher for the TimesCalledExpectation

    # File lib/rr/double.rb, line 77
77:     def times_matcher
78:       definition.times_matcher
79:     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 54
54:     def verify
55:       verify_times_matcher_is_set
56:       times_called_expectation.verify!
57:       true
58:     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 40
40:     def wildcard_match?(*arguments)
41:       definition.wildcard_match?(*arguments)
42:     end

Protected Instance Methods

args() click to toggle source
     # File lib/rr/double.rb, line 144
144:     def args
145:       definition.argument_expectation.expected_arguments
146:     end
argument_expectation() click to toggle source
     # File lib/rr/double.rb, line 148
148:     def argument_expectation
149:       definition.argument_expectation
150:     end
arity_matches?() click to toggle source
     # File lib/rr/double.rb, line 135
135:     def arity_matches?
136:       return true if subject_accepts_only_varargs?
137:       if subject_accepts_varargs?
138:         return ((subject_arity * 1) - 1) <= args.size
139:       else
140:         return subject_arity == args.size
141:       end
142:     end
ordered?() click to toggle source
     # File lib/rr/double.rb, line 98
 98:     def ordered?
 99:       definition.ordered?
100:     end
subject_accepts_only_varargs?() click to toggle source
     # File lib/rr/double.rb, line 127
127:     def subject_accepts_only_varargs?
128:       subject_arity == 1
129:     end
subject_accepts_varargs?() click to toggle source
     # File lib/rr/double.rb, line 131
131:     def subject_accepts_varargs?
132:       subject_arity < 0
133:     end
subject_arity() click to toggle source
     # File lib/rr/double.rb, line 123
123:     def subject_arity
124:       definition.subject.method(double_injection.send(:original_method_alias_name)).arity
125:     end
verbose?() click to toggle source
     # File lib/rr/double.rb, line 102
102:     def verbose?
103:       definition.verbose?
104:     end
verify_argument_expectation_is_set() click to toggle source
     # File lib/rr/double.rb, line 112
112:     def verify_argument_expectation_is_set
113:       unless definition.argument_expectation
114:         raise RR::Errors::DoubleDefinitionError, "#definition.argument_expectation is not set"
115:       end
116:     end
verify_method_signature() click to toggle source
     # File lib/rr/double.rb, line 118
118:     def verify_method_signature
119:       raise RR::Errors::SubjectDoesNotImplementMethodError unless definition.subject.respond_to?(double_injection.send(:original_method_alias_name))
120:       raise RR::Errors::SubjectHasDifferentArityError unless arity_matches?
121:     end
verify_times_matcher_is_set() click to toggle source
     # File lib/rr/double.rb, line 106
106:     def verify_times_matcher_is_set
107:       unless definition.times_matcher
108:         raise RR::Errors::DoubleDefinitionError, "#definition.times_matcher is not set"
109:       end
110:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.