transpec 3.0.0 → 3.0.1
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/.rubocop.yml +2 -0
- data/CHANGELOG.md +4 -0
- data/lib/transpec/version.rb +1 -1
- data/transpec.gemspec +4 -3
- metadata +3 -97
- data/spec/.rubocop.yml +0 -23
- data/spec/integration/configuration_modification_spec.rb +0 -186
- data/spec/integration/conversion_spec.rb +0 -145
- data/spec/spec_helper.rb +0 -52
- data/spec/support/cache_helper.rb +0 -62
- data/spec/support/file_helper.rb +0 -25
- data/spec/support/shared_context.rb +0 -84
- data/spec/transpec/cli_spec.rb +0 -341
- data/spec/transpec/commit_message_spec.rb +0 -81
- data/spec/transpec/config_spec.rb +0 -99
- data/spec/transpec/converter_spec.rb +0 -1374
- data/spec/transpec/directory_cloner_spec.rb +0 -74
- data/spec/transpec/dynamic_analyzer/rewriter_spec.rb +0 -143
- data/spec/transpec/dynamic_analyzer_spec.rb +0 -329
- data/spec/transpec/git_spec.rb +0 -151
- data/spec/transpec/option_parser_spec.rb +0 -275
- data/spec/transpec/processed_source_spec.rb +0 -93
- data/spec/transpec/project_spec.rb +0 -194
- data/spec/transpec/record_spec.rb +0 -128
- data/spec/transpec/report_spec.rb +0 -126
- data/spec/transpec/rspec_version_spec.rb +0 -129
- data/spec/transpec/spec_file_finder_spec.rb +0 -118
- data/spec/transpec/spec_suite_spec.rb +0 -108
- data/spec/transpec/static_context_inspector_spec.rb +0 -713
- data/spec/transpec/syntax/allow_spec.rb +0 -122
- data/spec/transpec/syntax/be_boolean_spec.rb +0 -176
- data/spec/transpec/syntax/be_close_spec.rb +0 -51
- data/spec/transpec/syntax/current_example_spec.rb +0 -319
- data/spec/transpec/syntax/double_spec.rb +0 -175
- data/spec/transpec/syntax/example_group_spec.rb +0 -716
- data/spec/transpec/syntax/example_spec.rb +0 -301
- data/spec/transpec/syntax/expect_spec.rb +0 -313
- data/spec/transpec/syntax/have_spec.rb +0 -1276
- data/spec/transpec/syntax/hook_spec.rb +0 -215
- data/spec/transpec/syntax/its_spec.rb +0 -448
- data/spec/transpec/syntax/matcher_definition_spec.rb +0 -59
- data/spec/transpec/syntax/method_stub_spec.rb +0 -1301
- data/spec/transpec/syntax/oneliner_should_spec.rb +0 -628
- data/spec/transpec/syntax/operator_spec.rb +0 -871
- data/spec/transpec/syntax/pending_spec.rb +0 -415
- data/spec/transpec/syntax/raise_error_spec.rb +0 -354
- data/spec/transpec/syntax/receive_spec.rb +0 -499
- data/spec/transpec/syntax/rspec_configure_spec.rb +0 -870
- data/spec/transpec/syntax/should_receive_spec.rb +0 -1108
- data/spec/transpec/syntax/should_spec.rb +0 -497
- data/spec/transpec/util_spec.rb +0 -115
- data/spec/transpec_spec.rb +0 -22
@@ -1,1108 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'transpec/syntax/should_receive'
|
5
|
-
|
6
|
-
module Transpec
|
7
|
-
class Syntax
|
8
|
-
describe ShouldReceive do
|
9
|
-
include_context 'parsed objects'
|
10
|
-
include_context 'syntax object', ShouldReceive, :should_receive_object
|
11
|
-
|
12
|
-
let(:record) { should_receive_object.report.records.first }
|
13
|
-
|
14
|
-
describe '#expectize!' do
|
15
|
-
context 'with expression `obj.should_receive(:message)`' do
|
16
|
-
let(:source) do
|
17
|
-
<<-END
|
18
|
-
describe 'example' do
|
19
|
-
it 'receives #foo' do
|
20
|
-
subject.should_receive(:foo)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
END
|
24
|
-
end
|
25
|
-
|
26
|
-
let(:expected_source) do
|
27
|
-
<<-END
|
28
|
-
describe 'example' do
|
29
|
-
it 'receives #foo' do
|
30
|
-
expect(subject).to receive(:foo)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
END
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'converts to `expect(obj).to receive(:message)` form' do
|
37
|
-
should_receive_object.expectize!
|
38
|
-
rewritten_source.should == expected_source
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'adds record `obj.should_receive(:message)` -> `expect(obj).to receive(:message)`' do
|
42
|
-
should_receive_object.expectize!
|
43
|
-
record.old_syntax.should == 'obj.should_receive(:message)'
|
44
|
-
record.new_syntax.should == 'expect(obj).to receive(:message)'
|
45
|
-
end
|
46
|
-
|
47
|
-
context 'when the statement continues over multi lines' do
|
48
|
-
let(:source) do
|
49
|
-
<<-END
|
50
|
-
describe 'example' do
|
51
|
-
it 'receives #foo and returns 1' do
|
52
|
-
subject.should_receive(
|
53
|
-
:foo
|
54
|
-
).
|
55
|
-
and_return(
|
56
|
-
1
|
57
|
-
)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
END
|
61
|
-
end
|
62
|
-
|
63
|
-
let(:expected_source) do
|
64
|
-
<<-END
|
65
|
-
describe 'example' do
|
66
|
-
it 'receives #foo and returns 1' do
|
67
|
-
expect(subject).to receive(
|
68
|
-
:foo
|
69
|
-
).
|
70
|
-
and_return(
|
71
|
-
1
|
72
|
-
)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
END
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'keeps the style as far as possible' do
|
79
|
-
should_receive_object.expectize!
|
80
|
-
rewritten_source.should == expected_source
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context 'and #expect and #receive are not available in the context' do
|
85
|
-
context 'and the context is determinable statically' do
|
86
|
-
let(:source) do
|
87
|
-
<<-END
|
88
|
-
describe 'example' do
|
89
|
-
class TestRunner
|
90
|
-
def run
|
91
|
-
something = 'something'
|
92
|
-
something.should_receive(:foo)
|
93
|
-
something.foo
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'receives #foo' do
|
98
|
-
TestRunner.new.run
|
99
|
-
end
|
100
|
-
end
|
101
|
-
END
|
102
|
-
end
|
103
|
-
|
104
|
-
context 'with runtime information' do
|
105
|
-
include_context 'dynamic analysis objects'
|
106
|
-
|
107
|
-
it 'raises ContextError' do
|
108
|
-
-> { should_receive_object.expectize! }.should raise_error(ContextError)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
context 'without runtime information' do
|
113
|
-
it 'raises ContextError' do
|
114
|
-
-> { should_receive_object.expectize! }.should raise_error(ContextError)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context 'and the context is not determinable statically' do
|
120
|
-
let(:source) do
|
121
|
-
<<-END
|
122
|
-
def my_eval(&block)
|
123
|
-
Object.new.instance_eval(&block)
|
124
|
-
end
|
125
|
-
|
126
|
-
describe 'example' do
|
127
|
-
it 'receives #foo' do
|
128
|
-
my_eval do
|
129
|
-
something = 'something'
|
130
|
-
something.should_receive(:foo)
|
131
|
-
something.foo
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
END
|
136
|
-
end
|
137
|
-
|
138
|
-
context 'with runtime information' do
|
139
|
-
include_context 'dynamic analysis objects'
|
140
|
-
|
141
|
-
it 'raises ContextError' do
|
142
|
-
-> { should_receive_object.expectize! }.should raise_error(ContextError)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
context 'without runtime information' do
|
147
|
-
it 'does not raise ContextError' do
|
148
|
-
-> { should_receive_object.expectize! }.should_not raise_error
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
context 'with expression `obj.should_not_receive(:message)`' do
|
156
|
-
let(:source) do
|
157
|
-
<<-END
|
158
|
-
describe 'example' do
|
159
|
-
it 'does not receive #foo' do
|
160
|
-
subject.should_not_receive(:foo)
|
161
|
-
end
|
162
|
-
end
|
163
|
-
END
|
164
|
-
end
|
165
|
-
|
166
|
-
let(:expected_source) do
|
167
|
-
<<-END
|
168
|
-
describe 'example' do
|
169
|
-
it 'does not receive #foo' do
|
170
|
-
expect(subject).not_to receive(:foo)
|
171
|
-
end
|
172
|
-
end
|
173
|
-
END
|
174
|
-
end
|
175
|
-
|
176
|
-
it 'converts to `expect(obj).not_to receive(:message)` form' do
|
177
|
-
should_receive_object.expectize!
|
178
|
-
rewritten_source.should == expected_source
|
179
|
-
end
|
180
|
-
|
181
|
-
it 'adds record ' \
|
182
|
-
'`obj.should_not_receive(:message)` -> `expect(obj).not_to receive(:message)`' do
|
183
|
-
should_receive_object.expectize!
|
184
|
-
record.old_syntax.should == 'obj.should_not_receive(:message)'
|
185
|
-
record.new_syntax.should == 'expect(obj).not_to receive(:message)'
|
186
|
-
end
|
187
|
-
|
188
|
-
context 'and "to_not" is passed as negative form' do
|
189
|
-
let(:expected_source) do
|
190
|
-
<<-END
|
191
|
-
describe 'example' do
|
192
|
-
it 'does not receive #foo' do
|
193
|
-
expect(subject).to_not receive(:foo)
|
194
|
-
end
|
195
|
-
end
|
196
|
-
END
|
197
|
-
end
|
198
|
-
|
199
|
-
it 'converts to `expect(obj).to_not receive(:message)` form' do
|
200
|
-
should_receive_object.expectize!('to_not')
|
201
|
-
rewritten_source.should == expected_source
|
202
|
-
end
|
203
|
-
|
204
|
-
it 'adds record ' \
|
205
|
-
'`obj.should_not_receive(:message)` -> `expect(obj).to_not receive(:message)`' do
|
206
|
-
should_receive_object.expectize!('to_not')
|
207
|
-
record.old_syntax.should == 'obj.should_not_receive(:message)'
|
208
|
-
record.new_syntax.should == 'expect(obj).to_not receive(:message)'
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
# Currently MessageExpectation#with supports the following syntax:
|
214
|
-
#
|
215
|
-
# subject.should_receive(:foo).with do |arg|
|
216
|
-
# arg == 1
|
217
|
-
# end
|
218
|
-
#
|
219
|
-
# This syntax allows to expect arbitrary arguments without expect or should.
|
220
|
-
# This is available only when #with got no normal arguments but a block,
|
221
|
-
# and the block will not be used as a substitute implementation.
|
222
|
-
#
|
223
|
-
# https://github.com/rspec/rspec-mocks/blob/e6d1980/lib/rspec/mocks/message_expectation.rb#L307
|
224
|
-
# https://github.com/rspec/rspec-mocks/blob/e6d1980/lib/rspec/mocks/argument_list_matcher.rb#L43
|
225
|
-
#
|
226
|
-
# Then, if you convert the example into expect syntax straightforward:
|
227
|
-
#
|
228
|
-
# expect(subject).to receive(:foo).with do |arg|
|
229
|
-
# arg == 1
|
230
|
-
# end
|
231
|
-
#
|
232
|
-
# The do..end block is taken by the #to method, because {..} blocks have higher precedence
|
233
|
-
# over do..end blocks. This behavior breaks the spec.
|
234
|
-
#
|
235
|
-
# To keep the same meaning of syntax, the block needs to be {..} form literal:
|
236
|
-
#
|
237
|
-
# expect(subject).to receive(:foo).with { |arg|
|
238
|
-
# arg == 1
|
239
|
-
# }
|
240
|
-
#
|
241
|
-
context 'with expression `obj.should_receive(:message).with do .. end`' do
|
242
|
-
let(:source) do
|
243
|
-
<<-END
|
244
|
-
describe 'example' do
|
245
|
-
it 'receives #foo with 1' do
|
246
|
-
subject.should_receive(:foo).with do |arg|
|
247
|
-
arg == 1
|
248
|
-
end
|
249
|
-
subject.foo(1)
|
250
|
-
end
|
251
|
-
end
|
252
|
-
END
|
253
|
-
end
|
254
|
-
|
255
|
-
let(:expected_source) do
|
256
|
-
<<-END
|
257
|
-
describe 'example' do
|
258
|
-
it 'receives #foo with 1' do
|
259
|
-
expect(subject).to receive(:foo).with { |arg|
|
260
|
-
arg == 1
|
261
|
-
}
|
262
|
-
subject.foo(1)
|
263
|
-
end
|
264
|
-
end
|
265
|
-
END
|
266
|
-
end
|
267
|
-
|
268
|
-
it 'converts to `expect(obj).to receive(:message) { .. }` form' do
|
269
|
-
should_receive_object.expectize!
|
270
|
-
rewritten_source.should == expected_source
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
# If #with take normal arguments, the block won't be used as an argument matcher.
|
275
|
-
context 'with expression `obj.should_receive(:message).with(arg) do .. end`' do
|
276
|
-
let(:source) do
|
277
|
-
<<-END
|
278
|
-
describe 'example' do
|
279
|
-
it 'receives #foo with 1' do
|
280
|
-
subject.should_receive(:foo).with(1) do |arg|
|
281
|
-
do_some_substitute_implementation
|
282
|
-
end
|
283
|
-
subject.foo(1)
|
284
|
-
end
|
285
|
-
end
|
286
|
-
END
|
287
|
-
end
|
288
|
-
|
289
|
-
let(:expected_source) do
|
290
|
-
<<-END
|
291
|
-
describe 'example' do
|
292
|
-
it 'receives #foo with 1' do
|
293
|
-
expect(subject).to receive(:foo).with(1) do |arg|
|
294
|
-
do_some_substitute_implementation
|
295
|
-
end
|
296
|
-
subject.foo(1)
|
297
|
-
end
|
298
|
-
end
|
299
|
-
END
|
300
|
-
end
|
301
|
-
|
302
|
-
it 'converts to `expect(obj).to receive(:message).with(arg) do .. end` form' do
|
303
|
-
should_receive_object.expectize!
|
304
|
-
rewritten_source.should == expected_source
|
305
|
-
end
|
306
|
-
end
|
307
|
-
|
308
|
-
# In this case, the do..end block is taken by the #should_receive method.
|
309
|
-
# This means the receiver of #once method is return value of #should_receive,
|
310
|
-
# that is actually an instance of RSpec::Mocks::MessageExpectation.
|
311
|
-
#
|
312
|
-
# subject.should_receive(:foo) do |arg|
|
313
|
-
# arg == 1
|
314
|
-
# end.once
|
315
|
-
#
|
316
|
-
# However with `expect(obj).to receive`, the do..end block is taken by the #to method.
|
317
|
-
# This means the receiver of #once method is return value of #to, that is actually
|
318
|
-
# return value of RSpec::Mocks::Matchers::Receive#setup_method_substitute
|
319
|
-
# and it's not the instance of RSpec::Mocks::MessageExpectation.
|
320
|
-
#
|
321
|
-
# https://github.com/rspec/rspec-mocks/blob/9cdef17/lib/rspec/mocks/targets.rb#L19
|
322
|
-
# https://github.com/rspec/rspec-mocks/blob/9cdef17/lib/rspec/mocks/matchers/receive.rb#L74
|
323
|
-
#
|
324
|
-
# Then, the following syntax will be error:
|
325
|
-
#
|
326
|
-
# expect(subject).to receive(:foo) do |arg|
|
327
|
-
# arg == 1
|
328
|
-
# end.once
|
329
|
-
#
|
330
|
-
# So the block needs to be {..} form literal also in this case.
|
331
|
-
#
|
332
|
-
# expect(subject).to receive(:foo) { |arg|
|
333
|
-
# arg == 1
|
334
|
-
# }.once
|
335
|
-
#
|
336
|
-
context 'with expression `obj.should_receive(:message) do .. end.once`' do
|
337
|
-
let(:source) do
|
338
|
-
<<-END
|
339
|
-
describe 'example' do
|
340
|
-
it 'receives #foo with 1' do
|
341
|
-
subject.should_receive(:foo) do |arg|
|
342
|
-
arg == 1
|
343
|
-
end.once
|
344
|
-
subject.foo(1)
|
345
|
-
end
|
346
|
-
end
|
347
|
-
END
|
348
|
-
end
|
349
|
-
|
350
|
-
let(:expected_source) do
|
351
|
-
<<-END
|
352
|
-
describe 'example' do
|
353
|
-
it 'receives #foo with 1' do
|
354
|
-
expect(subject).to receive(:foo) { |arg|
|
355
|
-
arg == 1
|
356
|
-
}.once
|
357
|
-
subject.foo(1)
|
358
|
-
end
|
359
|
-
end
|
360
|
-
END
|
361
|
-
end
|
362
|
-
|
363
|
-
it 'converts to `expect(obj).to receive(:message) { .. }.once` form' do
|
364
|
-
should_receive_object.expectize!
|
365
|
-
rewritten_source.should == expected_source
|
366
|
-
end
|
367
|
-
end
|
368
|
-
|
369
|
-
# This case, do..end block works without problem.
|
370
|
-
context 'with expression `obj.should_receive(:message) do .. end`' do
|
371
|
-
let(:source) do
|
372
|
-
<<-END
|
373
|
-
describe 'example' do
|
374
|
-
it 'receives #foo with 1' do
|
375
|
-
subject.should_receive(:foo) do |arg|
|
376
|
-
expect(arg).to eq(1)
|
377
|
-
end
|
378
|
-
subject.foo(1)
|
379
|
-
end
|
380
|
-
end
|
381
|
-
END
|
382
|
-
end
|
383
|
-
|
384
|
-
let(:expected_source) do
|
385
|
-
<<-END
|
386
|
-
describe 'example' do
|
387
|
-
it 'receives #foo with 1' do
|
388
|
-
expect(subject).to receive(:foo) do |arg|
|
389
|
-
expect(arg).to eq(1)
|
390
|
-
end
|
391
|
-
subject.foo(1)
|
392
|
-
end
|
393
|
-
end
|
394
|
-
END
|
395
|
-
end
|
396
|
-
|
397
|
-
it 'converts to `expect(obj).to receive(:message) do .. end` form' do
|
398
|
-
should_receive_object.expectize!
|
399
|
-
rewritten_source.should == expected_source
|
400
|
-
end
|
401
|
-
end
|
402
|
-
|
403
|
-
context 'with expression `Klass.any_instance.should_receive(:message)`' do
|
404
|
-
let(:source) do
|
405
|
-
<<-END
|
406
|
-
describe 'example' do
|
407
|
-
it 'receives #foo' do
|
408
|
-
Klass.any_instance.should_receive(:foo)
|
409
|
-
end
|
410
|
-
end
|
411
|
-
END
|
412
|
-
end
|
413
|
-
|
414
|
-
let(:expected_source) do
|
415
|
-
<<-END
|
416
|
-
describe 'example' do
|
417
|
-
it 'receives #foo' do
|
418
|
-
expect_any_instance_of(Klass).to receive(:foo)
|
419
|
-
end
|
420
|
-
end
|
421
|
-
END
|
422
|
-
end
|
423
|
-
|
424
|
-
it 'converts to `expect_any_instance_of(Klass).to receive(:message)` form' do
|
425
|
-
should_receive_object.expectize!
|
426
|
-
rewritten_source.should == expected_source
|
427
|
-
end
|
428
|
-
|
429
|
-
it 'adds record `Klass.any_instance.should_receive(:message)` ' \
|
430
|
-
'-> `expect_any_instance_of(Klass).to receive(:message)`' do
|
431
|
-
should_receive_object.expectize!
|
432
|
-
record.old_syntax.should == 'Klass.any_instance.should_receive(:message)'
|
433
|
-
record.new_syntax.should == 'expect_any_instance_of(Klass).to receive(:message)'
|
434
|
-
end
|
435
|
-
|
436
|
-
context 'when the statement continues over multi lines' do
|
437
|
-
let(:source) do
|
438
|
-
<<-END
|
439
|
-
describe 'example' do
|
440
|
-
it 'receives #foo and returns 1' do
|
441
|
-
Klass
|
442
|
-
.any_instance
|
443
|
-
.should_receive(
|
444
|
-
:foo
|
445
|
-
).
|
446
|
-
and_return(
|
447
|
-
1
|
448
|
-
)
|
449
|
-
end
|
450
|
-
end
|
451
|
-
END
|
452
|
-
end
|
453
|
-
|
454
|
-
let(:expected_source) do
|
455
|
-
<<-END
|
456
|
-
describe 'example' do
|
457
|
-
it 'receives #foo and returns 1' do
|
458
|
-
expect_any_instance_of(Klass)
|
459
|
-
.to receive(
|
460
|
-
:foo
|
461
|
-
).
|
462
|
-
and_return(
|
463
|
-
1
|
464
|
-
)
|
465
|
-
end
|
466
|
-
end
|
467
|
-
END
|
468
|
-
end
|
469
|
-
|
470
|
-
it 'keeps the style as far as possible' do
|
471
|
-
should_receive_object.expectize!
|
472
|
-
rewritten_source.should == expected_source
|
473
|
-
end
|
474
|
-
end
|
475
|
-
end
|
476
|
-
|
477
|
-
context 'with expression `described_class.any_instance.should_receive(:message)`' do
|
478
|
-
let(:source) do
|
479
|
-
<<-END
|
480
|
-
describe 'example' do
|
481
|
-
it 'receives #foo' do
|
482
|
-
described_class.any_instance.should_receive(:foo)
|
483
|
-
end
|
484
|
-
end
|
485
|
-
END
|
486
|
-
end
|
487
|
-
|
488
|
-
let(:expected_source) do
|
489
|
-
<<-END
|
490
|
-
describe 'example' do
|
491
|
-
it 'receives #foo' do
|
492
|
-
expect_any_instance_of(described_class).to receive(:foo)
|
493
|
-
end
|
494
|
-
end
|
495
|
-
END
|
496
|
-
end
|
497
|
-
|
498
|
-
it 'converts to `expect_any_instance_of(described_class).to receive(:message)` form' do
|
499
|
-
should_receive_object.expectize!
|
500
|
-
rewritten_source.should == expected_source
|
501
|
-
end
|
502
|
-
|
503
|
-
it 'adds record `Klass.any_instance.should_receive(:message)` ' \
|
504
|
-
'-> `expect_any_instance_of(Klass).to receive(:message)`' do
|
505
|
-
should_receive_object.expectize!
|
506
|
-
record.old_syntax.should == 'Klass.any_instance.should_receive(:message)'
|
507
|
-
record.new_syntax.should == 'expect_any_instance_of(Klass).to receive(:message)'
|
508
|
-
end
|
509
|
-
end
|
510
|
-
|
511
|
-
context 'with expression `variable.any_instance.should_receive(:message)`' do
|
512
|
-
let(:source) do
|
513
|
-
<<-END
|
514
|
-
describe 'example' do
|
515
|
-
it 'receives #foo' do
|
516
|
-
variable = String
|
517
|
-
variable.any_instance.should_receive(:foo)
|
518
|
-
'string'.foo
|
519
|
-
end
|
520
|
-
end
|
521
|
-
END
|
522
|
-
end
|
523
|
-
|
524
|
-
let(:expected_source) do
|
525
|
-
<<-END
|
526
|
-
describe 'example' do
|
527
|
-
it 'receives #foo' do
|
528
|
-
variable = String
|
529
|
-
expect_any_instance_of(variable).to receive(:foo)
|
530
|
-
'string'.foo
|
531
|
-
end
|
532
|
-
end
|
533
|
-
END
|
534
|
-
end
|
535
|
-
|
536
|
-
it 'converts to `expect_any_instance_of(variable).to receive(:message)` form' do
|
537
|
-
should_receive_object.expectize!
|
538
|
-
rewritten_source.should == expected_source
|
539
|
-
end
|
540
|
-
|
541
|
-
it 'adds record `Klass.any_instance.should_receive(:message)` ' \
|
542
|
-
'-> `expect_any_instance_of(Klass).to receive(:message)`' do
|
543
|
-
should_receive_object.expectize!
|
544
|
-
record.old_syntax.should == 'Klass.any_instance.should_receive(:message)'
|
545
|
-
record.new_syntax.should == 'expect_any_instance_of(Klass).to receive(:message)'
|
546
|
-
end
|
547
|
-
end
|
548
|
-
|
549
|
-
context 'with expression `variable.should_receive(:message)` ' \
|
550
|
-
'and the variable is an AnyInstance::Recorder' do
|
551
|
-
context 'with runtime information' do
|
552
|
-
include_context 'dynamic analysis objects'
|
553
|
-
|
554
|
-
let(:source) do
|
555
|
-
<<-END
|
556
|
-
describe 'example' do
|
557
|
-
it 'receives #foo' do
|
558
|
-
variable = String.any_instance
|
559
|
-
variable.should_receive(:foo)
|
560
|
-
'string'.foo
|
561
|
-
end
|
562
|
-
end
|
563
|
-
END
|
564
|
-
end
|
565
|
-
|
566
|
-
let(:expected_source) do
|
567
|
-
<<-END
|
568
|
-
describe 'example' do
|
569
|
-
it 'receives #foo' do
|
570
|
-
variable = String.any_instance
|
571
|
-
expect_any_instance_of(String).to receive(:foo)
|
572
|
-
'string'.foo
|
573
|
-
end
|
574
|
-
end
|
575
|
-
END
|
576
|
-
end
|
577
|
-
|
578
|
-
it 'converts to `expect_any_instance_of(Klass).to receive(:message)` form' do
|
579
|
-
should_receive_object.expectize!
|
580
|
-
rewritten_source.should == expected_source
|
581
|
-
end
|
582
|
-
|
583
|
-
it 'adds record `Klass.any_instance.should_receive(:message)` ' \
|
584
|
-
'-> `expect_any_instance_of(Klass).to receive(:message)`' do
|
585
|
-
should_receive_object.expectize!
|
586
|
-
record.old_syntax.should == 'Klass.any_instance.should_receive(:message)'
|
587
|
-
record.new_syntax.should == 'expect_any_instance_of(Klass).to receive(:message)'
|
588
|
-
end
|
589
|
-
end
|
590
|
-
end
|
591
|
-
end
|
592
|
-
|
593
|
-
describe '#useless_expectation?' do
|
594
|
-
subject { should_receive_object.useless_expectation? }
|
595
|
-
|
596
|
-
context 'with expression `obj.should_receive(:message).any_number_of_times`' do
|
597
|
-
let(:source) do
|
598
|
-
<<-END
|
599
|
-
describe 'example' do
|
600
|
-
it 'responds to #foo' do
|
601
|
-
subject.should_receive(:foo).any_number_of_times
|
602
|
-
end
|
603
|
-
end
|
604
|
-
END
|
605
|
-
end
|
606
|
-
|
607
|
-
it { should be_true }
|
608
|
-
end
|
609
|
-
|
610
|
-
context 'with expression `obj.should_receive(:message).with(arg).any_number_of_times`' do
|
611
|
-
let(:source) do
|
612
|
-
<<-END
|
613
|
-
describe 'example' do
|
614
|
-
it 'responds to #foo with 1' do
|
615
|
-
subject.should_receive(:foo).with(1).any_number_of_times
|
616
|
-
end
|
617
|
-
end
|
618
|
-
END
|
619
|
-
end
|
620
|
-
|
621
|
-
it { should be_true }
|
622
|
-
end
|
623
|
-
|
624
|
-
context 'with expression `obj.should_receive(:message).at_least(0)`' do
|
625
|
-
let(:source) do
|
626
|
-
<<-END
|
627
|
-
describe 'example' do
|
628
|
-
it 'responds to #foo' do
|
629
|
-
subject.should_receive(:foo).at_least(0)
|
630
|
-
end
|
631
|
-
end
|
632
|
-
END
|
633
|
-
end
|
634
|
-
|
635
|
-
it { should be_true }
|
636
|
-
end
|
637
|
-
|
638
|
-
context 'with expression `obj.should_receive(:message).at_least(1)`' do
|
639
|
-
let(:source) do
|
640
|
-
<<-END
|
641
|
-
describe 'example' do
|
642
|
-
it 'receives #foo at least once' do
|
643
|
-
subject.should_receive(:foo).with(1).at_least(1)
|
644
|
-
end
|
645
|
-
end
|
646
|
-
END
|
647
|
-
end
|
648
|
-
|
649
|
-
it { should be_false }
|
650
|
-
end
|
651
|
-
|
652
|
-
context 'with expression `obj.should_receive(:message)`' do
|
653
|
-
let(:source) do
|
654
|
-
<<-END
|
655
|
-
describe 'example' do
|
656
|
-
it 'receives to #foo' do
|
657
|
-
subject.should_receive(:foo)
|
658
|
-
end
|
659
|
-
end
|
660
|
-
END
|
661
|
-
end
|
662
|
-
|
663
|
-
it { should be_false }
|
664
|
-
end
|
665
|
-
end
|
666
|
-
|
667
|
-
describe '#allowize_useless_expectation!' do
|
668
|
-
context 'with expression `obj.should_receive(:message).any_number_of_times`' do
|
669
|
-
let(:source) do
|
670
|
-
<<-END
|
671
|
-
describe 'example' do
|
672
|
-
it 'responds to #foo' do
|
673
|
-
subject.should_receive(:foo).any_number_of_times
|
674
|
-
end
|
675
|
-
end
|
676
|
-
END
|
677
|
-
end
|
678
|
-
|
679
|
-
let(:expected_source) do
|
680
|
-
<<-END
|
681
|
-
describe 'example' do
|
682
|
-
it 'responds to #foo' do
|
683
|
-
allow(subject).to receive(:foo)
|
684
|
-
end
|
685
|
-
end
|
686
|
-
END
|
687
|
-
end
|
688
|
-
|
689
|
-
it 'converts to `allow(obj).to receive(:message)` form' do
|
690
|
-
should_receive_object.allowize_useless_expectation!
|
691
|
-
rewritten_source.should == expected_source
|
692
|
-
end
|
693
|
-
|
694
|
-
it 'adds record ' \
|
695
|
-
'`obj.should_receive(:message).any_number_of_times` -> `allow(obj).to receive(:message)`' do
|
696
|
-
should_receive_object.allowize_useless_expectation!
|
697
|
-
record.old_syntax.should == 'obj.should_receive(:message).any_number_of_times'
|
698
|
-
record.new_syntax.should == 'allow(obj).to receive(:message)'
|
699
|
-
end
|
700
|
-
|
701
|
-
context 'and #allow and #receive are not available in the context' do
|
702
|
-
context 'and the context is determinable statically' do
|
703
|
-
let(:source) do
|
704
|
-
<<-END
|
705
|
-
describe 'example' do
|
706
|
-
class TestRunner
|
707
|
-
def run
|
708
|
-
'something'.should_receive(:foo).any_number_of_times
|
709
|
-
end
|
710
|
-
end
|
711
|
-
|
712
|
-
it 'responds to #foo' do
|
713
|
-
TestRunner.new.run
|
714
|
-
end
|
715
|
-
end
|
716
|
-
END
|
717
|
-
end
|
718
|
-
|
719
|
-
context 'with runtime information' do
|
720
|
-
include_context 'dynamic analysis objects'
|
721
|
-
|
722
|
-
it 'raises ContextError' do
|
723
|
-
-> { should_receive_object.allowize_useless_expectation! }
|
724
|
-
.should raise_error(ContextError)
|
725
|
-
end
|
726
|
-
end
|
727
|
-
|
728
|
-
context 'without runtime information' do
|
729
|
-
it 'raises ContextError' do
|
730
|
-
-> { should_receive_object.allowize_useless_expectation! }
|
731
|
-
.should raise_error(ContextError)
|
732
|
-
end
|
733
|
-
end
|
734
|
-
end
|
735
|
-
|
736
|
-
context 'and the context is not determinable statically' do
|
737
|
-
let(:source) do
|
738
|
-
<<-END
|
739
|
-
def my_eval(&block)
|
740
|
-
Object.new.instance_eval(&block)
|
741
|
-
end
|
742
|
-
|
743
|
-
describe 'example' do
|
744
|
-
it 'responds to #foo' do
|
745
|
-
my_eval { 'something'.should_receive(:foo).any_number_of_times }
|
746
|
-
end
|
747
|
-
end
|
748
|
-
END
|
749
|
-
end
|
750
|
-
|
751
|
-
context 'with runtime information' do
|
752
|
-
include_context 'dynamic analysis objects'
|
753
|
-
|
754
|
-
it 'raises ContextError' do
|
755
|
-
-> { should_receive_object.allowize_useless_expectation! }
|
756
|
-
.should raise_error(ContextError)
|
757
|
-
end
|
758
|
-
end
|
759
|
-
|
760
|
-
context 'without runtime information' do
|
761
|
-
it 'does not raise ContextError' do
|
762
|
-
-> { should_receive_object.allowize_useless_expectation! }
|
763
|
-
.should_not raise_error
|
764
|
-
end
|
765
|
-
end
|
766
|
-
end
|
767
|
-
end
|
768
|
-
end
|
769
|
-
|
770
|
-
context 'with expression `Klass.any_instance.should_receive(:message).any_number_of_times`' do
|
771
|
-
let(:source) do
|
772
|
-
<<-END
|
773
|
-
describe 'example' do
|
774
|
-
it 'responds to #foo' do
|
775
|
-
Klass.any_instance.should_receive(:foo).any_number_of_times
|
776
|
-
end
|
777
|
-
end
|
778
|
-
END
|
779
|
-
end
|
780
|
-
|
781
|
-
let(:expected_source) do
|
782
|
-
<<-END
|
783
|
-
describe 'example' do
|
784
|
-
it 'responds to #foo' do
|
785
|
-
allow_any_instance_of(Klass).to receive(:foo)
|
786
|
-
end
|
787
|
-
end
|
788
|
-
END
|
789
|
-
end
|
790
|
-
|
791
|
-
it 'converts to `allow_any_instance_of(Klass).to receive(:message)` form' do
|
792
|
-
should_receive_object.allowize_useless_expectation!
|
793
|
-
rewritten_source.should == expected_source
|
794
|
-
end
|
795
|
-
|
796
|
-
it 'adds record `Klass.any_instance.should_receive(:message).any_number_of_times` ' \
|
797
|
-
'-> `allow_any_instance_of(Klass).to receive(:message)`' do
|
798
|
-
should_receive_object.allowize_useless_expectation!
|
799
|
-
record.old_syntax.should == 'Klass.any_instance.should_receive(:message).any_number_of_times'
|
800
|
-
record.new_syntax.should == 'allow_any_instance_of(Klass).to receive(:message)'
|
801
|
-
end
|
802
|
-
end
|
803
|
-
|
804
|
-
context 'with expression `described_class.any_instance.should_receive(:message).any_number_of_times`' do
|
805
|
-
let(:source) do
|
806
|
-
<<-END
|
807
|
-
describe 'example' do
|
808
|
-
it 'responds to #foo' do
|
809
|
-
described_class.any_instance.should_receive(:foo).any_number_of_times
|
810
|
-
end
|
811
|
-
end
|
812
|
-
END
|
813
|
-
end
|
814
|
-
|
815
|
-
let(:expected_source) do
|
816
|
-
<<-END
|
817
|
-
describe 'example' do
|
818
|
-
it 'responds to #foo' do
|
819
|
-
allow_any_instance_of(described_class).to receive(:foo)
|
820
|
-
end
|
821
|
-
end
|
822
|
-
END
|
823
|
-
end
|
824
|
-
|
825
|
-
it 'converts to `allow_any_instance_of(described_class).to receive(:message)` form' do
|
826
|
-
should_receive_object.allowize_useless_expectation!
|
827
|
-
rewritten_source.should == expected_source
|
828
|
-
end
|
829
|
-
|
830
|
-
it 'adds record `Klass.any_instance.should_receive(:message).any_number_of_times` ' \
|
831
|
-
'-> `allow_any_instance_of(Klass).to receive(:message)`' do
|
832
|
-
should_receive_object.allowize_useless_expectation!
|
833
|
-
record.old_syntax.should == 'Klass.any_instance.should_receive(:message).any_number_of_times'
|
834
|
-
record.new_syntax.should == 'allow_any_instance_of(Klass).to receive(:message)'
|
835
|
-
end
|
836
|
-
end
|
837
|
-
|
838
|
-
context 'with expression `obj.should_receive(:message).at_least(0)`' do
|
839
|
-
let(:source) do
|
840
|
-
<<-END
|
841
|
-
describe 'example' do
|
842
|
-
it 'responds to #foo' do
|
843
|
-
subject.should_receive(:foo).at_least(0)
|
844
|
-
end
|
845
|
-
end
|
846
|
-
END
|
847
|
-
end
|
848
|
-
|
849
|
-
let(:expected_source) do
|
850
|
-
<<-END
|
851
|
-
describe 'example' do
|
852
|
-
it 'responds to #foo' do
|
853
|
-
allow(subject).to receive(:foo)
|
854
|
-
end
|
855
|
-
end
|
856
|
-
END
|
857
|
-
end
|
858
|
-
|
859
|
-
it 'converts to `allow(obj).to receive(:message)` form' do
|
860
|
-
should_receive_object.allowize_useless_expectation!
|
861
|
-
rewritten_source.should == expected_source
|
862
|
-
end
|
863
|
-
|
864
|
-
it 'adds record ' \
|
865
|
-
'`obj.should_receive(:message).at_least(0)` -> `allow(obj).to receive(:message)`' do
|
866
|
-
should_receive_object.allowize_useless_expectation!
|
867
|
-
record.old_syntax.should == 'obj.should_receive(:message).at_least(0)'
|
868
|
-
record.new_syntax.should == 'allow(obj).to receive(:message)'
|
869
|
-
end
|
870
|
-
end
|
871
|
-
|
872
|
-
context 'with expression `Klass.any_instance.should_receive(:message).at_least(0)`' do
|
873
|
-
let(:source) do
|
874
|
-
<<-END
|
875
|
-
describe 'example' do
|
876
|
-
it 'responds to #foo' do
|
877
|
-
Klass.any_instance.should_receive(:foo).at_least(0)
|
878
|
-
end
|
879
|
-
end
|
880
|
-
END
|
881
|
-
end
|
882
|
-
|
883
|
-
let(:expected_source) do
|
884
|
-
<<-END
|
885
|
-
describe 'example' do
|
886
|
-
it 'responds to #foo' do
|
887
|
-
allow_any_instance_of(Klass).to receive(:foo)
|
888
|
-
end
|
889
|
-
end
|
890
|
-
END
|
891
|
-
end
|
892
|
-
|
893
|
-
it 'converts to `allow_any_instance_of(Klass).to receive(:message)` form' do
|
894
|
-
should_receive_object.allowize_useless_expectation!
|
895
|
-
rewritten_source.should == expected_source
|
896
|
-
end
|
897
|
-
|
898
|
-
it 'adds record `Klass.any_instance.should_receive(:message).at_least(0)` ' \
|
899
|
-
'-> `allow_any_instance_of(Klass).to receive(:message)`' do
|
900
|
-
should_receive_object.allowize_useless_expectation!
|
901
|
-
record.old_syntax.should == 'Klass.any_instance.should_receive(:message).at_least(0)'
|
902
|
-
record.new_syntax.should == 'allow_any_instance_of(Klass).to receive(:message)'
|
903
|
-
end
|
904
|
-
end
|
905
|
-
|
906
|
-
context 'with expression `obj.should_receive(:message)`' do
|
907
|
-
let(:source) do
|
908
|
-
<<-END
|
909
|
-
describe 'example' do
|
910
|
-
it 'receives to #foo' do
|
911
|
-
subject.should_receive(:foo)
|
912
|
-
end
|
913
|
-
end
|
914
|
-
END
|
915
|
-
end
|
916
|
-
|
917
|
-
it 'does nothing' do
|
918
|
-
should_receive_object.allowize_useless_expectation!
|
919
|
-
rewritten_source.should == source
|
920
|
-
end
|
921
|
-
end
|
922
|
-
end
|
923
|
-
|
924
|
-
describe '#stubize_useless_expectation!' do
|
925
|
-
before do
|
926
|
-
should_receive_object.stubize_useless_expectation!
|
927
|
-
end
|
928
|
-
|
929
|
-
context 'with expression `obj.should_receive(:message).any_number_of_times`' do
|
930
|
-
let(:source) do
|
931
|
-
<<-END
|
932
|
-
describe 'example' do
|
933
|
-
it 'responds to #foo' do
|
934
|
-
subject.should_receive(:foo).any_number_of_times
|
935
|
-
end
|
936
|
-
end
|
937
|
-
END
|
938
|
-
end
|
939
|
-
|
940
|
-
let(:expected_source) do
|
941
|
-
<<-END
|
942
|
-
describe 'example' do
|
943
|
-
it 'responds to #foo' do
|
944
|
-
subject.stub(:foo)
|
945
|
-
end
|
946
|
-
end
|
947
|
-
END
|
948
|
-
end
|
949
|
-
|
950
|
-
it 'converts to `obj.stub(:message)` form' do
|
951
|
-
rewritten_source.should == expected_source
|
952
|
-
end
|
953
|
-
|
954
|
-
it 'adds record ' \
|
955
|
-
'`obj.should_receive(:message).any_number_of_times` -> `obj.stub(:message)`' do
|
956
|
-
record.old_syntax.should == 'obj.should_receive(:message).any_number_of_times'
|
957
|
-
record.new_syntax.should == 'obj.stub(:message)'
|
958
|
-
end
|
959
|
-
end
|
960
|
-
|
961
|
-
context 'with expression `obj.should_receive(:message)`' do
|
962
|
-
let(:source) do
|
963
|
-
<<-END
|
964
|
-
describe 'example' do
|
965
|
-
it 'receives to #foo' do
|
966
|
-
subject.should_receive(:foo)
|
967
|
-
end
|
968
|
-
end
|
969
|
-
END
|
970
|
-
end
|
971
|
-
|
972
|
-
it 'does nothing' do
|
973
|
-
rewritten_source.should == source
|
974
|
-
end
|
975
|
-
end
|
976
|
-
end
|
977
|
-
|
978
|
-
describe '#remove_useless_and_return!' do
|
979
|
-
before do
|
980
|
-
should_receive_object.remove_useless_and_return!
|
981
|
-
end
|
982
|
-
|
983
|
-
context 'with expression `obj.should_receive(:message).and_return { value }`' do
|
984
|
-
let(:source) do
|
985
|
-
<<-END
|
986
|
-
describe 'example' do
|
987
|
-
it 'receives #foo and returns 1' do
|
988
|
-
subject.should_receive(:foo).and_return { 1 }
|
989
|
-
end
|
990
|
-
end
|
991
|
-
END
|
992
|
-
end
|
993
|
-
|
994
|
-
let(:expected_source) do
|
995
|
-
<<-END
|
996
|
-
describe 'example' do
|
997
|
-
it 'receives #foo and returns 1' do
|
998
|
-
subject.should_receive(:foo) { 1 }
|
999
|
-
end
|
1000
|
-
end
|
1001
|
-
END
|
1002
|
-
end
|
1003
|
-
|
1004
|
-
it 'converts to `obj.should_receive(:message) { value }` form' do
|
1005
|
-
rewritten_source.should == expected_source
|
1006
|
-
end
|
1007
|
-
|
1008
|
-
it 'adds record ' \
|
1009
|
-
'`obj.should_receive(:message).and_return { value }` -> `obj.should_receive(:message) { value }`' do
|
1010
|
-
record.old_syntax.should == 'obj.should_receive(:message).and_return { value }'
|
1011
|
-
record.new_syntax.should == 'obj.should_receive(:message) { value }'
|
1012
|
-
end
|
1013
|
-
end
|
1014
|
-
end
|
1015
|
-
|
1016
|
-
describe '#add_receiver_arg_to_any_instance_implementation_block!' do
|
1017
|
-
before do
|
1018
|
-
should_receive_object.add_receiver_arg_to_any_instance_implementation_block!
|
1019
|
-
end
|
1020
|
-
|
1021
|
-
context 'with expression `Klass.any_instance.should_receive(:message) do |arg| .. end`' do
|
1022
|
-
let(:source) do
|
1023
|
-
<<-END
|
1024
|
-
describe 'example' do
|
1025
|
-
it 'receives #foo' do
|
1026
|
-
Klass.any_instance.should_receive(:foo) do |arg|
|
1027
|
-
end
|
1028
|
-
end
|
1029
|
-
end
|
1030
|
-
END
|
1031
|
-
end
|
1032
|
-
|
1033
|
-
let(:expected_source) do
|
1034
|
-
<<-END
|
1035
|
-
describe 'example' do
|
1036
|
-
it 'receives #foo' do
|
1037
|
-
Klass.any_instance.should_receive(:foo) do |instance, arg|
|
1038
|
-
end
|
1039
|
-
end
|
1040
|
-
end
|
1041
|
-
END
|
1042
|
-
end
|
1043
|
-
|
1044
|
-
it 'converts to `Klass.any_instance.should_receive(:message) do |instance, arg| .. end` form' do
|
1045
|
-
rewritten_source.should == expected_source
|
1046
|
-
end
|
1047
|
-
|
1048
|
-
it 'adds record `Klass.any_instance.should_receive(:message) { |arg| }` ' \
|
1049
|
-
'-> `Klass.any_instance.should_receive(:message) { |instance, arg| }`' do
|
1050
|
-
record.old_syntax.should == 'Klass.any_instance.should_receive(:message) { |arg| }'
|
1051
|
-
record.new_syntax.should == 'Klass.any_instance.should_receive(:message) { |instance, arg| }'
|
1052
|
-
end
|
1053
|
-
end
|
1054
|
-
|
1055
|
-
context 'with expression `Klass.any_instance.should_receive(:message) do .. end`' do
|
1056
|
-
let(:source) do
|
1057
|
-
<<-END
|
1058
|
-
describe 'example' do
|
1059
|
-
it 'receives #foo' do
|
1060
|
-
Klass.any_instance.should_receive(:foo) do
|
1061
|
-
end
|
1062
|
-
end
|
1063
|
-
end
|
1064
|
-
END
|
1065
|
-
end
|
1066
|
-
|
1067
|
-
it 'does nothing' do
|
1068
|
-
rewritten_source.should == source
|
1069
|
-
end
|
1070
|
-
end
|
1071
|
-
|
1072
|
-
context 'with expression `Klass.any_instance.should_receive(:message) do |instance| .. end`' do
|
1073
|
-
let(:source) do
|
1074
|
-
<<-END
|
1075
|
-
describe 'example' do
|
1076
|
-
it 'receives #foo' do
|
1077
|
-
Klass.any_instance.should_receive(:foo) do |instance|
|
1078
|
-
end
|
1079
|
-
end
|
1080
|
-
end
|
1081
|
-
END
|
1082
|
-
end
|
1083
|
-
|
1084
|
-
it 'does nothing' do
|
1085
|
-
rewritten_source.should == source
|
1086
|
-
end
|
1087
|
-
end
|
1088
|
-
|
1089
|
-
context 'with expression `obj.should_receive(:message) do |arg| .. end`' do
|
1090
|
-
let(:source) do
|
1091
|
-
<<-END
|
1092
|
-
describe 'example' do
|
1093
|
-
it 'receives #foo' do
|
1094
|
-
subject.should_receive(:foo) do |arg|
|
1095
|
-
end
|
1096
|
-
end
|
1097
|
-
end
|
1098
|
-
END
|
1099
|
-
end
|
1100
|
-
|
1101
|
-
it 'does nothing' do
|
1102
|
-
rewritten_source.should == source
|
1103
|
-
end
|
1104
|
-
end
|
1105
|
-
end
|
1106
|
-
end
|
1107
|
-
end
|
1108
|
-
end
|