rr 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Appraisals +3 -43
- data/CHANGES.md +46 -0
- data/CREDITS.md +5 -0
- data/Gemfile +3 -12
- data/README.md +25 -24
- data/Rakefile +16 -38
- data/doc/02_syntax_comparison.md +1 -0
- data/lib/rr/core_ext/array.rb +2 -0
- data/lib/rr/core_ext/hash.rb +2 -0
- data/lib/rr/deprecations.rb +97 -0
- data/lib/rr/double_definitions/double_injections/any_instance_of.rb +1 -1
- data/lib/rr/double_definitions/double_injections/instance.rb +2 -2
- data/lib/rr/dsl.rb +152 -0
- data/lib/rr/injections/method_missing_injection.rb +6 -2
- data/lib/rr/integrations/minitest_4.rb +1 -1
- data/lib/rr/integrations/minitest_4_active_support.rb +1 -1
- data/lib/rr/integrations/rspec/invocation_matcher.rb +0 -8
- data/lib/rr/integrations/rspec_2.rb +20 -2
- data/lib/rr/recorded_call.rb +29 -0
- data/lib/rr/recorded_calls.rb +8 -4
- data/lib/rr/space.rb +1 -1
- data/lib/rr/spy_verification.rb +13 -5
- data/lib/rr/version.rb +1 -1
- data/lib/rr/wildcard_matchers.rb +10 -10
- data/lib/rr/without_autohook.rb +5 -13
- data/rr.gemspec +3 -3
- data/spec/defines_spec_suite_tasks.rb +12 -0
- data/spec/global_helper.rb +5 -0
- data/spec/spec_suite_configuration.rb +1 -7
- data/spec/suites.yml +1 -1
- data/spec/suites/rspec_2/functional/any_instance_of_spec.rb +133 -33
- data/spec/suites/rspec_2/functional/dont_allow_spec.rb +13 -8
- data/spec/suites/rspec_2/functional/mock_bang_spec.rb +20 -0
- data/spec/suites/rspec_2/functional/mock_instance_of_spec.rb +14 -0
- data/spec/suites/rspec_2/functional/mock_instance_of_strong_spec.rb +15 -0
- data/spec/suites/rspec_2/functional/mock_proxy_instance_of_spec.rb +15 -0
- data/spec/suites/rspec_2/functional/mock_proxy_spec.rb +14 -0
- data/spec/suites/rspec_2/functional/mock_spec.rb +8 -232
- data/spec/suites/rspec_2/functional/mock_strong_spec.rb +14 -0
- data/spec/suites/rspec_2/functional/received_spec.rb +16 -0
- data/spec/suites/rspec_2/functional/spy_spec.rb +89 -28
- data/spec/suites/rspec_2/functional/stub_bang_spec.rb +20 -0
- data/spec/suites/rspec_2/functional/stub_instance_of_spec.rb +15 -0
- data/spec/suites/rspec_2/functional/stub_instance_of_strong_spec.rb +15 -0
- data/spec/suites/rspec_2/functional/stub_proxy_instance_of_spec.rb +16 -0
- data/spec/suites/rspec_2/functional/stub_proxy_spec.rb +45 -0
- data/spec/suites/rspec_2/functional/stub_spec.rb +42 -161
- data/spec/suites/rspec_2/functional/stub_strong_spec.rb +15 -0
- data/spec/suites/rspec_2/helper.rb +2 -2
- data/spec/suites/rspec_2/support/mixins/double_definition_creator_helpers.rb +173 -0
- data/spec/suites/rspec_2/support/mixins/mock_definition_creator_helpers.rb +45 -0
- data/spec/suites/rspec_2/support/mixins/proxy_definition_creator_helpers.rb +33 -0
- data/spec/suites/rspec_2/support/mixins/stub_creator_helpers.rb +43 -0
- data/spec/suites/rspec_2/support/mixins/stub_definition_creator_helpers.rb +45 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/argument_expectations_with_never_called_qualifier.rb +39 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/argument_expectations_with_times_called_qualifier.rb +50 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/argument_expectations_without_qualifiers.rb +131 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/dont_allow.rb +148 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_instance_of.rb +26 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_instance_of_strong.rb +28 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_proxy.rb +11 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_strong.rb +37 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mocking.rb +107 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of.rb +32 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of_strong.rb +39 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_proxy.rb +11 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_strong.rb +37 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stubbing.rb +57 -0
- data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/array_flatten_bug.rb +35 -0
- data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/block_form.rb +31 -0
- data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/comparing_arity.rb +63 -0
- data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/object_is_proxy.rb +43 -0
- data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/sequential_invocations.rb +26 -0
- data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/setting_implementation.rb +51 -0
- data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/yields.rb +81 -0
- data/spec/suites/rspec_2/unit/core_ext/enumerable_spec.rb +0 -28
- data/spec/suites/rspec_2/unit/deprecations_spec.rb +27 -0
- data/spec/suites/rspec_2/unit/dsl/double_creators_spec.rb +133 -0
- data/spec/suites/rspec_2/unit/dsl/space_spec.rb +99 -0
- data/spec/suites/rspec_2/unit/dsl/wildcard_matchers_spec.rb +67 -0
- data/spec/suites/rspec_2/unit/integrations/rspec_spec.rb +4 -19
- data/spec/suites/rspec_2/unit/space_spec.rb +5 -3
- data/spec/suites/rspec_2/unit/spy_verification_spec.rb +1 -1
- data/spec/support/adapter.rb +1 -1
- data/spec/support/adapter_tests/rspec.rb +19 -15
- data/spec/support/project/generator.rb +0 -4
- metadata +55 -48
- data/gemfiles/ruby_18_rspec_1.gemfile +0 -14
- data/gemfiles/ruby_18_rspec_1.gemfile.lock +0 -38
- data/gemfiles/ruby_18_rspec_1_rails_2.gemfile +0 -18
- data/gemfiles/ruby_18_rspec_1_rails_2.gemfile.lock +0 -64
- data/gemfiles/ruby_19_rspec_2_rails_3.gemfile +0 -15
- data/gemfiles/ruby_19_rspec_2_rails_3.gemfile.lock +0 -123
- data/lib/rr/adapters.rb +0 -34
- data/lib/rr/adapters/rr_methods.rb +0 -142
- data/lib/rr/integrations/rspec_1.rb +0 -46
- data/lib/rr/integrations/test_unit_1.rb +0 -63
- data/lib/rr/integrations/test_unit_2.rb +0 -17
- data/lib/rr/integrations/test_unit_200.rb +0 -27
- data/lib/rr/integrations/test_unit_200_active_support.rb +0 -25
- data/lib/rr/integrations/test_unit_2_active_support.rb +0 -38
- data/spec/suites/rspec_1/helper.rb +0 -24
- data/spec/suites/rspec_1/integration/rspec_1_spec.rb +0 -93
- data/spec/suites/rspec_1/integration/test_unit_1_spec.rb +0 -102
- data/spec/suites/rspec_1/integration/test_unit_2_spec.rb +0 -109
- data/spec/suites/rspec_1/spec_helper.rb +0 -3
- data/spec/suites/rspec_1_rails_2/integration/astc_rails_2_spec.rb +0 -141
- data/spec/suites/rspec_1_rails_2/integration/rspec_1_rails_2_spec.rb +0 -132
- data/spec/suites/rspec_1_rails_2/integration/test_unit_1_rails_2_spec.rb +0 -141
- data/spec/suites/rspec_1_rails_2/integration/test_unit_2_rails_2_spec.rb +0 -148
- data/spec/suites/rspec_1_rails_2/spec_helper.rb +0 -3
- data/spec/suites/rspec_2/functional/dsl_spec.rb +0 -13
- data/spec/suites/rspec_2/functional/instance_of_spec.rb +0 -14
- data/spec/suites/rspec_2/functional/proxy_spec.rb +0 -136
- data/spec/suites/rspec_2/functional/strong_spec.rb +0 -79
- data/spec/suites/rspec_2/integration/test_unit_200_spec.rb +0 -102
- data/spec/suites/rspec_2/integration/test_unit_2_spec.rb +0 -109
- data/spec/suites/rspec_2/unit/adapters/rr_methods/double_creators_spec.rb +0 -135
- data/spec/suites/rspec_2/unit/adapters/rr_methods/space_spec.rb +0 -101
- data/spec/suites/rspec_2/unit/adapters/rr_methods/wildcard_matchers_spec.rb +0 -69
- data/spec/suites/rspec_2_rails_3/integration/astc_rails_3_spec.rb +0 -141
- data/spec/suites/rspec_2_rails_3/integration/minitest_4_rails_3_spec.rb +0 -148
- data/spec/suites/rspec_2_rails_3/integration/rspec_2_rails_3_spec.rb +0 -172
- data/spec/suites/rspec_2_rails_3/integration/test_unit_200_rails_3_spec.rb +0 -141
- data/spec/suites/rspec_2_rails_3/integration/test_unit_2_rails_3_spec.rb +0 -148
- data/spec/suites/rspec_2_rails_3/spec_helper.rb +0 -3
- data/spec/suites/rspec_2_rails_4/integration/test_unit_200_rails_4_spec.rb +0 -142
- data/spec/suites/rspec_2_rails_4/integration/test_unit_2_rails_4_spec.rb +0 -149
data/lib/rr/dsl.rb
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
module RR
|
|
2
|
+
module DSL
|
|
3
|
+
METHODS_TO_EXCLUDE_FROM_SPYING = [
|
|
4
|
+
:methods,
|
|
5
|
+
:==,
|
|
6
|
+
:__send__,
|
|
7
|
+
:__id__,
|
|
8
|
+
:object_id,
|
|
9
|
+
:class,
|
|
10
|
+
:respond_to?,
|
|
11
|
+
:inspect,
|
|
12
|
+
:to_s,
|
|
13
|
+
:respond_to_missing?,
|
|
14
|
+
:instance_eval,
|
|
15
|
+
:instance_exec
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
include DoubleDefinitions::Strategies::StrategyMethods
|
|
19
|
+
|
|
20
|
+
def mock(subject=DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name=nil, &definition_eval_block)
|
|
21
|
+
double_definition_create = DoubleDefinitions::DoubleDefinitionCreate.new
|
|
22
|
+
double_definition_create.mock(subject, method_name, &definition_eval_block)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def stub(subject=DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name=nil, &definition_eval_block)
|
|
26
|
+
double_definition_create = DoubleDefinitions::DoubleDefinitionCreate.new
|
|
27
|
+
double_definition_create.stub(subject, method_name, &definition_eval_block)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def dont_allow(subject=DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name=nil, &definition_eval_block)
|
|
31
|
+
double_definition_create = DoubleDefinitions::DoubleDefinitionCreate.new
|
|
32
|
+
double_definition_create.dont_allow(subject, method_name, &definition_eval_block)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def proxy(subject=DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name=nil, &definition_eval_block)
|
|
36
|
+
double_definition_create = DoubleDefinitions::DoubleDefinitionCreate.new
|
|
37
|
+
double_definition_create.proxy(subject, method_name, &definition_eval_block)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def strong(subject=DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name=nil, &definition_eval_block)
|
|
41
|
+
double_definition_create = DoubleDefinitions::DoubleDefinitionCreate.new
|
|
42
|
+
double_definition_create.strong(subject, method_name, &definition_eval_block)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def instance_of(subject=DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name=nil, &definition_eval_block)
|
|
46
|
+
double_definition_create = DoubleDefinitions::DoubleDefinitionCreate.new
|
|
47
|
+
double_definition_create.instance_of(subject, method_name, &definition_eval_block)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def any_instance_of(*args, &block)
|
|
51
|
+
RR::DoubleDefinitions::DoubleInjections::AnyInstanceOf.call(*args, &block)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Verifies all the DoubleInjection objects have met their
|
|
55
|
+
# TimesCalledExpectations.
|
|
56
|
+
def verify
|
|
57
|
+
RR::Space.instance.verify_doubles
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Resets the registered Doubles and ordered Doubles
|
|
61
|
+
def reset
|
|
62
|
+
RR::Space.instance.reset
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Returns a AnyTimesMatcher. This is meant to be passed in as an argument
|
|
66
|
+
# to Double#times.
|
|
67
|
+
#
|
|
68
|
+
# mock(object).method_name(anything).times(any_times) {return_value}
|
|
69
|
+
def any_times
|
|
70
|
+
TimesCalledMatchers::AnyTimesMatcher.new
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Sets up an Anything wildcard ArgumentEqualityExpectation
|
|
74
|
+
# that succeeds when passed any argument.
|
|
75
|
+
# mock(object).method_name(anything) {return_value}
|
|
76
|
+
# object.method_name("an arbitrary value") # passes
|
|
77
|
+
def anything
|
|
78
|
+
RR::WildcardMatchers::Anything.new
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Sets up an IsA wildcard ArgumentEqualityExpectation
|
|
82
|
+
# that succeeds when passed an argument of a certain type.
|
|
83
|
+
# mock(object).method_name(is_a(String)) {return_value}
|
|
84
|
+
# object.method_name("A String") # passes
|
|
85
|
+
def is_a(klass)
|
|
86
|
+
RR::WildcardMatchers::IsA.new(klass)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Sets up an Numeric wildcard ArgumentEqualityExpectation
|
|
90
|
+
# that succeeds when passed an argument that is ::Numeric.
|
|
91
|
+
# mock(object).method_name(numeric) {return_value}
|
|
92
|
+
# object.method_name(99) # passes
|
|
93
|
+
def numeric
|
|
94
|
+
RR::WildcardMatchers::Numeric.new
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Sets up an Boolean wildcard ArgumentEqualityExpectation
|
|
98
|
+
# that succeeds when passed an argument that is a ::Boolean.
|
|
99
|
+
# mock(object).method_name(boolean) {return_value}
|
|
100
|
+
# object.method_name(false) # passes
|
|
101
|
+
def boolean
|
|
102
|
+
RR::WildcardMatchers::Boolean.new
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Sets up a DuckType wildcard ArgumentEqualityExpectation
|
|
106
|
+
# that succeeds when the passed argument implements the methods.
|
|
107
|
+
# arg = Object.new
|
|
108
|
+
# def arg.foo; end
|
|
109
|
+
# def arg.bar; end
|
|
110
|
+
# mock(object).method_name(duck_type(:foo, :bar)) {return_value}
|
|
111
|
+
# object.method_name(arg) # passes
|
|
112
|
+
def duck_type(*args)
|
|
113
|
+
RR::WildcardMatchers::DuckType.new(*args)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Sets up a HashIncluding wildcard ArgumentEqualityExpectation
|
|
117
|
+
# that succeeds when the passed argument contains at least those keys
|
|
118
|
+
# and values of the expectation.
|
|
119
|
+
# mock(object).method_name(hash_including(:foo => 1)) {return_value}
|
|
120
|
+
# object.method_name({:foo => 1, :bar => 2) # passes
|
|
121
|
+
def hash_including(expected_hash)
|
|
122
|
+
RR::WildcardMatchers::HashIncluding.new(expected_hash)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Sets up a Satisfy wildcard ArgumentEqualityExpectation
|
|
126
|
+
# that succeeds when the passed argument causes the expectation's
|
|
127
|
+
# proc to return true.
|
|
128
|
+
# mock(object).method_name(satisfy {|arg| arg == :foo}) {return_value}
|
|
129
|
+
# object.method_name(:foo) # passes
|
|
130
|
+
def satisfy(expectation_proc=nil, &block)
|
|
131
|
+
expectation_proc ||= block
|
|
132
|
+
RR::WildcardMatchers::Satisfy.new(expectation_proc)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def spy(subject)
|
|
136
|
+
subject_methods = subject.public_methods.map {|method_name| method_name.to_sym }
|
|
137
|
+
methods_to_stub = subject_methods - METHODS_TO_EXCLUDE_FROM_SPYING
|
|
138
|
+
|
|
139
|
+
methods_to_stub.each do |method|
|
|
140
|
+
stub.proxy(subject, method)
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def received(subject)
|
|
145
|
+
RR::SpyVerificationProxy.new(subject)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
instance_methods.each do |name|
|
|
149
|
+
alias_method "rr_#{name}", name
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
@@ -73,8 +73,12 @@ module RR
|
|
|
73
73
|
|
|
74
74
|
subject_class.class_eval((<<-METHOD), __FILE__, __LINE__ + 1)
|
|
75
75
|
def method_missing(method_name, *args, &block)
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
if respond_to_missing?(method_name, true)
|
|
77
|
+
super
|
|
78
|
+
else
|
|
79
|
+
obj = ::RR::Injections::MethodMissingInjection::BoundObjects[#{id}]
|
|
80
|
+
MethodDispatches::MethodMissingDispatch.new(self, obj, method_name, args, block).call
|
|
81
|
+
end
|
|
78
82
|
end
|
|
79
83
|
METHOD
|
|
80
84
|
end
|
|
@@ -36,7 +36,7 @@ module RR
|
|
|
36
36
|
def hook
|
|
37
37
|
assertion_error_class = self.assertion_error_class
|
|
38
38
|
test_case_class.class_eval do
|
|
39
|
-
include RR::
|
|
39
|
+
include RR::DSL
|
|
40
40
|
include Mixin
|
|
41
41
|
|
|
42
42
|
unless instance_methods.any? { |method_name| method_name.to_sym == :setup_with_rr }
|
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
module RR
|
|
2
2
|
module Integrations
|
|
3
|
-
class RSpec2
|
|
3
|
+
class RSpec2
|
|
4
|
+
module Mixin
|
|
5
|
+
def setup_mocks_for_rspec
|
|
6
|
+
RR.reset
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def verify_mocks_for_rspec
|
|
10
|
+
RR.verify
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def teardown_mocks_for_rspec
|
|
14
|
+
RR.reset
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def have_received(method = nil)
|
|
18
|
+
RSpec::InvocationMatcher.new(method)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
4
22
|
def name
|
|
5
23
|
'RSpec 2'
|
|
6
24
|
end
|
|
@@ -14,7 +32,7 @@ module RR
|
|
|
14
32
|
def hook
|
|
15
33
|
::RSpec.configure do |config|
|
|
16
34
|
config.mock_with Mixin
|
|
17
|
-
config.include RR::
|
|
35
|
+
config.include RR::DSL
|
|
18
36
|
end
|
|
19
37
|
|
|
20
38
|
patterns =
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module RR
|
|
2
|
+
class RecordedCall < Struct.new(:subject, :method_name, :arguments, :block)
|
|
3
|
+
def inspect
|
|
4
|
+
'[%s, %s, %s, %s]' % [
|
|
5
|
+
subject_to_s,
|
|
6
|
+
method_name.inspect,
|
|
7
|
+
arguments.inspect,
|
|
8
|
+
block.inspect
|
|
9
|
+
]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def ==(other)
|
|
13
|
+
other.is_a?(self.class) &&
|
|
14
|
+
subject == other.subject &&
|
|
15
|
+
method_name == other.method_name &&
|
|
16
|
+
arguments == other.arguments
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def subject_to_s
|
|
22
|
+
if subject.respond_to?(:__rr__original_to_s, true)
|
|
23
|
+
subject.__rr__original_to_s
|
|
24
|
+
else
|
|
25
|
+
subject.to_s
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/rr/recorded_calls.rb
CHANGED
|
@@ -9,13 +9,17 @@ module RR
|
|
|
9
9
|
|
|
10
10
|
attr_reader :recorded_calls
|
|
11
11
|
|
|
12
|
+
def [](index)
|
|
13
|
+
@recorded_calls[index]
|
|
14
|
+
end
|
|
15
|
+
|
|
12
16
|
def clear
|
|
13
17
|
self.ordered_index = 0
|
|
14
18
|
recorded_calls.clear
|
|
15
19
|
end
|
|
16
20
|
|
|
17
|
-
def
|
|
18
|
-
recorded_calls <<
|
|
21
|
+
def add(subject, method_name, arguments, block)
|
|
22
|
+
recorded_calls << RecordedCall.new(subject, method_name, arguments, block)
|
|
19
23
|
end
|
|
20
24
|
|
|
21
25
|
def any?(&block)
|
|
@@ -43,9 +47,9 @@ module RR
|
|
|
43
47
|
unless Injections::DoubleInjection.exists_by_subject?(spy_verification.subject, spy_verification.method_name)
|
|
44
48
|
RR::Errors.build_error(RR::Errors::SpyVerificationErrors::DoubleInjectionNotFoundError,
|
|
45
49
|
"A Double Injection for the subject and method call:\n" <<
|
|
46
|
-
"#{spy_verification.
|
|
50
|
+
"#{spy_verification.subject_inspect}\n" <<
|
|
47
51
|
"#{spy_verification.method_name}\ndoes not exist in:\n" <<
|
|
48
|
-
"\t#{recorded_calls.map {|call| call.inspect}.join("\n\t")}"
|
|
52
|
+
"\t#{recorded_calls.map {|call| call.inspect }.join("\n\t")}"
|
|
49
53
|
)
|
|
50
54
|
end
|
|
51
55
|
end
|
data/lib/rr/space.rb
CHANGED
data/lib/rr/spy_verification.rb
CHANGED
|
@@ -13,12 +13,12 @@ module RR
|
|
|
13
13
|
|
|
14
14
|
include RR::DoubleDefinitions::DoubleDefinition::TimesDefinitionConstructionMethods
|
|
15
15
|
include RR::DoubleDefinitions::DoubleDefinition::ArgumentDefinitionConstructionMethods
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
def ordered
|
|
18
18
|
@ordered = true
|
|
19
19
|
self
|
|
20
20
|
end
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
def ordered?
|
|
23
23
|
@ordered
|
|
24
24
|
end
|
|
@@ -32,7 +32,15 @@ module RR
|
|
|
32
32
|
call
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
|
-
|
|
35
|
+
|
|
36
|
+
def subject_inspect
|
|
37
|
+
if subject.respond_to?(:__rr__original_inspect, true)
|
|
38
|
+
subject.__rr__original_inspect
|
|
39
|
+
else
|
|
40
|
+
subject.inspect
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
36
44
|
protected
|
|
37
45
|
attr_writer :times_matcher
|
|
38
46
|
|
|
@@ -40,9 +48,9 @@ module RR
|
|
|
40
48
|
# with_no_args and with actually set @argument_expectation
|
|
41
49
|
args.empty? ? with_no_args : with(*args)
|
|
42
50
|
end
|
|
43
|
-
|
|
51
|
+
|
|
44
52
|
def install_method_callback(return_value_block)
|
|
45
53
|
# Do nothing. This is to support DefinitionConstructionMethods
|
|
46
54
|
end
|
|
47
55
|
end
|
|
48
|
-
end
|
|
56
|
+
end
|
data/lib/rr/version.rb
CHANGED
data/lib/rr/wildcard_matchers.rb
CHANGED
|
@@ -12,7 +12,7 @@ divisible by a certain integer. In use, it might look like this:
|
|
|
12
12
|
|
|
13
13
|
mock(BananaGrabber).bunch_bananas(divisible_by(5))
|
|
14
14
|
|
|
15
|
-
To implement this, we need a class RR::WildcardMatchers::DivisibleBy with
|
|
15
|
+
To implement this, we need a class RR::WildcardMatchers::DivisibleBy with
|
|
16
16
|
these instance methods:
|
|
17
17
|
|
|
18
18
|
* ==(other)
|
|
@@ -38,7 +38,7 @@ might look like this:
|
|
|
38
38
|
DivisibleBy#==(other) should return true if other is a wildcard matcher that
|
|
39
39
|
matches the same things as self, so a natural way to write DivisibleBy#== is:
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
class RR::WildcardMatchers::DivisibleBy
|
|
43
43
|
def ==(other)
|
|
44
44
|
# Ensure that other is actually a DivisibleBy
|
|
@@ -86,7 +86,7 @@ false otherwise. In the case of DivisibleBy, wildcard_matches? reads:
|
|
|
86
86
|
# If other isn't a number, how can it be divisible by anything?
|
|
87
87
|
return false unless other.is_a?(Numeric)
|
|
88
88
|
|
|
89
|
-
# If other is in fact divisible by expected_divisor, then
|
|
89
|
+
# If other is in fact divisible by expected_divisor, then
|
|
90
90
|
# other modulo expected_divisor should be 0.
|
|
91
91
|
|
|
92
92
|
other % expected_divisor == 0
|
|
@@ -105,10 +105,10 @@ But that's less expressive than the original:
|
|
|
105
105
|
mock(BananaGrabber).bunch_bananas(divisible_by(5))
|
|
106
106
|
|
|
107
107
|
To be able to use the convenient divisible_by matcher rather than the uglier
|
|
108
|
-
DivisibleBy.new version, re-open the module RR::
|
|
109
|
-
|
|
108
|
+
DivisibleBy.new version, re-open the module RR::DSL and define divisible_by
|
|
109
|
+
there as a simple wrapper around DivisibleBy.new:
|
|
110
110
|
|
|
111
|
-
module RR::
|
|
111
|
+
module RR::DSL
|
|
112
112
|
def divisible_by(expected_divisor)
|
|
113
113
|
RR::WildcardMatchers::DivisibleBy.new(expected_divisor)
|
|
114
114
|
end
|
|
@@ -134,19 +134,19 @@ Here's all the code for DivisibleBy in one place for easy reference:
|
|
|
134
134
|
def inspect
|
|
135
135
|
"integer divisible by #{expected.divisor}"
|
|
136
136
|
end
|
|
137
|
-
|
|
137
|
+
|
|
138
138
|
def wildcard_matches?(other)
|
|
139
139
|
# If other isn't a number, how can it be divisible by anything?
|
|
140
140
|
return false unless other.is_a?(Numeric)
|
|
141
141
|
|
|
142
|
-
# If other is in fact divisible by expected_divisor, then
|
|
142
|
+
# If other is in fact divisible by expected_divisor, then
|
|
143
143
|
# other modulo expected_divisor should be 0.
|
|
144
144
|
|
|
145
145
|
other % expected_divisor == 0
|
|
146
146
|
end
|
|
147
147
|
end
|
|
148
|
-
|
|
149
|
-
module RR::
|
|
148
|
+
|
|
149
|
+
module RR::DSL
|
|
150
150
|
def divisible_by(expected_divisor)
|
|
151
151
|
RR::WildcardMatchers::DivisibleBy.new(expected_divisor)
|
|
152
152
|
end
|
data/lib/rr/without_autohook.rb
CHANGED
|
@@ -36,7 +36,7 @@ require 'rr/double_definitions/strategies/implementation/proxy'
|
|
|
36
36
|
require 'rr/double_definitions/strategies/double_injection/double_injection_strategy'
|
|
37
37
|
require 'rr/double_definitions/strategies/double_injection/instance'
|
|
38
38
|
require 'rr/double_definitions/strategies/double_injection/any_instance_of'
|
|
39
|
-
require 'rr/
|
|
39
|
+
require 'rr/dsl'
|
|
40
40
|
require 'rr/double_definitions/double_injections/instance'
|
|
41
41
|
require 'rr/double_definitions/double_injections/any_instance_of'
|
|
42
42
|
require 'rr/double_definitions/double_definition'
|
|
@@ -49,6 +49,7 @@ require 'rr/method_dispatches/base_method_dispatch'
|
|
|
49
49
|
require 'rr/method_dispatches/method_dispatch'
|
|
50
50
|
require 'rr/method_dispatches/method_missing_dispatch'
|
|
51
51
|
require 'rr/hash_with_object_id_key'
|
|
52
|
+
require 'rr/recorded_call'
|
|
52
53
|
require 'rr/recorded_calls'
|
|
53
54
|
require 'rr/proc_from_block'
|
|
54
55
|
|
|
@@ -88,24 +89,19 @@ require 'rr/spy_verification'
|
|
|
88
89
|
require 'rr/integrations'
|
|
89
90
|
require 'rr/integrations/decorator'
|
|
90
91
|
require 'rr/integrations/rspec/invocation_matcher'
|
|
91
|
-
require 'rr/integrations/rspec_1'
|
|
92
92
|
require 'rr/integrations/rspec_2'
|
|
93
93
|
require 'rr/integrations/minitest_4'
|
|
94
94
|
require 'rr/integrations/minitest_4_active_support'
|
|
95
95
|
require 'rr/integrations/minitest'
|
|
96
96
|
require 'rr/integrations/minitest_active_support'
|
|
97
|
-
|
|
98
|
-
require 'rr/
|
|
99
|
-
require 'rr/integrations/test_unit_200_active_support'
|
|
100
|
-
require 'rr/integrations/test_unit_2'
|
|
101
|
-
require 'rr/integrations/test_unit_2_active_support'
|
|
102
|
-
require 'rr/adapters'
|
|
97
|
+
|
|
98
|
+
require 'rr/deprecations'
|
|
103
99
|
|
|
104
100
|
require 'rr/version'
|
|
105
101
|
|
|
106
102
|
module RR
|
|
107
103
|
class << self
|
|
108
|
-
include
|
|
104
|
+
include DSL
|
|
109
105
|
|
|
110
106
|
(RR::Space.instance_methods - Object.instance_methods).each do |method_name|
|
|
111
107
|
class_eval((<<-METHOD), __FILE__, __LINE__ + 1)
|
|
@@ -117,10 +113,6 @@ module RR
|
|
|
117
113
|
|
|
118
114
|
attr_accessor :debug
|
|
119
115
|
alias_method :debug?, :debug
|
|
120
|
-
|
|
121
|
-
def ruby_18?
|
|
122
|
-
RUBY_VERSION =~ /^1\.8/
|
|
123
|
-
end
|
|
124
116
|
end
|
|
125
117
|
end
|
|
126
118
|
|