mcmire-rr 1.0.5.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +269 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +47 -0
- data/LICENSE +22 -0
- data/README.rdoc +390 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/rr.rb +101 -0
- data/lib/rr/adapters/minitest.rb +31 -0
- data/lib/rr/adapters/rr_methods.rb +146 -0
- data/lib/rr/adapters/rspec.rb +61 -0
- data/lib/rr/adapters/rspec2.rb +22 -0
- data/lib/rr/adapters/test_unit.rb +31 -0
- data/lib/rr/blank_slate.rb +17 -0
- data/lib/rr/class_instance_method_defined.rb +9 -0
- data/lib/rr/double.rb +154 -0
- data/lib/rr/double_definitions/child_double_definition_create.rb +27 -0
- data/lib/rr/double_definitions/double_definition.rb +365 -0
- data/lib/rr/double_definitions/double_definition_create.rb +139 -0
- data/lib/rr/double_definitions/double_definition_create_blank_slate.rb +26 -0
- data/lib/rr/double_definitions/double_injections/any_instance_of.rb +28 -0
- data/lib/rr/double_definitions/double_injections/instance.rb +16 -0
- data/lib/rr/double_definitions/strategies/double_injection/any_instance_of.rb +30 -0
- data/lib/rr/double_definitions/strategies/double_injection/double_injection_strategy.rb +10 -0
- data/lib/rr/double_definitions/strategies/double_injection/instance.rb +17 -0
- data/lib/rr/double_definitions/strategies/implementation/implementation_strategy.rb +10 -0
- data/lib/rr/double_definitions/strategies/implementation/proxy.rb +60 -0
- data/lib/rr/double_definitions/strategies/implementation/reimplementation.rb +14 -0
- data/lib/rr/double_definitions/strategies/implementation/strongly_typed_reimplementation.rb +15 -0
- data/lib/rr/double_definitions/strategies/strategy.rb +43 -0
- data/lib/rr/double_definitions/strategies/strategy_methods.rb +53 -0
- data/lib/rr/double_definitions/strategies/verification/dont_allow.rb +31 -0
- data/lib/rr/double_definitions/strategies/verification/mock.rb +42 -0
- data/lib/rr/double_definitions/strategies/verification/stub.rb +43 -0
- data/lib/rr/double_definitions/strategies/verification/verification_strategy.rb +10 -0
- data/lib/rr/double_matches.rb +42 -0
- data/lib/rr/errors/argument_equality_error.rb +6 -0
- data/lib/rr/errors/double_definition_error.rb +6 -0
- data/lib/rr/errors/double_not_found_error.rb +6 -0
- data/lib/rr/errors/double_order_error.rb +6 -0
- data/lib/rr/errors/rr_error.rb +20 -0
- data/lib/rr/errors/spy_verification_errors/double_injection_not_found_error.rb +8 -0
- data/lib/rr/errors/spy_verification_errors/invocation_count_error.rb +8 -0
- data/lib/rr/errors/spy_verification_errors/spy_verification_error.rb +8 -0
- data/lib/rr/errors/subject_does_not_implement_method_error.rb +6 -0
- data/lib/rr/errors/subject_has_different_arity_error.rb +6 -0
- data/lib/rr/errors/times_called_error.rb +6 -0
- data/lib/rr/expectations/any_argument_expectation.rb +21 -0
- data/lib/rr/expectations/argument_equality_expectation.rb +41 -0
- data/lib/rr/expectations/times_called_expectation.rb +57 -0
- data/lib/rr/hash_with_object_id_key.rb +46 -0
- data/lib/rr/injections/double_injection.rb +220 -0
- data/lib/rr/injections/injection.rb +33 -0
- data/lib/rr/injections/method_missing_injection.rb +73 -0
- data/lib/rr/injections/singleton_method_added_injection.rb +72 -0
- data/lib/rr/method_dispatches/base_method_dispatch.rb +84 -0
- data/lib/rr/method_dispatches/method_dispatch.rb +59 -0
- data/lib/rr/method_dispatches/method_missing_dispatch.rb +61 -0
- data/lib/rr/proc_from_block.rb +7 -0
- data/lib/rr/recorded_calls.rb +103 -0
- data/lib/rr/space.rb +119 -0
- data/lib/rr/spy_verification.rb +48 -0
- data/lib/rr/spy_verification_proxy.rb +13 -0
- data/lib/rr/times_called_matchers/any_times_matcher.rb +18 -0
- data/lib/rr/times_called_matchers/at_least_matcher.rb +15 -0
- data/lib/rr/times_called_matchers/at_most_matcher.rb +23 -0
- data/lib/rr/times_called_matchers/integer_matcher.rb +19 -0
- data/lib/rr/times_called_matchers/never_matcher.rb +23 -0
- data/lib/rr/times_called_matchers/non_terminal.rb +27 -0
- data/lib/rr/times_called_matchers/proc_matcher.rb +11 -0
- data/lib/rr/times_called_matchers/range_matcher.rb +21 -0
- data/lib/rr/times_called_matchers/terminal.rb +20 -0
- data/lib/rr/times_called_matchers/times_called_matcher.rb +44 -0
- data/lib/rr/wildcard_matchers.rb +158 -0
- data/lib/rr/wildcard_matchers/anything.rb +18 -0
- data/lib/rr/wildcard_matchers/boolean.rb +23 -0
- data/lib/rr/wildcard_matchers/duck_type.rb +32 -0
- data/lib/rr/wildcard_matchers/hash_including.rb +29 -0
- data/lib/rr/wildcard_matchers/is_a.rb +25 -0
- data/lib/rr/wildcard_matchers/numeric.rb +13 -0
- data/lib/rr/wildcard_matchers/range.rb +7 -0
- data/lib/rr/wildcard_matchers/regexp.rb +7 -0
- data/lib/rr/wildcard_matchers/satisfy.rb +26 -0
- data/spec/api/any_instance_of/all_instances_of_spec.rb +12 -0
- data/spec/api/any_instance_of/any_instance_of_spec.rb +47 -0
- data/spec/api/any_instance_of/instance_of_spec.rb +12 -0
- data/spec/api/dont_allow/dont_allow_after_stub_spec.rb +14 -0
- data/spec/api/mock/mock_spec.rb +193 -0
- data/spec/api/proxy/proxy_spec.rb +86 -0
- data/spec/api/spy/spy_spec.rb +49 -0
- data/spec/api/strong/strong_spec.rb +87 -0
- data/spec/api/stub/stub_spec.rb +152 -0
- data/spec/core_spec_suite.rb +18 -0
- data/spec/environment_fixture_setup.rb +7 -0
- data/spec/minitest_spec_suite.rb +21 -0
- data/spec/proc_from_block_spec.rb +14 -0
- data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +67 -0
- data/spec/rr/adapters/rr_methods_creator_spec.rb +137 -0
- data/spec/rr/adapters/rr_methods_space_spec.rb +98 -0
- data/spec/rr/adapters/rr_methods_spec_helper.rb +7 -0
- data/spec/rr/adapters/rr_methods_times_matcher_spec.rb +13 -0
- data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +112 -0
- data/spec/rr/double_definitions/double_definition_create_blank_slate_spec.rb +91 -0
- data/spec/rr/double_definitions/double_definition_create_spec.rb +443 -0
- data/spec/rr/double_injection/double_injection_spec.rb +546 -0
- data/spec/rr/double_injection/double_injection_verify_spec.rb +29 -0
- data/spec/rr/errors/rr_error_spec.rb +67 -0
- data/spec/rr/expectations/any_argument_expectation_spec.rb +47 -0
- data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +14 -0
- data/spec/rr/expectations/argument_equality_expectation_spec.rb +135 -0
- data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +34 -0
- data/spec/rr/expectations/hash_including_argument_equality_expectation_spec.rb +82 -0
- data/spec/rr/expectations/hash_including_spec.rb +17 -0
- data/spec/rr/expectations/satisfy_argument_equality_expectation_spec.rb +59 -0
- data/spec/rr/expectations/satisfy_spec.rb +14 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +22 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +37 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +43 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +11 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +58 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +35 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +39 -0
- data/spec/rr/minitest/minitest_integration_test.rb +59 -0
- data/spec/rr/minitest/test_helper.rb +7 -0
- data/spec/rr/rspec/invocation_matcher_spec.rb +279 -0
- data/spec/rr/rspec/rspec_adapter_spec.rb +63 -0
- data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +21 -0
- data/spec/rr/rspec/rspec_backtrace_tweaking_spec_fixture.rb +11 -0
- data/spec/rr/rspec/rspec_usage_spec.rb +86 -0
- data/spec/rr/space/hash_with_object_id_key_spec.rb +88 -0
- data/spec/rr/space/space_spec.rb +596 -0
- data/spec/rr/test_unit/test_helper.rb +7 -0
- data/spec/rr/test_unit/test_unit_backtrace_test.rb +36 -0
- data/spec/rr/test_unit/test_unit_integration_test.rb +59 -0
- data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +47 -0
- data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +55 -0
- data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +70 -0
- data/spec/rr/times_called_matchers/integer_matcher_spec.rb +70 -0
- data/spec/rr/times_called_matchers/proc_matcher_spec.rb +55 -0
- data/spec/rr/times_called_matchers/range_matcher_spec.rb +76 -0
- data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +118 -0
- data/spec/rr/wildcard_matchers/anything_spec.rb +24 -0
- data/spec/rr/wildcard_matchers/boolean_spec.rb +36 -0
- data/spec/rr/wildcard_matchers/duck_type_spec.rb +52 -0
- data/spec/rr/wildcard_matchers/is_a_spec.rb +32 -0
- data/spec/rr/wildcard_matchers/numeric_spec.rb +32 -0
- data/spec/rr/wildcard_matchers/range_spec.rb +35 -0
- data/spec/rr/wildcard_matchers/regexp_spec.rb +43 -0
- data/spec/rr_spec.rb +28 -0
- data/spec/rspec_spec_suite.rb +16 -0
- data/spec/spec_helper.rb +40 -0
- data/spec/spec_suite.rb +50 -0
- data/spec/spy_verification_spec.rb +129 -0
- data/spec/test_unit_spec_suite.rb +20 -0
- metadata +220 -0
@@ -0,0 +1,59 @@
|
|
1
|
+
module RR
|
2
|
+
module MethodDispatches
|
3
|
+
class MethodDispatch < BaseMethodDispatch
|
4
|
+
attr_reader :double_injection, :subject
|
5
|
+
def initialize(double_injection, subject, args, block)
|
6
|
+
@double_injection, @subject, @args, @block = double_injection, subject, args, block
|
7
|
+
@double = find_double_to_attempt
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
space.record_call(subject, method_name, args, block)
|
12
|
+
if double
|
13
|
+
double.method_call(args)
|
14
|
+
call_yields
|
15
|
+
return_value_1 = call_implementation
|
16
|
+
return_value_2 = extract_subject_from_return_value(return_value_1)
|
17
|
+
if after_call_proc
|
18
|
+
extract_subject_from_return_value(after_call_proc.call(return_value_2))
|
19
|
+
else
|
20
|
+
return_value_2
|
21
|
+
end
|
22
|
+
else
|
23
|
+
double_not_found_error
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def call_original_method
|
28
|
+
if subject_has_original_method?
|
29
|
+
subject.__send__(original_method_alias_name, *args, &block)
|
30
|
+
elsif subject_has_original_method_missing?
|
31
|
+
call_original_method_missing
|
32
|
+
else
|
33
|
+
subject.__send__(:method_missing, method_name, *args, &block)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
protected
|
38
|
+
def call_implementation
|
39
|
+
if implementation_is_original_method?
|
40
|
+
call_original_method
|
41
|
+
else
|
42
|
+
if implementation
|
43
|
+
if implementation.is_a?(Method)
|
44
|
+
implementation.call(*args, &block)
|
45
|
+
else
|
46
|
+
call_args = block ? args + [ProcFromBlock.new(&block)] : args
|
47
|
+
implementation.call(*call_args)
|
48
|
+
end
|
49
|
+
else
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def_delegators :definition, :implementation
|
56
|
+
def_delegators :double_injection, :subject_has_original_method?, :subject_has_original_method_missing?, :method_name, :original_method_alias_name
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module RR
|
2
|
+
module MethodDispatches
|
3
|
+
class MethodMissingDispatch < BaseMethodDispatch
|
4
|
+
extend(Module.new do
|
5
|
+
def original_method_missing_alias_name
|
6
|
+
"__rr__original_method_missing"
|
7
|
+
end
|
8
|
+
end)
|
9
|
+
|
10
|
+
attr_reader :subject, :subject_class, :method_name
|
11
|
+
def initialize(subject, subject_class, method_name, args, block)
|
12
|
+
@subject, @subject_class, @method_name, @args, @block = subject, subject_class, method_name, args, block
|
13
|
+
end
|
14
|
+
|
15
|
+
def call
|
16
|
+
if Injections::DoubleInjection.exists?(subject_class, method_name)
|
17
|
+
@double = find_double_to_attempt
|
18
|
+
if double
|
19
|
+
return_value = extract_subject_from_return_value(call_implementation)
|
20
|
+
if after_call_proc
|
21
|
+
extract_subject_from_return_value(after_call_proc.call(return_value))
|
22
|
+
else
|
23
|
+
return_value
|
24
|
+
end
|
25
|
+
else
|
26
|
+
double_not_found_error
|
27
|
+
end
|
28
|
+
else
|
29
|
+
call_original_method
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def call_original_method
|
34
|
+
Injections::DoubleInjection.find_or_create(subject_class, method_name).dispatch_method_delegates_to_dispatch_original_method do
|
35
|
+
call_original_method_missing
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
def call_implementation
|
41
|
+
if implementation_is_original_method?
|
42
|
+
space.record_call(subject, method_name, args, block)
|
43
|
+
double.method_call(args)
|
44
|
+
call_original_method
|
45
|
+
else
|
46
|
+
if double_injection = Injections::DoubleInjection.find(subject_class, method_name)
|
47
|
+
double_injection.bind_method
|
48
|
+
# The DoubleInjection takes care of calling double.method_call
|
49
|
+
subject.__send__(method_name, *args, &block)
|
50
|
+
else
|
51
|
+
nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def double_injection
|
57
|
+
Injections::DoubleInjection.find_or_create(subject_class, method_name)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module RR
|
2
|
+
class RecordedCalls
|
3
|
+
include RR::Space::Reader
|
4
|
+
|
5
|
+
def initialize(recorded_calls=[])
|
6
|
+
@recorded_calls = recorded_calls
|
7
|
+
@ordered_index = 0
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :recorded_calls
|
11
|
+
|
12
|
+
def clear
|
13
|
+
self.ordered_index = 0
|
14
|
+
recorded_calls.clear
|
15
|
+
end
|
16
|
+
|
17
|
+
def <<(recorded_call)
|
18
|
+
recorded_calls << recorded_call
|
19
|
+
end
|
20
|
+
|
21
|
+
def any?(&block)
|
22
|
+
recorded_calls.any?(&block)
|
23
|
+
end
|
24
|
+
|
25
|
+
def ==(other)
|
26
|
+
recorded_calls == other.recorded_calls
|
27
|
+
end
|
28
|
+
|
29
|
+
def match_error(spy_verification)
|
30
|
+
double_injection_exists_error(spy_verification) || begin
|
31
|
+
if spy_verification.ordered?
|
32
|
+
ordered_match_error(spy_verification)
|
33
|
+
else
|
34
|
+
unordered_match_error(spy_verification)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
attr_accessor :ordered_index
|
41
|
+
|
42
|
+
def double_injection_exists_error(spy_verification)
|
43
|
+
unless Injections::DoubleInjection.exists_by_subject?(spy_verification.subject, spy_verification.method_name)
|
44
|
+
RR::Errors::SpyVerificationErrors::DoubleInjectionNotFoundError.new(
|
45
|
+
"A Double Injection for the subject and method call:\n" <<
|
46
|
+
"#{spy_verification.subject.inspect}\n" <<
|
47
|
+
"#{spy_verification.method_name}\ndoes not exist in:\n" <<
|
48
|
+
"\t#{recorded_calls.map {|call| call.inspect}.join("\n\t")}"
|
49
|
+
)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def ordered_match_error(spy_verification)
|
54
|
+
memoized_matching_recorded_calls = matching_recorded_calls(spy_verification)
|
55
|
+
|
56
|
+
if memoized_matching_recorded_calls.last
|
57
|
+
self.ordered_index = recorded_calls.index(memoized_matching_recorded_calls.last)
|
58
|
+
end
|
59
|
+
(0..memoized_matching_recorded_calls.size).to_a.any? do |i|
|
60
|
+
spy_verification.times_matcher.matches?(i)
|
61
|
+
end ? nil : invocation_count_error(spy_verification, memoized_matching_recorded_calls)
|
62
|
+
end
|
63
|
+
|
64
|
+
def unordered_match_error(spy_verification)
|
65
|
+
memoized_matching_recorded_calls = matching_recorded_calls(spy_verification)
|
66
|
+
|
67
|
+
spy_verification.times_matcher.matches?(
|
68
|
+
memoized_matching_recorded_calls.size
|
69
|
+
) ? nil : invocation_count_error(spy_verification, memoized_matching_recorded_calls)
|
70
|
+
end
|
71
|
+
|
72
|
+
def matching_recorded_calls(spy_verification)
|
73
|
+
recorded_calls[ordered_index..-1].
|
74
|
+
select(&match_double_injection(spy_verification)).
|
75
|
+
select(&match_argument_expectation(spy_verification))
|
76
|
+
end
|
77
|
+
|
78
|
+
def match_double_injection(spy_verification)
|
79
|
+
lambda do |recorded_call|
|
80
|
+
recorded_call[0] == spy_verification.subject &&
|
81
|
+
recorded_call[1] == spy_verification.method_name
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def match_argument_expectation(spy_verification)
|
86
|
+
lambda do |recorded_call|
|
87
|
+
spy_verification.argument_expectation.exact_match?(*recorded_call[2]) ||
|
88
|
+
spy_verification.argument_expectation.wildcard_match?(*recorded_call[2])
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def invocation_count_error(spy_verification, matching_recorded_calls)
|
93
|
+
RR::Errors::SpyVerificationErrors::InvocationCountError.new(
|
94
|
+
"On subject #{spy_verification.subject.inspect}\n" <<
|
95
|
+
"Expected #{Double.formatted_name(spy_verification.method_name, spy_verification.argument_expectation.expected_arguments)}\n" <<
|
96
|
+
"to be called #{spy_verification.times_matcher.expected_times_message},\n" <<
|
97
|
+
"but was called #{matching_recorded_calls.size} times.\n" <<
|
98
|
+
"All of the method calls related to Doubles are:\n" <<
|
99
|
+
"\t#{recorded_calls.map {|call| call.inspect}.join("\n\t")}"
|
100
|
+
)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/lib/rr/space.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
module RR
|
2
|
+
# RR::Space.instance is the global state subject for the RR framework.
|
3
|
+
class Space
|
4
|
+
module Reader
|
5
|
+
def space
|
6
|
+
RR::Space.instance
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def instance
|
12
|
+
@instance ||= new
|
13
|
+
end
|
14
|
+
attr_writer :instance
|
15
|
+
|
16
|
+
protected
|
17
|
+
def method_missing(method_name, *args, &block)
|
18
|
+
instance.__send__(method_name, *args, &block)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
attr_reader :ordered_doubles, :recorded_calls
|
23
|
+
attr_accessor :trim_backtrace
|
24
|
+
def initialize
|
25
|
+
@ordered_doubles = []
|
26
|
+
@trim_backtrace = false
|
27
|
+
@recorded_calls = RR::RecordedCalls.new
|
28
|
+
end
|
29
|
+
|
30
|
+
# Registers the ordered Double to be verified.
|
31
|
+
def register_ordered_double(double)
|
32
|
+
@ordered_doubles << double unless ordered_doubles.include?(double)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Verifies that the passed in ordered Double is being called
|
36
|
+
# in the correct position.
|
37
|
+
def verify_ordered_double(double)
|
38
|
+
unless double.terminal?
|
39
|
+
raise Errors::DoubleOrderError,
|
40
|
+
"Ordered Doubles cannot have a NonTerminal TimesCalledExpectation"
|
41
|
+
end
|
42
|
+
unless @ordered_doubles.first == double
|
43
|
+
message = Double.formatted_name(double.method_name, double.expected_arguments)
|
44
|
+
message << " called out of order in list\n"
|
45
|
+
message << Double.list_message_part(@ordered_doubles)
|
46
|
+
raise Errors::DoubleOrderError, message
|
47
|
+
end
|
48
|
+
@ordered_doubles.shift unless double.attempt?
|
49
|
+
double
|
50
|
+
end
|
51
|
+
|
52
|
+
# Verifies all the DoubleInjection objects have met their
|
53
|
+
# TimesCalledExpectations.
|
54
|
+
def verify_doubles(*subjects)
|
55
|
+
Injections::DoubleInjection.verify(*subjects)
|
56
|
+
end
|
57
|
+
alias_method :verify, :verify_doubles
|
58
|
+
|
59
|
+
# Resets the registered Doubles and ordered Doubles
|
60
|
+
def reset
|
61
|
+
reset_ordered_doubles
|
62
|
+
Injections::DoubleInjection.reset
|
63
|
+
reset_method_missing_injections
|
64
|
+
reset_singleton_method_added_injections
|
65
|
+
reset_recorded_calls
|
66
|
+
reset_bound_objects
|
67
|
+
end
|
68
|
+
|
69
|
+
# Verifies the DoubleInjection for the passed in subject and method_name.
|
70
|
+
def verify_double(subject, method_name)
|
71
|
+
Injections::DoubleInjection.verify_double(class << subject; self; end, method_name)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Resets the DoubleInjection for the passed in subject and method_name.
|
75
|
+
def reset_double(subject, method_name)
|
76
|
+
Injections::DoubleInjection.reset_double(class << subject; self; end, method_name)
|
77
|
+
end
|
78
|
+
|
79
|
+
def record_call(subject, method_name, arguments, block)
|
80
|
+
@recorded_calls << [subject, method_name, arguments, block]
|
81
|
+
end
|
82
|
+
|
83
|
+
def blank_slate_whitelist
|
84
|
+
@blank_slate_whitelist ||= [
|
85
|
+
"object_id", "respond_to?", "respond_to_missing?", "method_missing", "instance_eval", "instance_exec", "class_eval"
|
86
|
+
]
|
87
|
+
end
|
88
|
+
|
89
|
+
protected
|
90
|
+
# Removes the ordered Doubles from the list
|
91
|
+
def reset_ordered_doubles
|
92
|
+
@ordered_doubles.clear
|
93
|
+
end
|
94
|
+
|
95
|
+
def reset_method_missing_injections
|
96
|
+
Injections::MethodMissingInjection.instances.each do |subject_class, injection|
|
97
|
+
injection.reset
|
98
|
+
end
|
99
|
+
Injections::MethodMissingInjection.instances.clear
|
100
|
+
end
|
101
|
+
|
102
|
+
def reset_singleton_method_added_injections
|
103
|
+
Injections::SingletonMethodAddedInjection.instances.each do |subject, injection|
|
104
|
+
injection.reset
|
105
|
+
end
|
106
|
+
Injections::SingletonMethodAddedInjection.instances.clear
|
107
|
+
end
|
108
|
+
|
109
|
+
def reset_recorded_calls
|
110
|
+
@recorded_calls.clear
|
111
|
+
end
|
112
|
+
|
113
|
+
def reset_bound_objects
|
114
|
+
# TODO: Figure out how to clear and reset these bindings
|
115
|
+
#RR::Injections::DoubleInjection::BoundObjects.clear
|
116
|
+
#RR::Injections::DoubleInjection::MethodMissingInjection.clear
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module RR
|
2
|
+
class SpyVerification
|
3
|
+
def initialize(subject, method_name, args)
|
4
|
+
@subject = subject
|
5
|
+
@method_name = method_name.to_sym
|
6
|
+
set_argument_expectation_for_args(args)
|
7
|
+
@ordered = false
|
8
|
+
once
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :argument_expectation, :method_name, :times_matcher
|
12
|
+
attr_accessor :subject
|
13
|
+
|
14
|
+
include RR::DoubleDefinitions::DoubleDefinition::TimesDefinitionConstructionMethods
|
15
|
+
include RR::DoubleDefinitions::DoubleDefinition::ArgumentDefinitionConstructionMethods
|
16
|
+
|
17
|
+
def ordered
|
18
|
+
@ordered = true
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def ordered?
|
23
|
+
@ordered
|
24
|
+
end
|
25
|
+
|
26
|
+
def call
|
27
|
+
(error = RR.recorded_calls.match_error(self)) && raise(error)
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_proc
|
31
|
+
lambda do
|
32
|
+
call
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
attr_writer :times_matcher
|
38
|
+
|
39
|
+
def set_argument_expectation_for_args(args)
|
40
|
+
# with_no_args and with actually set @argument_expectation
|
41
|
+
args.empty? ? with_no_args : with(*args)
|
42
|
+
end
|
43
|
+
|
44
|
+
def install_method_callback(return_value_block)
|
45
|
+
# Do nothing. This is to support DefinitionConstructionMethods
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module RR
|
2
|
+
module TimesCalledMatchers #:nodoc:
|
3
|
+
class AnyTimesMatcher < TimesCalledMatcher
|
4
|
+
include NonTerminal
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
end
|
8
|
+
|
9
|
+
def matches?(times_called)
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
13
|
+
def expected_times_message
|
14
|
+
"any number of times"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module RR
|
2
|
+
module TimesCalledMatchers #:nodoc:
|
3
|
+
class AtLeastMatcher < TimesCalledMatcher
|
4
|
+
include NonTerminal
|
5
|
+
|
6
|
+
def matches?(times_called)
|
7
|
+
times_called >= @times
|
8
|
+
end
|
9
|
+
|
10
|
+
def expected_times_message
|
11
|
+
"at least #{@times.inspect} times"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|