redinger-rr 0.10.3
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.
- data/CHANGES +221 -0
- data/README.rdoc +343 -0
- data/Rakefile +88 -0
- data/VERSION.yml +4 -0
- data/lib/rr.rb +88 -0
- data/lib/rr/adapters/rr_methods.rb +122 -0
- data/lib/rr/adapters/rspec.rb +59 -0
- data/lib/rr/adapters/test_unit.rb +29 -0
- data/lib/rr/double.rb +152 -0
- data/lib/rr/double_definitions/child_double_definition_creator.rb +27 -0
- data/lib/rr/double_definitions/double_definition.rb +348 -0
- data/lib/rr/double_definitions/double_definition_creator.rb +167 -0
- data/lib/rr/double_definitions/double_definition_creator_proxy.rb +37 -0
- data/lib/rr/double_definitions/strategies/implementation/implementation_strategy.rb +15 -0
- data/lib/rr/double_definitions/strategies/implementation/proxy.rb +62 -0
- data/lib/rr/double_definitions/strategies/implementation/reimplementation.rb +14 -0
- data/lib/rr/double_definitions/strategies/implementation/strongly_typed_reimplementation.rb +17 -0
- data/lib/rr/double_definitions/strategies/scope/instance.rb +15 -0
- data/lib/rr/double_definitions/strategies/scope/instance_of_class.rb +50 -0
- data/lib/rr/double_definitions/strategies/scope/scope_strategy.rb +15 -0
- data/lib/rr/double_definitions/strategies/strategy.rb +70 -0
- data/lib/rr/double_definitions/strategies/verification/dont_allow.rb +34 -0
- data/lib/rr/double_definitions/strategies/verification/mock.rb +44 -0
- data/lib/rr/double_definitions/strategies/verification/stub.rb +45 -0
- data/lib/rr/double_definitions/strategies/verification/verification_strategy.rb +15 -0
- data/lib/rr/double_injection.rb +180 -0
- data/lib/rr/double_matches.rb +51 -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 +44 -0
- data/lib/rr/method_dispatches/base_method_dispatch.rb +108 -0
- data/lib/rr/method_dispatches/method_dispatch.rb +61 -0
- data/lib/rr/method_dispatches/method_missing_dispatch.rb +49 -0
- data/lib/rr/proc_from_block.rb +7 -0
- data/lib/rr/recorded_calls.rb +103 -0
- data/lib/rr/space.rb +123 -0
- data/lib/rr/spy_verification.rb +48 -0
- data/lib/rr/spy_verification_proxy.rb +18 -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/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/core_spec_suite.rb +19 -0
- data/spec/environment_fixture_setup.rb +7 -0
- data/spec/high_level_spec.rb +398 -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 +149 -0
- data/spec/rr/adapters/rr_methods_space_spec.rb +115 -0
- data/spec/rr/adapters/rr_methods_spec_helper.rb +11 -0
- data/spec/rr/adapters/rr_methods_times_matcher_spec.rb +17 -0
- data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +112 -0
- data/spec/rr/double_definitions/double_definition_creator_proxy_spec.rb +155 -0
- data/spec/rr/double_definitions/double_definition_creator_spec.rb +502 -0
- data/spec/rr/double_definitions/double_definition_spec.rb +1165 -0
- data/spec/rr/double_injection/double_injection_spec.rb +339 -0
- data/spec/rr/double_injection/double_injection_verify_spec.rb +29 -0
- data/spec/rr/double_spec.rb +352 -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 +46 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +69 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +71 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +23 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +104 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +81 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +83 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +38 -0
- data/spec/rr/rspec/invocation_matcher_spec.rb +279 -0
- data/spec/rr/rspec/rspec_adapter_spec.rb +66 -0
- data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +31 -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 +550 -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 +57 -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 +17 -0
- data/spec/spec_helper.rb +109 -0
- data/spec/spec_suite.rb +31 -0
- data/spec/spy_verification_spec.rb +129 -0
- data/spec/test_unit_spec_suite.rb +21 -0
- metadata +193 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Expectations
|
5
|
+
describe TimesCalledExpectation do
|
6
|
+
context "with a failure" do
|
7
|
+
it_should_behave_like "RR::Expectations::TimesCalledExpectation"
|
8
|
+
attr_reader :times, :matcher, :expectation
|
9
|
+
|
10
|
+
before do
|
11
|
+
@times = 0
|
12
|
+
double.definition.times(0)
|
13
|
+
@matcher = double.definition.times_matcher
|
14
|
+
@expectation = TimesCalledExpectation.new(double)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#attempt!" do
|
18
|
+
it "raises error that includes the double" do
|
19
|
+
lambda {expectation.attempt}.should raise_error(
|
20
|
+
Errors::TimesCalledError,
|
21
|
+
"#{double.formatted_name}\n#{matcher.error_message(1)}"
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#verify!" do
|
27
|
+
it "raises error with passed in message prepended" do
|
28
|
+
expectation.instance_variable_set(:@times_called, 1)
|
29
|
+
lambda {expectation.verify!}.should raise_error(
|
30
|
+
Errors::TimesCalledError,
|
31
|
+
"#{double.formatted_name}\n#{matcher.error_message(1)}"
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,279 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Adapters
|
5
|
+
module Rspec
|
6
|
+
describe InvocationMatcher do
|
7
|
+
describe "matching against a method with no doubles" do
|
8
|
+
before do
|
9
|
+
@matcher = InvocationMatcher.new(:foobar)
|
10
|
+
@result = @matcher.matches?(Object.new)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "does not match" do
|
14
|
+
@result.should_not be
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "defining an expectation using a method invocation" do
|
19
|
+
before do
|
20
|
+
@subject = Object.new
|
21
|
+
stub(@subject).foobar
|
22
|
+
@subject.foobar(:args)
|
23
|
+
@result = InvocationMatcher.new.foobar(:args).matches?(@subject)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "uses the invoked method as the expected method" do
|
27
|
+
@result.should be
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "matching against a stubbed method that was never called" do
|
32
|
+
before do
|
33
|
+
@subject = Object.new
|
34
|
+
stub(@subject).foobar
|
35
|
+
@matcher = InvocationMatcher.new(:foobar)
|
36
|
+
@result = @matcher.matches?(@subject)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "does not match" do
|
40
|
+
@result.should_not be
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "matching against a stubbed method that was called once" do
|
45
|
+
before do
|
46
|
+
@subject = Object.new
|
47
|
+
stub(@subject).foobar
|
48
|
+
@subject.foobar
|
49
|
+
@result = InvocationMatcher.new(:foobar).matches?(@subject)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "does match" do
|
53
|
+
@result.should be
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "matching against a stubbed method that was called with unexpected arguments" do
|
58
|
+
before do
|
59
|
+
@args = %w(one two)
|
60
|
+
@subject = Object.new
|
61
|
+
stub(@subject).foobar
|
62
|
+
@subject.foobar(:other)
|
63
|
+
@result = InvocationMatcher.new(:foobar).with(*@args).matches?(@subject)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "does not match" do
|
67
|
+
@result.should_not be
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "matching against a stubbed method that was called with expected arguments" do
|
72
|
+
before do
|
73
|
+
@args = %w(one two)
|
74
|
+
@subject = Object.new
|
75
|
+
stub(@subject).foobar
|
76
|
+
@subject.foobar(*@args)
|
77
|
+
@result = InvocationMatcher.new(:foobar).with(*@args).matches?(@subject)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "does match" do
|
81
|
+
@result.should be
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "defining a fulfilled argument expectation using a method invocation" do
|
86
|
+
before do
|
87
|
+
@args = %w(one two)
|
88
|
+
@subject = Object.new
|
89
|
+
stub(@subject).foobar
|
90
|
+
@subject.foobar(*@args)
|
91
|
+
@result = InvocationMatcher.new.foobar(*@args).matches?(@subject)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "does match" do
|
95
|
+
@result.should be
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "defining an unfulfilled argument expectation using a method invocation" do
|
100
|
+
before do
|
101
|
+
@args = %w(one two)
|
102
|
+
@subject = Object.new
|
103
|
+
stub(@subject).foobar
|
104
|
+
@subject.foobar(:other)
|
105
|
+
@result = InvocationMatcher.new.foobar(*@args).matches?(@subject)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "does not match" do
|
109
|
+
@result.should_not be
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "matching against a stubbed method that was called more than once" do
|
114
|
+
before do
|
115
|
+
@subject = Object.new
|
116
|
+
stub(@subject).foobar
|
117
|
+
2.times { @subject.foobar }
|
118
|
+
@result = InvocationMatcher.new(:foobar).twice.matches?(@subject)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "does match" do
|
122
|
+
@result.should be
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "matching a stubbed method with any arguments" do
|
127
|
+
before do
|
128
|
+
@subject = Object.new
|
129
|
+
stub(@subject).foobar
|
130
|
+
@subject.foobar(:args)
|
131
|
+
@result = InvocationMatcher.new(:foobar).with_any_args.matches?(@subject)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "does match" do
|
135
|
+
@result.should be
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "matching a stubbed method with no arguments when arguments are not provided" do
|
140
|
+
before do
|
141
|
+
@subject = Object.new
|
142
|
+
stub(@subject).foobar
|
143
|
+
@subject.foobar
|
144
|
+
@result = InvocationMatcher.new(:foobar).with_no_args.matches?(@subject)
|
145
|
+
end
|
146
|
+
|
147
|
+
it "does match" do
|
148
|
+
@result.should be
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "matching a stubbed method with no arguments when arguments are provided" do
|
153
|
+
before do
|
154
|
+
@subject = Object.new
|
155
|
+
stub(@subject).foobar
|
156
|
+
@subject.foobar(:args)
|
157
|
+
@result = InvocationMatcher.new(:foobar).with_no_args.matches?(@subject)
|
158
|
+
end
|
159
|
+
|
160
|
+
it "does not match" do
|
161
|
+
@result.should_not be
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe "matching a method that was called twice when expected once" do
|
166
|
+
before do
|
167
|
+
@subject = Object.new
|
168
|
+
stub(@subject).foobar
|
169
|
+
2.times { @subject.foobar }
|
170
|
+
@matcher = InvocationMatcher.new(:foobar).times(1)
|
171
|
+
@result = @matcher.matches?(@subject)
|
172
|
+
end
|
173
|
+
|
174
|
+
it "does not match" do
|
175
|
+
@result.should_not be
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe "matching a method that was called twice when expected twice" do
|
180
|
+
before do
|
181
|
+
@subject = Object.new
|
182
|
+
stub(@subject).foobar
|
183
|
+
2.times { @subject.foobar }
|
184
|
+
@result = InvocationMatcher.new(:foobar).times(2).matches?(@subject)
|
185
|
+
end
|
186
|
+
|
187
|
+
it "does match" do
|
188
|
+
@result.should be
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
describe "matching a method that was called twice when any number of times" do
|
193
|
+
before do
|
194
|
+
@subject = Object.new
|
195
|
+
stub(@subject).foobar
|
196
|
+
2.times { @subject.foobar }
|
197
|
+
@result = InvocationMatcher.new(:foobar).any_number_of_times.matches?(@subject)
|
198
|
+
end
|
199
|
+
|
200
|
+
it "does match" do
|
201
|
+
@result.should be
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
describe "matching a method that was called three times when expected at most twice" do
|
206
|
+
before do
|
207
|
+
@subject = Object.new
|
208
|
+
stub(@subject).foobar
|
209
|
+
3.times { @subject.foobar }
|
210
|
+
@result = InvocationMatcher.new(:foobar).at_most(2).matches?(@subject)
|
211
|
+
end
|
212
|
+
|
213
|
+
it "does not match" do
|
214
|
+
@result.should_not be
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
describe "matching a method that was called once when expected at most twice" do
|
219
|
+
before do
|
220
|
+
@subject = Object.new
|
221
|
+
stub(@subject).foobar
|
222
|
+
@subject.foobar
|
223
|
+
@result = InvocationMatcher.new(:foobar).at_most(2).matches?(@subject)
|
224
|
+
end
|
225
|
+
|
226
|
+
it "does match" do
|
227
|
+
@result.should be
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
describe "matching a method that was called once when expected at least twice" do
|
232
|
+
before do
|
233
|
+
@subject = Object.new
|
234
|
+
stub(@subject).foobar
|
235
|
+
@subject.foobar
|
236
|
+
@result = InvocationMatcher.new(:foobar).at_least(2).matches?(@subject)
|
237
|
+
end
|
238
|
+
|
239
|
+
it "does not match" do
|
240
|
+
@result.should_not be
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
describe "matching a method that was called three times when expected at least twice" do
|
245
|
+
before do
|
246
|
+
@subject = Object.new
|
247
|
+
stub(@subject).foobar
|
248
|
+
3.times { @subject.foobar }
|
249
|
+
@result = InvocationMatcher.new(:foobar).at_least(2).matches?(@subject)
|
250
|
+
end
|
251
|
+
|
252
|
+
it "does match" do
|
253
|
+
@result.should be
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
describe "that does not match" do
|
258
|
+
before do
|
259
|
+
@error = Object.new
|
260
|
+
@message = 'Verification error message'
|
261
|
+
stub(RR::Space.instance.recorded_calls).match_error { @error }
|
262
|
+
stub(@error).message { @message }
|
263
|
+
|
264
|
+
@matcher = InvocationMatcher.new(:foobar)
|
265
|
+
@result = @matcher.matches?(Object.new)
|
266
|
+
end
|
267
|
+
|
268
|
+
it "returns false when matching" do
|
269
|
+
@result.should_not be
|
270
|
+
end
|
271
|
+
|
272
|
+
it "returns a failure messsage" do
|
273
|
+
@matcher.failure_message.should == @message
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Adapters
|
5
|
+
describe Rspec do
|
6
|
+
attr_reader :fixture, :subject, :method_name
|
7
|
+
describe "#setup_mocks_for_rspec" do
|
8
|
+
before do
|
9
|
+
@fixture = Object.new
|
10
|
+
fixture.extend Rspec
|
11
|
+
|
12
|
+
@subject = Object.new
|
13
|
+
@method_name = :foobar
|
14
|
+
end
|
15
|
+
|
16
|
+
it "resets the double_injections" do
|
17
|
+
RR.double_injection(subject, method_name)
|
18
|
+
RR.double_injections.should_not be_empty
|
19
|
+
|
20
|
+
fixture.setup_mocks_for_rspec
|
21
|
+
RR.double_injections.should be_empty
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#verify_mocks_for_rspec" do
|
26
|
+
before do
|
27
|
+
@fixture = Object.new
|
28
|
+
fixture.extend Rspec
|
29
|
+
|
30
|
+
@subject = Object.new
|
31
|
+
@method_name = :foobar
|
32
|
+
end
|
33
|
+
|
34
|
+
it "verifies the double_injections" do
|
35
|
+
double_injection = RR.double_injection(subject, method_name)
|
36
|
+
double = new_double(double_injection)
|
37
|
+
|
38
|
+
double.definition.once
|
39
|
+
|
40
|
+
lambda do
|
41
|
+
fixture.verify_mocks_for_rspec
|
42
|
+
end.should raise_error(::RR::Errors::TimesCalledError)
|
43
|
+
RR.double_injections.should be_empty
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#teardown_mocks_for_rspec" do
|
48
|
+
before do
|
49
|
+
@fixture = Object.new
|
50
|
+
fixture.extend Rspec
|
51
|
+
|
52
|
+
@subject = Object.new
|
53
|
+
@method_name = :foobar
|
54
|
+
end
|
55
|
+
|
56
|
+
it "resets the double_injections" do
|
57
|
+
RR.double_injection(subject, method_name)
|
58
|
+
RR.double_injections.should_not be_empty
|
59
|
+
|
60
|
+
fixture.teardown_mocks_for_rspec
|
61
|
+
RR.double_injections.should be_empty
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Adapters
|
5
|
+
describe Rspec do
|
6
|
+
describe "#trim_backtrace" do
|
7
|
+
it "does not set trim_backtrace" do
|
8
|
+
RR.trim_backtrace.should == false
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe ".included" do
|
13
|
+
it "does not add backtrace identifier twice" do
|
14
|
+
length = ::Spec::Runner::QuietBacktraceTweaker::IGNORE_PATTERNS.length
|
15
|
+
class << Object.new
|
16
|
+
include ::RR::Adapters::Rspec
|
17
|
+
end
|
18
|
+
::Spec::Runner::QuietBacktraceTweaker::IGNORE_PATTERNS.length.should == length
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "backtrace tweaking" do
|
23
|
+
it "hides rr library from the backtrace by default" do
|
24
|
+
dir = File.dirname(__FILE__)
|
25
|
+
output = `ruby #{dir}/rspec_backtrace_tweaking_spec_fixture.rb`
|
26
|
+
output.should_not include("lib/rr")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require "spec"
|
3
|
+
dir = File.dirname(__FILE__)
|
4
|
+
require File.expand_path("#{dir}/../../../lib/rr")
|
5
|
+
|
6
|
+
describe "Example" do
|
7
|
+
it("hides RR framework in backtrace") do
|
8
|
+
mock(subject).foobar()
|
9
|
+
RR.verify_double(subject, :foobar)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
describe RR do
|
4
|
+
attr_reader :subject
|
5
|
+
before do
|
6
|
+
@subject = Object.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#mock" do
|
10
|
+
it "creates a mock DoubleInjection Double" do
|
11
|
+
mock(subject).foobar(1, 2) {:baz}
|
12
|
+
subject.foobar(1, 2).should == :baz
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#stub" do
|
17
|
+
it "creates a stub DoubleInjection Double" do
|
18
|
+
stub(subject).foobar {:baz}
|
19
|
+
subject.foobar("any", "thing").should == :baz
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#mock and #proxy" do
|
24
|
+
before do
|
25
|
+
def subject.foobar
|
26
|
+
:baz
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "creates a proxy DoubleInjection Double" do
|
31
|
+
mock.proxy(subject).foobar
|
32
|
+
subject.foobar.should == :baz
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#stub and #proxy" do
|
37
|
+
before do
|
38
|
+
def subject.foobar
|
39
|
+
:baz
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it "creates a proxy DoubleInjection Double" do
|
44
|
+
stub.proxy(subject).foobar
|
45
|
+
subject.foobar.should == :baz
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#stub and #proxy" do
|
50
|
+
before do
|
51
|
+
def subject.foobar
|
52
|
+
:baz
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it "creates a proxy DoubleInjection Double" do
|
57
|
+
stub.proxy(subject).foobar
|
58
|
+
subject.foobar.should == :baz
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "spies" do
|
63
|
+
it "validates that a Double was called after it was called" do
|
64
|
+
stub(subject).foobar
|
65
|
+
subject.foobar(1, 2)
|
66
|
+
|
67
|
+
subject.should have_received.foobar(1, 2)
|
68
|
+
lambda do
|
69
|
+
subject.should have_received.foobar(1, 2, 3)
|
70
|
+
end.should raise_error(Spec::Expectations::ExpectationNotMetError)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
it "creates an invocation matcher with a method name" do
|
75
|
+
method = :test
|
76
|
+
matcher = 'fake'
|
77
|
+
mock(RR::Adapters::Rspec::InvocationMatcher).new(method) { matcher }
|
78
|
+
have_received(method).should == matcher
|
79
|
+
end
|
80
|
+
|
81
|
+
it "creates an invocation matcher without a method name" do
|
82
|
+
matcher = 'fake'
|
83
|
+
mock(RR::Adapters::Rspec::InvocationMatcher).new(nil) { matcher }
|
84
|
+
have_received.should == matcher
|
85
|
+
end
|
86
|
+
end
|