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,59 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'transpec/syntax/matcher_definition'
|
5
|
-
|
6
|
-
module Transpec
|
7
|
-
class Syntax
|
8
|
-
describe MatcherDefinition do
|
9
|
-
include_context 'parsed objects'
|
10
|
-
include_context 'syntax object', MatcherDefinition, :matcher_definition
|
11
|
-
|
12
|
-
let(:record) { matcher_definition.report.records.last }
|
13
|
-
|
14
|
-
describe '#convert_deprecated_method!' do
|
15
|
-
before do
|
16
|
-
matcher_definition.convert_deprecated_method!
|
17
|
-
end
|
18
|
-
|
19
|
-
[
|
20
|
-
[:match_for_should, :match],
|
21
|
-
[:match_for_should_not, :match_when_negated],
|
22
|
-
[:failure_message_for_should, :failure_message],
|
23
|
-
[:failure_message_for_should_not, :failure_message_when_negated]
|
24
|
-
].each do |target_method, converted_method|
|
25
|
-
context "with expression `#{target_method} { }`" do
|
26
|
-
let(:source) do
|
27
|
-
<<-END
|
28
|
-
RSpec::Matchers.define :be_awesome do |expected|
|
29
|
-
#{target_method} do |actual|
|
30
|
-
true
|
31
|
-
end
|
32
|
-
end
|
33
|
-
END
|
34
|
-
end
|
35
|
-
|
36
|
-
let(:expected_source) do
|
37
|
-
<<-END
|
38
|
-
RSpec::Matchers.define :be_awesome do |expected|
|
39
|
-
#{converted_method} do |actual|
|
40
|
-
true
|
41
|
-
end
|
42
|
-
end
|
43
|
-
END
|
44
|
-
end
|
45
|
-
|
46
|
-
it "converts to `#{converted_method} { }` form" do
|
47
|
-
rewritten_source.should == expected_source
|
48
|
-
end
|
49
|
-
|
50
|
-
it "adds record `#{target_method} { }` -> `#{converted_method} { }`" do
|
51
|
-
record.old_syntax.should == "#{target_method} { }"
|
52
|
-
record.new_syntax.should == "#{converted_method} { }"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,1301 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'transpec/syntax/method_stub'
|
5
|
-
require 'transpec'
|
6
|
-
|
7
|
-
module Transpec
|
8
|
-
class Syntax
|
9
|
-
describe MethodStub do
|
10
|
-
include_context 'parsed objects'
|
11
|
-
include_context 'syntax object', MethodStub, :method_stub_object
|
12
|
-
|
13
|
-
let(:record) { method_stub_object.report.records.first }
|
14
|
-
|
15
|
-
describe '#conversion_target?' do
|
16
|
-
let(:target_node) do
|
17
|
-
ast.each_node(:send).find do |send_node|
|
18
|
-
method_name = send_node.children[1]
|
19
|
-
method_name == :stub
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
let(:method_stub_object) do
|
24
|
-
MethodStub.new(target_node, runtime_data)
|
25
|
-
end
|
26
|
-
|
27
|
-
subject { method_stub_object.conversion_target? }
|
28
|
-
|
29
|
-
context 'when #stub node is passed' do
|
30
|
-
let(:source) do
|
31
|
-
<<-END
|
32
|
-
describe 'example' do
|
33
|
-
it 'responds to #foo' do
|
34
|
-
subject.stub(:foo)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
END
|
38
|
-
end
|
39
|
-
|
40
|
-
it { should be_true }
|
41
|
-
end
|
42
|
-
|
43
|
-
context 'when Factory.stub node is passed' do
|
44
|
-
let(:source) do
|
45
|
-
<<-END
|
46
|
-
describe 'example' do
|
47
|
-
it "is not RSpec's #stub" do
|
48
|
-
Factory.stub(:foo)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
END
|
52
|
-
end
|
53
|
-
|
54
|
-
it { should be_false }
|
55
|
-
end
|
56
|
-
|
57
|
-
context 'with runtime information' do
|
58
|
-
include_context 'dynamic analysis objects'
|
59
|
-
|
60
|
-
context "when RSpec's #stub node is passed" do
|
61
|
-
let(:source) do
|
62
|
-
<<-END
|
63
|
-
describe 'example' do
|
64
|
-
it 'responds to #foo' do
|
65
|
-
subject.stub(:foo)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
END
|
69
|
-
end
|
70
|
-
|
71
|
-
it { should be_true }
|
72
|
-
end
|
73
|
-
|
74
|
-
context 'when another #stub node is passed' do
|
75
|
-
let(:source) do
|
76
|
-
<<-END
|
77
|
-
module AnotherStubProvider
|
78
|
-
def self.stub(*args)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe 'example' do
|
83
|
-
it "is not RSpec's #stub" do
|
84
|
-
AnotherStubProvider.stub(:something)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
END
|
88
|
-
end
|
89
|
-
|
90
|
-
it { should be_false }
|
91
|
-
end
|
92
|
-
|
93
|
-
context "when Factory.stub node is passed and it's RSpec's #stub" do
|
94
|
-
let(:source) do
|
95
|
-
<<-END
|
96
|
-
module Factory
|
97
|
-
end
|
98
|
-
|
99
|
-
describe 'example' do
|
100
|
-
it 'responds to #foo' do
|
101
|
-
Factory.stub(:foo)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
END
|
105
|
-
end
|
106
|
-
|
107
|
-
it { should be_true }
|
108
|
-
end
|
109
|
-
|
110
|
-
context 'when Factory.stub node is passed and it has not been run' do
|
111
|
-
let(:source) do
|
112
|
-
<<-END
|
113
|
-
module Factory
|
114
|
-
end
|
115
|
-
|
116
|
-
describe 'example' do
|
117
|
-
it 'responds to #foo' do
|
118
|
-
true || Factory.stub(:foo)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
END
|
122
|
-
end
|
123
|
-
|
124
|
-
it { should be_false }
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
describe '#method_name' do
|
130
|
-
let(:source) do
|
131
|
-
<<-END
|
132
|
-
describe 'example' do
|
133
|
-
it 'responds to #foo' do
|
134
|
-
subject.stub(:foo)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
END
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'returns the method name' do
|
141
|
-
method_stub_object.method_name.should == :stub
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
describe '#hash_arg?' do
|
146
|
-
subject { method_stub_object.hash_arg? }
|
147
|
-
|
148
|
-
context 'with expression `obj.stub(:message => value)`' do
|
149
|
-
let(:source) do
|
150
|
-
<<-END
|
151
|
-
describe 'example' do
|
152
|
-
it 'responds to #foo' do
|
153
|
-
subject.stub(:foo => value)
|
154
|
-
end
|
155
|
-
end
|
156
|
-
END
|
157
|
-
end
|
158
|
-
|
159
|
-
it { should be_true }
|
160
|
-
end
|
161
|
-
|
162
|
-
context 'with expression `obj.stub(:message)`' do
|
163
|
-
let(:source) do
|
164
|
-
<<-END
|
165
|
-
describe 'example' do
|
166
|
-
it 'responds to #foo' do
|
167
|
-
subject.stub(:foo)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
END
|
171
|
-
end
|
172
|
-
|
173
|
-
it { should be_false }
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
describe '#allowize!' do
|
178
|
-
before do
|
179
|
-
method_stub_object.stub(:rspec_version).and_return(rspec_version)
|
180
|
-
method_stub_object.allowize! unless example.metadata[:no_before_allowize!]
|
181
|
-
end
|
182
|
-
|
183
|
-
let(:rspec_version) { Transpec.required_rspec_version }
|
184
|
-
|
185
|
-
context 'with expression `obj.stub(:message)`' do
|
186
|
-
let(:source) do
|
187
|
-
<<-END
|
188
|
-
describe 'example' do
|
189
|
-
it 'responds to #foo' do
|
190
|
-
subject.stub(:foo)
|
191
|
-
end
|
192
|
-
end
|
193
|
-
END
|
194
|
-
end
|
195
|
-
|
196
|
-
let(:expected_source) do
|
197
|
-
<<-END
|
198
|
-
describe 'example' do
|
199
|
-
it 'responds to #foo' do
|
200
|
-
allow(subject).to receive(:foo)
|
201
|
-
end
|
202
|
-
end
|
203
|
-
END
|
204
|
-
end
|
205
|
-
|
206
|
-
it 'converts to `allow(obj).to receive(:message)` form' do
|
207
|
-
rewritten_source.should == expected_source
|
208
|
-
end
|
209
|
-
|
210
|
-
it 'adds record `obj.stub(:message)` -> `allow(obj).to receive(:message)`' do
|
211
|
-
record.old_syntax.should == 'obj.stub(:message)'
|
212
|
-
record.new_syntax.should == 'allow(obj).to receive(:message)'
|
213
|
-
end
|
214
|
-
|
215
|
-
context 'with runtime information' do
|
216
|
-
include_context 'dynamic analysis objects'
|
217
|
-
|
218
|
-
it 'converts to `allow(obj).to receive(:message)` form' do
|
219
|
-
rewritten_source.should == expected_source
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
context 'and #allow and #receive are not available in the context', :no_before_allowize! do
|
224
|
-
context 'and the context is determinable statically' do
|
225
|
-
let(:source) do
|
226
|
-
<<-END
|
227
|
-
describe 'example' do
|
228
|
-
class TestRunner
|
229
|
-
def run
|
230
|
-
'something'.stub(:foo)
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
it 'responds to #foo' do
|
235
|
-
TestRunner.new.run
|
236
|
-
end
|
237
|
-
end
|
238
|
-
END
|
239
|
-
end
|
240
|
-
|
241
|
-
context 'with runtime information' do
|
242
|
-
include_context 'dynamic analysis objects'
|
243
|
-
|
244
|
-
it 'raises ContextError' do
|
245
|
-
-> { method_stub_object.allowize! }.should raise_error(ContextError)
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
context 'without runtime information' do
|
250
|
-
it 'raises ContextError' do
|
251
|
-
-> { method_stub_object.allowize! }.should raise_error(ContextError)
|
252
|
-
end
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
context 'and the context is not determinable statically' do
|
257
|
-
let(:source) do
|
258
|
-
<<-END
|
259
|
-
def my_eval(&block)
|
260
|
-
Object.new.instance_eval(&block)
|
261
|
-
end
|
262
|
-
|
263
|
-
describe 'example' do
|
264
|
-
it 'responds to #foo' do
|
265
|
-
my_eval { 'something'.stub(:foo) }
|
266
|
-
end
|
267
|
-
end
|
268
|
-
END
|
269
|
-
end
|
270
|
-
|
271
|
-
context 'with runtime information' do
|
272
|
-
include_context 'dynamic analysis objects'
|
273
|
-
|
274
|
-
it 'raises ContextError' do
|
275
|
-
-> { method_stub_object.allowize! }.should raise_error(ContextError)
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
|
-
context 'without runtime information' do
|
280
|
-
it 'does not raise ContextError' do
|
281
|
-
-> { method_stub_object.allowize! }.should_not raise_error
|
282
|
-
end
|
283
|
-
end
|
284
|
-
end
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
context 'with expression `obj.stub!(:message)`' do
|
289
|
-
let(:source) do
|
290
|
-
<<-END
|
291
|
-
describe 'example' do
|
292
|
-
it 'responds to #foo' do
|
293
|
-
subject.stub!(:foo)
|
294
|
-
end
|
295
|
-
end
|
296
|
-
END
|
297
|
-
end
|
298
|
-
|
299
|
-
let(:expected_source) do
|
300
|
-
<<-END
|
301
|
-
describe 'example' do
|
302
|
-
it 'responds to #foo' do
|
303
|
-
allow(subject).to receive(:foo)
|
304
|
-
end
|
305
|
-
end
|
306
|
-
END
|
307
|
-
end
|
308
|
-
|
309
|
-
it 'converts to `allow(obj).to receive(:message)` form' do
|
310
|
-
rewritten_source.should == expected_source
|
311
|
-
end
|
312
|
-
|
313
|
-
it 'adds record `obj.stub!(:message)` -> `allow(obj).to receive(:message)`' do
|
314
|
-
record.old_syntax.should == 'obj.stub!(:message)'
|
315
|
-
record.new_syntax.should == 'allow(obj).to receive(:message)'
|
316
|
-
end
|
317
|
-
end
|
318
|
-
|
319
|
-
context 'with expression `obj.stub(:message).and_return(value)`' do
|
320
|
-
let(:source) do
|
321
|
-
<<-END
|
322
|
-
describe 'example' do
|
323
|
-
it 'responds to #foo and returns 1' do
|
324
|
-
subject.stub(:foo).and_return(1)
|
325
|
-
end
|
326
|
-
end
|
327
|
-
END
|
328
|
-
end
|
329
|
-
|
330
|
-
let(:expected_source) do
|
331
|
-
<<-END
|
332
|
-
describe 'example' do
|
333
|
-
it 'responds to #foo and returns 1' do
|
334
|
-
allow(subject).to receive(:foo).and_return(1)
|
335
|
-
end
|
336
|
-
end
|
337
|
-
END
|
338
|
-
end
|
339
|
-
|
340
|
-
it 'converts to `allow(obj).to receive(:message).and_return(value)` form' do
|
341
|
-
rewritten_source.should == expected_source
|
342
|
-
end
|
343
|
-
end
|
344
|
-
|
345
|
-
context 'with expression `obj.stub(:message).and_raise(RuntimeError)`' do
|
346
|
-
let(:source) do
|
347
|
-
<<-END
|
348
|
-
describe 'example' do
|
349
|
-
it 'responds to #foo and raises RuntimeError' do
|
350
|
-
subject.stub(:foo).and_raise(RuntimeError)
|
351
|
-
end
|
352
|
-
end
|
353
|
-
END
|
354
|
-
end
|
355
|
-
|
356
|
-
let(:expected_source) do
|
357
|
-
<<-END
|
358
|
-
describe 'example' do
|
359
|
-
it 'responds to #foo and raises RuntimeError' do
|
360
|
-
allow(subject).to receive(:foo).and_raise(RuntimeError)
|
361
|
-
end
|
362
|
-
end
|
363
|
-
END
|
364
|
-
end
|
365
|
-
|
366
|
-
it 'converts to `allow(obj).to receive(:message).and_raise(RuntimeError)` form' do
|
367
|
-
rewritten_source.should == expected_source
|
368
|
-
end
|
369
|
-
end
|
370
|
-
|
371
|
-
context 'when the statement continues over multi lines' do
|
372
|
-
let(:source) do
|
373
|
-
<<-END
|
374
|
-
describe 'example' do
|
375
|
-
it 'responds to #foo and returns 1' do
|
376
|
-
subject.stub(
|
377
|
-
:foo
|
378
|
-
).
|
379
|
-
and_return(
|
380
|
-
1
|
381
|
-
)
|
382
|
-
end
|
383
|
-
end
|
384
|
-
END
|
385
|
-
end
|
386
|
-
|
387
|
-
let(:expected_source) do
|
388
|
-
<<-END
|
389
|
-
describe 'example' do
|
390
|
-
it 'responds to #foo and returns 1' do
|
391
|
-
allow(subject).to receive(
|
392
|
-
:foo
|
393
|
-
).
|
394
|
-
and_return(
|
395
|
-
1
|
396
|
-
)
|
397
|
-
end
|
398
|
-
end
|
399
|
-
END
|
400
|
-
end
|
401
|
-
|
402
|
-
it 'keeps the style as far as possible' do
|
403
|
-
rewritten_source.should == expected_source
|
404
|
-
end
|
405
|
-
end
|
406
|
-
|
407
|
-
context 'with expression `obj.stub(:message => value)`' do
|
408
|
-
context 'and #receive_messages is available' do
|
409
|
-
# #before here does not work because #allowized! is invoked in super #before.
|
410
|
-
let(:rspec_version) do
|
411
|
-
rspec_version = Transpec.required_rspec_version
|
412
|
-
rspec_version.stub(:receive_messages_available?).and_return(true)
|
413
|
-
rspec_version
|
414
|
-
end
|
415
|
-
|
416
|
-
let(:source) do
|
417
|
-
<<-END
|
418
|
-
describe 'example' do
|
419
|
-
it 'responds to #foo and returns 1' do
|
420
|
-
subject.stub(:foo => 1)
|
421
|
-
end
|
422
|
-
end
|
423
|
-
END
|
424
|
-
end
|
425
|
-
|
426
|
-
let(:expected_source) do
|
427
|
-
<<-END
|
428
|
-
describe 'example' do
|
429
|
-
it 'responds to #foo and returns 1' do
|
430
|
-
allow(subject).to receive_messages(:foo => 1)
|
431
|
-
end
|
432
|
-
end
|
433
|
-
END
|
434
|
-
end
|
435
|
-
|
436
|
-
it 'converts to `allow(obj).to receive_messages(:message => value)` form' do
|
437
|
-
rewritten_source.should == expected_source
|
438
|
-
end
|
439
|
-
|
440
|
-
it 'adds record ' \
|
441
|
-
'`obj.stub(:message => value)` -> `allow(obj).to receive_messages(:message => value)`' do
|
442
|
-
record.old_syntax.should == 'obj.stub(:message => value)'
|
443
|
-
record.new_syntax.should == 'allow(obj).to receive_messages(:message => value)'
|
444
|
-
end
|
445
|
-
end
|
446
|
-
|
447
|
-
context 'and #receive_messages is not available' do
|
448
|
-
let(:source) do
|
449
|
-
<<-END
|
450
|
-
describe 'example' do
|
451
|
-
it 'responds to #foo and returns 1' do
|
452
|
-
subject.stub(:foo => 1)
|
453
|
-
end
|
454
|
-
end
|
455
|
-
END
|
456
|
-
end
|
457
|
-
|
458
|
-
let(:expected_source) do
|
459
|
-
<<-END
|
460
|
-
describe 'example' do
|
461
|
-
it 'responds to #foo and returns 1' do
|
462
|
-
allow(subject).to receive(:foo).and_return(1)
|
463
|
-
end
|
464
|
-
end
|
465
|
-
END
|
466
|
-
end
|
467
|
-
|
468
|
-
it 'converts to `allow(obj).to receive(:message).and_return(value)` form' do
|
469
|
-
rewritten_source.should == expected_source
|
470
|
-
end
|
471
|
-
|
472
|
-
it 'adds record ' \
|
473
|
-
'`obj.stub(:message => value)` -> `allow(obj).to receive(:message).and_return(value)`' do
|
474
|
-
record.old_syntax.should == 'obj.stub(:message => value)'
|
475
|
-
record.new_syntax.should == 'allow(obj).to receive(:message).and_return(value)'
|
476
|
-
end
|
477
|
-
end
|
478
|
-
end
|
479
|
-
|
480
|
-
context 'with expression `obj.stub(method: value)`' do
|
481
|
-
let(:source) do
|
482
|
-
<<-END
|
483
|
-
describe 'example' do
|
484
|
-
it 'responds to #foo and returns 1' do
|
485
|
-
subject.stub(foo: 1)
|
486
|
-
end
|
487
|
-
end
|
488
|
-
END
|
489
|
-
end
|
490
|
-
|
491
|
-
let(:expected_source) do
|
492
|
-
<<-END
|
493
|
-
describe 'example' do
|
494
|
-
it 'responds to #foo and returns 1' do
|
495
|
-
allow(subject).to receive(:foo).and_return(1)
|
496
|
-
end
|
497
|
-
end
|
498
|
-
END
|
499
|
-
end
|
500
|
-
|
501
|
-
it 'converts to `allow(obj).to receive(:message).and_return(value)` form' do
|
502
|
-
rewritten_source.should == expected_source
|
503
|
-
end
|
504
|
-
|
505
|
-
it 'adds record ' \
|
506
|
-
'`obj.stub(:message => value)` -> `allow(obj).to receive(:message).and_return(value)`' do
|
507
|
-
record.old_syntax.should == 'obj.stub(:message => value)'
|
508
|
-
record.new_syntax.should == 'allow(obj).to receive(:message).and_return(value)'
|
509
|
-
end
|
510
|
-
end
|
511
|
-
|
512
|
-
context 'with expression `obj.stub(:a_method => a_value, b_method => b_value)`' do
|
513
|
-
let(:source) do
|
514
|
-
<<-END
|
515
|
-
describe 'example' do
|
516
|
-
it 'responds to #foo and returns 1, and responds to #bar and returns 2' do
|
517
|
-
subject.stub(:foo => 1, :bar => 2)
|
518
|
-
end
|
519
|
-
end
|
520
|
-
END
|
521
|
-
end
|
522
|
-
|
523
|
-
let(:expected_source) do
|
524
|
-
<<-END
|
525
|
-
describe 'example' do
|
526
|
-
it 'responds to #foo and returns 1, and responds to #bar and returns 2' do
|
527
|
-
allow(subject).to receive(:foo).and_return(1)
|
528
|
-
allow(subject).to receive(:bar).and_return(2)
|
529
|
-
end
|
530
|
-
end
|
531
|
-
END
|
532
|
-
end
|
533
|
-
|
534
|
-
it 'converts to `allow(obj).to receive(:a_method).and_return(a_value)` ' \
|
535
|
-
'and `allow(obj).to receive(:b_method).and_return(b_value)`' do
|
536
|
-
rewritten_source.should == expected_source
|
537
|
-
end
|
538
|
-
|
539
|
-
it 'adds record ' \
|
540
|
-
'`obj.stub(:message => value)` -> `allow(obj).to receive(:message).and_return(value)`' do
|
541
|
-
record.old_syntax.should == 'obj.stub(:message => value)'
|
542
|
-
record.new_syntax.should == 'allow(obj).to receive(:message).and_return(value)'
|
543
|
-
end
|
544
|
-
|
545
|
-
context 'when the statement continues over multi lines' do
|
546
|
-
context 'and #receive_messages is available' do
|
547
|
-
# #before here does not work because #allowized! is invoked in super #before.
|
548
|
-
let(:rspec_version) do
|
549
|
-
rspec_version = Transpec.required_rspec_version
|
550
|
-
rspec_version.stub(:receive_messages_available?).and_return(true)
|
551
|
-
rspec_version
|
552
|
-
end
|
553
|
-
|
554
|
-
let(:source) do
|
555
|
-
<<-END
|
556
|
-
describe 'example' do
|
557
|
-
it 'responds to #foo and returns 1, and responds to #bar and returns 2' do
|
558
|
-
subject
|
559
|
-
.stub(
|
560
|
-
:foo => 1,
|
561
|
-
:bar => 2
|
562
|
-
)
|
563
|
-
end
|
564
|
-
end
|
565
|
-
END
|
566
|
-
end
|
567
|
-
|
568
|
-
let(:expected_source) do
|
569
|
-
<<-END
|
570
|
-
describe 'example' do
|
571
|
-
it 'responds to #foo and returns 1, and responds to #bar and returns 2' do
|
572
|
-
allow(subject)
|
573
|
-
.to receive_messages(
|
574
|
-
:foo => 1,
|
575
|
-
:bar => 2
|
576
|
-
)
|
577
|
-
end
|
578
|
-
end
|
579
|
-
END
|
580
|
-
end
|
581
|
-
|
582
|
-
it 'keeps the style' do
|
583
|
-
rewritten_source.should == expected_source
|
584
|
-
end
|
585
|
-
end
|
586
|
-
|
587
|
-
context 'and #receive_messages is not available' do
|
588
|
-
let(:source) do
|
589
|
-
<<-END
|
590
|
-
describe 'example' do
|
591
|
-
it 'responds to #foo and returns 1, and responds to #bar and returns 2' do
|
592
|
-
subject
|
593
|
-
.stub(
|
594
|
-
:foo => 1,
|
595
|
-
:bar => 2
|
596
|
-
)
|
597
|
-
end
|
598
|
-
end
|
599
|
-
END
|
600
|
-
end
|
601
|
-
|
602
|
-
let(:expected_source) do
|
603
|
-
<<-END
|
604
|
-
describe 'example' do
|
605
|
-
it 'responds to #foo and returns 1, and responds to #bar and returns 2' do
|
606
|
-
allow(subject)
|
607
|
-
.to receive(:foo).and_return(1)
|
608
|
-
allow(subject)
|
609
|
-
.to receive(:bar).and_return(2)
|
610
|
-
end
|
611
|
-
end
|
612
|
-
END
|
613
|
-
end
|
614
|
-
|
615
|
-
it 'keeps the style except around the hash' do
|
616
|
-
rewritten_source.should == expected_source
|
617
|
-
end
|
618
|
-
end
|
619
|
-
end
|
620
|
-
end
|
621
|
-
|
622
|
-
context 'with expression `obj.stub_chain(:foo, :bar => value)`' do
|
623
|
-
let(:source) do
|
624
|
-
<<-END
|
625
|
-
describe 'example' do
|
626
|
-
it 'responds to .foo.bar and returns 1' do
|
627
|
-
subject.stub_chain(:foo, :bar => 1)
|
628
|
-
end
|
629
|
-
end
|
630
|
-
END
|
631
|
-
end
|
632
|
-
|
633
|
-
let(:expected_source) do
|
634
|
-
<<-END
|
635
|
-
describe 'example' do
|
636
|
-
it 'responds to .foo.bar and returns 1' do
|
637
|
-
allow(subject).to receive_message_chain(:foo, :bar => 1)
|
638
|
-
end
|
639
|
-
end
|
640
|
-
END
|
641
|
-
end
|
642
|
-
|
643
|
-
context 'and #receive_message_chain is available' do
|
644
|
-
# #before here does not work because #allowized! is invoked in super #before.
|
645
|
-
let(:rspec_version) do
|
646
|
-
rspec_version = Transpec.required_rspec_version
|
647
|
-
rspec_version.stub(:receive_message_chain_available?).and_return(true)
|
648
|
-
rspec_version
|
649
|
-
end
|
650
|
-
|
651
|
-
it 'converts to `allow(obj).to receive_message_chain(:foo, :bar => value)` form' do
|
652
|
-
rewritten_source.should == expected_source
|
653
|
-
end
|
654
|
-
|
655
|
-
it "adds record `obj.stub_chain(:message1, :message2)` -> ' +
|
656
|
-
'`allow(obj).to receive_message_chain(:message1, :message2)`" do
|
657
|
-
record.old_syntax.should == 'obj.stub_chain(:message1, :message2)'
|
658
|
-
record.new_syntax.should == 'allow(obj).to receive_message_chain(:message1, :message2)'
|
659
|
-
end
|
660
|
-
end
|
661
|
-
|
662
|
-
context 'and #receive_message_chain is not available' do
|
663
|
-
it 'does nothing' do
|
664
|
-
rewritten_source.should == source
|
665
|
-
end
|
666
|
-
end
|
667
|
-
end
|
668
|
-
|
669
|
-
[:unstub, :unstub!].each do |method|
|
670
|
-
context "with expression `obj.#{method}(:message)`" do
|
671
|
-
let(:source) do
|
672
|
-
<<-END
|
673
|
-
describe 'example' do
|
674
|
-
it 'does not respond to #foo' do
|
675
|
-
subject.#{method}(:foo)
|
676
|
-
end
|
677
|
-
end
|
678
|
-
END
|
679
|
-
end
|
680
|
-
|
681
|
-
let(:expected_source) do
|
682
|
-
<<-END
|
683
|
-
describe 'example' do
|
684
|
-
it 'does not respond to #foo' do
|
685
|
-
allow(subject).to receive(:foo).and_call_original
|
686
|
-
end
|
687
|
-
end
|
688
|
-
END
|
689
|
-
end
|
690
|
-
|
691
|
-
it 'converts to `allow(subject).to receive(:method).and_call_original`' do
|
692
|
-
rewritten_source.should == expected_source
|
693
|
-
end
|
694
|
-
|
695
|
-
it "adds record `obj.#{method}(:message)` -> `allow(obj).to receive(:message).and_call_original`" do
|
696
|
-
record.old_syntax.should == "obj.#{method}(:message)"
|
697
|
-
record.new_syntax.should == 'allow(obj).to receive(:message).and_call_original'
|
698
|
-
end
|
699
|
-
end
|
700
|
-
end
|
701
|
-
|
702
|
-
context 'with expression `obj.unstub :message`' do
|
703
|
-
let(:source) do
|
704
|
-
<<-END
|
705
|
-
describe 'example' do
|
706
|
-
it 'does not respond to #foo' do
|
707
|
-
subject.unstub :foo
|
708
|
-
end
|
709
|
-
end
|
710
|
-
END
|
711
|
-
end
|
712
|
-
|
713
|
-
let(:expected_source) do
|
714
|
-
<<-END
|
715
|
-
describe 'example' do
|
716
|
-
it 'does not respond to #foo' do
|
717
|
-
allow(subject).to receive(:foo).and_call_original
|
718
|
-
end
|
719
|
-
end
|
720
|
-
END
|
721
|
-
end
|
722
|
-
|
723
|
-
it 'converts to `allow(subject).to receive(:method).and_call_original`' do
|
724
|
-
rewritten_source.should == expected_source
|
725
|
-
end
|
726
|
-
end
|
727
|
-
|
728
|
-
context 'with expression `Klass.any_instance.stub(:message)`' do
|
729
|
-
let(:source) do
|
730
|
-
<<-END
|
731
|
-
describe 'example' do
|
732
|
-
it 'responds to #foo' do
|
733
|
-
Klass.any_instance.stub(:foo)
|
734
|
-
end
|
735
|
-
end
|
736
|
-
END
|
737
|
-
end
|
738
|
-
|
739
|
-
let(:expected_source) do
|
740
|
-
<<-END
|
741
|
-
describe 'example' do
|
742
|
-
it 'responds to #foo' do
|
743
|
-
allow_any_instance_of(Klass).to receive(:foo)
|
744
|
-
end
|
745
|
-
end
|
746
|
-
END
|
747
|
-
end
|
748
|
-
|
749
|
-
it 'converts to `allow_any_instance_of(Klass).to receive(:message)` form' do
|
750
|
-
rewritten_source.should == expected_source
|
751
|
-
end
|
752
|
-
|
753
|
-
it 'adds record `Klass.any_instance.stub(:message)` ' \
|
754
|
-
'-> `allow_any_instance_of(obj).to receive(:message)`' do
|
755
|
-
record.old_syntax.should == 'Klass.any_instance.stub(:message)'
|
756
|
-
record.new_syntax.should == 'allow_any_instance_of(Klass).to receive(:message)'
|
757
|
-
end
|
758
|
-
|
759
|
-
context 'when the statement continues over multi lines' do
|
760
|
-
let(:source) do
|
761
|
-
<<-END
|
762
|
-
describe 'example' do
|
763
|
-
it 'responds to #foo and returns 1' do
|
764
|
-
Klass
|
765
|
-
.any_instance
|
766
|
-
.stub(
|
767
|
-
:foo
|
768
|
-
).
|
769
|
-
and_return(
|
770
|
-
1
|
771
|
-
)
|
772
|
-
end
|
773
|
-
end
|
774
|
-
END
|
775
|
-
end
|
776
|
-
|
777
|
-
let(:expected_source) do
|
778
|
-
<<-END
|
779
|
-
describe 'example' do
|
780
|
-
it 'responds to #foo and returns 1' do
|
781
|
-
allow_any_instance_of(Klass)
|
782
|
-
.to receive(
|
783
|
-
:foo
|
784
|
-
).
|
785
|
-
and_return(
|
786
|
-
1
|
787
|
-
)
|
788
|
-
end
|
789
|
-
end
|
790
|
-
END
|
791
|
-
end
|
792
|
-
|
793
|
-
it 'keeps the style as far as possible' do
|
794
|
-
rewritten_source.should == expected_source
|
795
|
-
end
|
796
|
-
end
|
797
|
-
end
|
798
|
-
|
799
|
-
context 'with expression `described_class.any_instance.stub(:message)`' do
|
800
|
-
let(:source) do
|
801
|
-
<<-END
|
802
|
-
describe 'example' do
|
803
|
-
it 'responds to #foo' do
|
804
|
-
described_class.any_instance.stub(:foo)
|
805
|
-
end
|
806
|
-
end
|
807
|
-
END
|
808
|
-
end
|
809
|
-
|
810
|
-
let(:expected_source) do
|
811
|
-
<<-END
|
812
|
-
describe 'example' do
|
813
|
-
it 'responds to #foo' do
|
814
|
-
allow_any_instance_of(described_class).to receive(:foo)
|
815
|
-
end
|
816
|
-
end
|
817
|
-
END
|
818
|
-
end
|
819
|
-
|
820
|
-
it 'converts to `allow_any_instance_of(described_class).to receive(:message)` form' do
|
821
|
-
rewritten_source.should == expected_source
|
822
|
-
end
|
823
|
-
|
824
|
-
it 'adds record `Klass.any_instance.stub(:message)` ' \
|
825
|
-
'-> `allow_any_instance_of(obj).to receive(:message)`' do
|
826
|
-
record.old_syntax.should == 'Klass.any_instance.stub(:message)'
|
827
|
-
record.new_syntax.should == 'allow_any_instance_of(Klass).to receive(:message)'
|
828
|
-
end
|
829
|
-
end
|
830
|
-
|
831
|
-
context 'with expression `variable.any_instance.stub(:message)` ' \
|
832
|
-
'and the variable is an AnyInstance::Recorder' do
|
833
|
-
context 'with runtime information' do
|
834
|
-
include_context 'dynamic analysis objects'
|
835
|
-
|
836
|
-
let(:source) do
|
837
|
-
<<-END
|
838
|
-
describe 'example' do
|
839
|
-
it 'responds to #foo' do
|
840
|
-
variable = String.any_instance
|
841
|
-
variable.stub(:foo)
|
842
|
-
end
|
843
|
-
end
|
844
|
-
END
|
845
|
-
end
|
846
|
-
|
847
|
-
let(:expected_source) do
|
848
|
-
<<-END
|
849
|
-
describe 'example' do
|
850
|
-
it 'responds to #foo' do
|
851
|
-
variable = String.any_instance
|
852
|
-
allow_any_instance_of(String).to receive(:foo)
|
853
|
-
end
|
854
|
-
end
|
855
|
-
END
|
856
|
-
end
|
857
|
-
|
858
|
-
it 'converts to `allow_any_instance_of(Klass).to receive(:message)` form' do
|
859
|
-
rewritten_source.should == expected_source
|
860
|
-
end
|
861
|
-
|
862
|
-
it 'adds record `Klass.any_instance.stub(:message)` ' \
|
863
|
-
'-> `allow_any_instance_of(obj).to receive(:message)`' do
|
864
|
-
record.old_syntax.should == 'Klass.any_instance.stub(:message)'
|
865
|
-
record.new_syntax.should == 'allow_any_instance_of(Klass).to receive(:message)'
|
866
|
-
end
|
867
|
-
end
|
868
|
-
end
|
869
|
-
|
870
|
-
[:unstub, :unstub!].each do |method|
|
871
|
-
context "with expression `Klass.any_instance.#{method}(:message)`" do
|
872
|
-
let(:source) do
|
873
|
-
<<-END
|
874
|
-
describe 'example' do
|
875
|
-
it 'does not respond to #foo' do
|
876
|
-
Klass.any_instance.#{method}(:foo)
|
877
|
-
end
|
878
|
-
end
|
879
|
-
END
|
880
|
-
end
|
881
|
-
|
882
|
-
let(:expected_source) do
|
883
|
-
<<-END
|
884
|
-
describe 'example' do
|
885
|
-
it 'does not respond to #foo' do
|
886
|
-
allow_any_instance_of(Klass).to receive(:foo).and_call_original
|
887
|
-
end
|
888
|
-
end
|
889
|
-
END
|
890
|
-
end
|
891
|
-
|
892
|
-
it 'converts to `allow(subject).to receive(:method).and_call_original`' do
|
893
|
-
rewritten_source.should == expected_source
|
894
|
-
end
|
895
|
-
|
896
|
-
it "adds record `Klass.any_instance.#{method}(:message)` " \
|
897
|
-
'-> `allow_any_instance_of(Klass).to receive(:message).and_call_original`' do
|
898
|
-
record.old_syntax.should == "Klass.any_instance.#{method}(:message)"
|
899
|
-
record.new_syntax.should == 'allow_any_instance_of(Klass).to receive(:message).and_call_original'
|
900
|
-
end
|
901
|
-
end
|
902
|
-
end
|
903
|
-
end
|
904
|
-
|
905
|
-
describe '#convert_deprecated_method!' do
|
906
|
-
before do
|
907
|
-
method_stub_object.convert_deprecated_method!
|
908
|
-
end
|
909
|
-
|
910
|
-
[
|
911
|
-
[:stub!, :stub, 'responds to'],
|
912
|
-
[:unstub!, :unstub, 'does not respond to']
|
913
|
-
].each do |method, replacement_method, description|
|
914
|
-
context "with expression `obj.#{method}(:message)`" do
|
915
|
-
let(:source) do
|
916
|
-
<<-END
|
917
|
-
describe 'example' do
|
918
|
-
it '#{description} #foo' do
|
919
|
-
subject.#{method}(:foo)
|
920
|
-
end
|
921
|
-
end
|
922
|
-
END
|
923
|
-
end
|
924
|
-
|
925
|
-
let(:expected_source) do
|
926
|
-
<<-END
|
927
|
-
describe 'example' do
|
928
|
-
it '#{description} #foo' do
|
929
|
-
subject.#{replacement_method}(:foo)
|
930
|
-
end
|
931
|
-
end
|
932
|
-
END
|
933
|
-
end
|
934
|
-
|
935
|
-
it "converts to `obj.##{replacement_method}(:message)`" do
|
936
|
-
rewritten_source.should == expected_source
|
937
|
-
end
|
938
|
-
|
939
|
-
it 'adds record ' \
|
940
|
-
"`obj.#{method}(:message)` -> `obj.#{replacement_method}(:message)`" do
|
941
|
-
record.old_syntax.should == "obj.#{method}(:message)"
|
942
|
-
record.new_syntax.should == "obj.#{replacement_method}(:message)"
|
943
|
-
end
|
944
|
-
end
|
945
|
-
end
|
946
|
-
|
947
|
-
[
|
948
|
-
[:stub, 'responds to'],
|
949
|
-
[:unstub, 'does not respond to']
|
950
|
-
].each do |method, description|
|
951
|
-
context "with expression `obj.#{method}(:message)`" do
|
952
|
-
let(:source) do
|
953
|
-
<<-END
|
954
|
-
describe 'example' do
|
955
|
-
it '#{description} #foo' do
|
956
|
-
subject.#{method}(:foo)
|
957
|
-
end
|
958
|
-
end
|
959
|
-
END
|
960
|
-
end
|
961
|
-
|
962
|
-
it 'does nothing' do
|
963
|
-
rewritten_source.should == source
|
964
|
-
end
|
965
|
-
|
966
|
-
it 'reports nothing' do
|
967
|
-
method_stub_object.report.records.should be_empty
|
968
|
-
end
|
969
|
-
end
|
970
|
-
end
|
971
|
-
end
|
972
|
-
|
973
|
-
describe '#allow_no_message?' do
|
974
|
-
subject { method_stub_object.allow_no_message? }
|
975
|
-
|
976
|
-
context 'with expression `obj.stub(:message).any_number_of_times`' do
|
977
|
-
let(:source) do
|
978
|
-
<<-END
|
979
|
-
describe 'example' do
|
980
|
-
it 'responds to #foo' do
|
981
|
-
subject.stub(:foo).any_number_of_times
|
982
|
-
end
|
983
|
-
end
|
984
|
-
END
|
985
|
-
end
|
986
|
-
|
987
|
-
it { should be_true }
|
988
|
-
end
|
989
|
-
|
990
|
-
context 'with expression `obj.stub(:message).with(arg).any_number_of_times`' do
|
991
|
-
let(:source) do
|
992
|
-
<<-END
|
993
|
-
describe 'example' do
|
994
|
-
it 'responds to #foo with 1' do
|
995
|
-
subject.stub(:foo).with(1).any_number_of_times
|
996
|
-
end
|
997
|
-
end
|
998
|
-
END
|
999
|
-
end
|
1000
|
-
|
1001
|
-
it { should be_true }
|
1002
|
-
end
|
1003
|
-
|
1004
|
-
context 'with expression `obj.stub(:message).at_least(0)`' do
|
1005
|
-
let(:source) do
|
1006
|
-
<<-END
|
1007
|
-
describe 'example' do
|
1008
|
-
it 'responds to #foo' do
|
1009
|
-
subject.stub(:foo).at_least(0)
|
1010
|
-
end
|
1011
|
-
end
|
1012
|
-
END
|
1013
|
-
end
|
1014
|
-
|
1015
|
-
it { should be_true }
|
1016
|
-
end
|
1017
|
-
|
1018
|
-
context 'with expression `obj.stub(:message)`' do
|
1019
|
-
let(:source) do
|
1020
|
-
<<-END
|
1021
|
-
describe 'example' do
|
1022
|
-
it 'responds to #foo' do
|
1023
|
-
subject.stub(:foo)
|
1024
|
-
end
|
1025
|
-
end
|
1026
|
-
END
|
1027
|
-
end
|
1028
|
-
|
1029
|
-
it { should be_false }
|
1030
|
-
end
|
1031
|
-
end
|
1032
|
-
|
1033
|
-
describe '#remove_no_message_allowance!' do
|
1034
|
-
before do
|
1035
|
-
method_stub_object.remove_no_message_allowance!
|
1036
|
-
end
|
1037
|
-
|
1038
|
-
context 'with expression `obj.stub(:message).any_number_of_times`' do
|
1039
|
-
let(:source) do
|
1040
|
-
<<-END
|
1041
|
-
describe 'example' do
|
1042
|
-
it 'responds to #foo' do
|
1043
|
-
subject.stub(:foo).any_number_of_times
|
1044
|
-
end
|
1045
|
-
end
|
1046
|
-
END
|
1047
|
-
end
|
1048
|
-
|
1049
|
-
let(:expected_source) do
|
1050
|
-
<<-END
|
1051
|
-
describe 'example' do
|
1052
|
-
it 'responds to #foo' do
|
1053
|
-
subject.stub(:foo)
|
1054
|
-
end
|
1055
|
-
end
|
1056
|
-
END
|
1057
|
-
end
|
1058
|
-
|
1059
|
-
it 'removes `.any_number_of_times`' do
|
1060
|
-
rewritten_source.should == expected_source
|
1061
|
-
end
|
1062
|
-
|
1063
|
-
it 'adds record ' \
|
1064
|
-
'`obj.stub(:message).any_number_of_times` -> `obj.stub(:message)`' do
|
1065
|
-
record.old_syntax.should == 'obj.stub(:message).any_number_of_times'
|
1066
|
-
record.new_syntax.should == 'obj.stub(:message)'
|
1067
|
-
end
|
1068
|
-
end
|
1069
|
-
|
1070
|
-
context 'with expression `obj.stub(:message).at_least(0)`' do
|
1071
|
-
let(:source) do
|
1072
|
-
<<-END
|
1073
|
-
describe 'example' do
|
1074
|
-
it 'responds to #foo' do
|
1075
|
-
subject.stub(:foo).at_least(0)
|
1076
|
-
end
|
1077
|
-
end
|
1078
|
-
END
|
1079
|
-
end
|
1080
|
-
|
1081
|
-
let(:expected_source) do
|
1082
|
-
<<-END
|
1083
|
-
describe 'example' do
|
1084
|
-
it 'responds to #foo' do
|
1085
|
-
subject.stub(:foo)
|
1086
|
-
end
|
1087
|
-
end
|
1088
|
-
END
|
1089
|
-
end
|
1090
|
-
|
1091
|
-
it 'removes `.at_least(0)`' do
|
1092
|
-
rewritten_source.should == expected_source
|
1093
|
-
end
|
1094
|
-
|
1095
|
-
it 'adds record ' \
|
1096
|
-
'`obj.stub(:message).at_least(0)` -> `obj.stub(:message)`' do
|
1097
|
-
record.old_syntax.should == 'obj.stub(:message).at_least(0)'
|
1098
|
-
record.new_syntax.should == 'obj.stub(:message)'
|
1099
|
-
end
|
1100
|
-
end
|
1101
|
-
|
1102
|
-
context 'with expression `obj.stub(:message)`' do
|
1103
|
-
let(:source) do
|
1104
|
-
<<-END
|
1105
|
-
describe 'example' do
|
1106
|
-
it 'responds to #foo' do
|
1107
|
-
subject.stub(:foo)
|
1108
|
-
end
|
1109
|
-
end
|
1110
|
-
END
|
1111
|
-
end
|
1112
|
-
|
1113
|
-
it 'does nothing' do
|
1114
|
-
rewritten_source.should == source
|
1115
|
-
end
|
1116
|
-
end
|
1117
|
-
end
|
1118
|
-
|
1119
|
-
describe '#remove_useless_and_return!' do
|
1120
|
-
before do
|
1121
|
-
method_stub_object.remove_useless_and_return!
|
1122
|
-
end
|
1123
|
-
|
1124
|
-
context 'with expression `obj.stub(:message).and_return { value }`' do
|
1125
|
-
let(:source) do
|
1126
|
-
<<-END
|
1127
|
-
describe 'example' do
|
1128
|
-
it 'responds to #foo and returns 1' do
|
1129
|
-
subject.stub(:foo).and_return { 1 }
|
1130
|
-
end
|
1131
|
-
end
|
1132
|
-
END
|
1133
|
-
end
|
1134
|
-
|
1135
|
-
let(:expected_source) do
|
1136
|
-
<<-END
|
1137
|
-
describe 'example' do
|
1138
|
-
it 'responds to #foo and returns 1' do
|
1139
|
-
subject.stub(:foo) { 1 }
|
1140
|
-
end
|
1141
|
-
end
|
1142
|
-
END
|
1143
|
-
end
|
1144
|
-
|
1145
|
-
it 'converts to `obj.stub(:message) { value }` form' do
|
1146
|
-
rewritten_source.should == expected_source
|
1147
|
-
end
|
1148
|
-
|
1149
|
-
it 'adds record `obj.stub(:message).and_return { value }` -> `obj.stub(:message) { value }`' do
|
1150
|
-
record.old_syntax.should == 'obj.stub(:message).and_return { value }'
|
1151
|
-
record.new_syntax.should == 'obj.stub(:message) { value }'
|
1152
|
-
end
|
1153
|
-
end
|
1154
|
-
|
1155
|
-
context 'with multiline expression `obj.stub(:message)\n.and_return { value }`' do
|
1156
|
-
let(:source) do
|
1157
|
-
<<-END
|
1158
|
-
describe 'example' do
|
1159
|
-
it 'responds to #foo and returns 1' do
|
1160
|
-
subject.stub(:foo)
|
1161
|
-
.and_return { 1 }
|
1162
|
-
end
|
1163
|
-
end
|
1164
|
-
END
|
1165
|
-
end
|
1166
|
-
|
1167
|
-
let(:expected_source) do
|
1168
|
-
<<-END
|
1169
|
-
describe 'example' do
|
1170
|
-
it 'responds to #foo and returns 1' do
|
1171
|
-
subject.stub(:foo) { 1 }
|
1172
|
-
end
|
1173
|
-
end
|
1174
|
-
END
|
1175
|
-
end
|
1176
|
-
|
1177
|
-
it 'converts to `obj.stub(:message) { value }` form' \
|
1178
|
-
'while preventing the block from being interpreted as a hash' do
|
1179
|
-
rewritten_source.should == expected_source
|
1180
|
-
end
|
1181
|
-
end
|
1182
|
-
|
1183
|
-
context 'with multiline expression `obj.stub(:message).\nand_return { value }`' do
|
1184
|
-
let(:source) do
|
1185
|
-
<<-END
|
1186
|
-
describe 'example' do
|
1187
|
-
it 'responds to #foo and returns 1' do
|
1188
|
-
subject.stub(:foo).
|
1189
|
-
and_return { 1 }
|
1190
|
-
end
|
1191
|
-
end
|
1192
|
-
END
|
1193
|
-
end
|
1194
|
-
|
1195
|
-
let(:expected_source) do
|
1196
|
-
<<-END
|
1197
|
-
describe 'example' do
|
1198
|
-
it 'responds to #foo and returns 1' do
|
1199
|
-
subject.stub(:foo) { 1 }
|
1200
|
-
end
|
1201
|
-
end
|
1202
|
-
END
|
1203
|
-
end
|
1204
|
-
|
1205
|
-
it 'converts to `obj.stub(:message) { value }` form' \
|
1206
|
-
'while preventing the block from being interpreted as a hash' do
|
1207
|
-
rewritten_source.should == expected_source
|
1208
|
-
end
|
1209
|
-
end
|
1210
|
-
|
1211
|
-
context 'with expression `obj.stub(:message).and_return`' do
|
1212
|
-
let(:source) do
|
1213
|
-
<<-END
|
1214
|
-
describe 'example' do
|
1215
|
-
it 'responds to #foo' do
|
1216
|
-
subject.stub(:foo).and_return
|
1217
|
-
end
|
1218
|
-
end
|
1219
|
-
END
|
1220
|
-
end
|
1221
|
-
|
1222
|
-
let(:expected_source) do
|
1223
|
-
<<-END
|
1224
|
-
describe 'example' do
|
1225
|
-
it 'responds to #foo' do
|
1226
|
-
subject.stub(:foo)
|
1227
|
-
end
|
1228
|
-
end
|
1229
|
-
END
|
1230
|
-
end
|
1231
|
-
|
1232
|
-
it 'converts to `obj.stub(:message)` form' do
|
1233
|
-
rewritten_source.should == expected_source
|
1234
|
-
end
|
1235
|
-
|
1236
|
-
it 'adds record `obj.stub(:message).and_return` -> `obj.stub(:message)`' do
|
1237
|
-
record.old_syntax.should == 'obj.stub(:message).and_return'
|
1238
|
-
record.new_syntax.should == 'obj.stub(:message)'
|
1239
|
-
end
|
1240
|
-
end
|
1241
|
-
|
1242
|
-
context 'with expression `obj.stub(:message).and_return(value)`' do
|
1243
|
-
let(:source) do
|
1244
|
-
<<-END
|
1245
|
-
describe 'example' do
|
1246
|
-
it 'responds to #foo and returns 1' do
|
1247
|
-
subject.stub(:foo).and_return(1)
|
1248
|
-
end
|
1249
|
-
end
|
1250
|
-
END
|
1251
|
-
end
|
1252
|
-
|
1253
|
-
it 'does nothing' do
|
1254
|
-
rewritten_source.should == source
|
1255
|
-
record.should be_nil
|
1256
|
-
end
|
1257
|
-
end
|
1258
|
-
end
|
1259
|
-
|
1260
|
-
describe '#add_receiver_arg_to_any_instance_implementation_block!' do
|
1261
|
-
before do
|
1262
|
-
method_stub_object.add_receiver_arg_to_any_instance_implementation_block!
|
1263
|
-
end
|
1264
|
-
|
1265
|
-
context 'with expression `Klass.any_instance.stub(:message) do |arg| .. end`' do
|
1266
|
-
let(:source) do
|
1267
|
-
<<-END
|
1268
|
-
describe 'example' do
|
1269
|
-
it 'responds to #foo' do
|
1270
|
-
Klass.any_instance.stub(:foo) do |arg|
|
1271
|
-
end
|
1272
|
-
end
|
1273
|
-
end
|
1274
|
-
END
|
1275
|
-
end
|
1276
|
-
|
1277
|
-
let(:expected_source) do
|
1278
|
-
<<-END
|
1279
|
-
describe 'example' do
|
1280
|
-
it 'responds to #foo' do
|
1281
|
-
Klass.any_instance.stub(:foo) do |instance, arg|
|
1282
|
-
end
|
1283
|
-
end
|
1284
|
-
end
|
1285
|
-
END
|
1286
|
-
end
|
1287
|
-
|
1288
|
-
it 'converts to `Klass.any_instance.stub(:message) do |instance, arg| .. end` form' do
|
1289
|
-
rewritten_source.should == expected_source
|
1290
|
-
end
|
1291
|
-
|
1292
|
-
it 'adds record `Klass.any_instance.stub(:message) { |arg| }` ' \
|
1293
|
-
'-> `Klass.any_instance.stub(:message) { |instance, arg| }`' do
|
1294
|
-
record.old_syntax.should == 'Klass.any_instance.stub(:message) { |arg| }'
|
1295
|
-
record.new_syntax.should == 'Klass.any_instance.stub(:message) { |instance, arg| }'
|
1296
|
-
end
|
1297
|
-
end
|
1298
|
-
end
|
1299
|
-
end
|
1300
|
-
end
|
1301
|
-
end
|