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,871 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'transpec/syntax/operator'
|
5
|
-
require 'transpec/syntax/should'
|
6
|
-
|
7
|
-
module Transpec
|
8
|
-
class Syntax
|
9
|
-
describe Operator do
|
10
|
-
include ::AST::Sexp
|
11
|
-
include_context 'parsed objects'
|
12
|
-
include_context 'syntax object', Should, :should_object
|
13
|
-
|
14
|
-
subject(:matcher) { should_object.operator_matcher }
|
15
|
-
let(:record) { matcher.report.records.first }
|
16
|
-
|
17
|
-
describe '#method_name' do
|
18
|
-
let(:source) do
|
19
|
-
<<-END
|
20
|
-
describe 'example' do
|
21
|
-
it 'is 1' do
|
22
|
-
subject.should == 1
|
23
|
-
end
|
24
|
-
end
|
25
|
-
END
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'returns the method name' do
|
29
|
-
matcher.method_name.should == :==
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '#convert_operator!' do
|
34
|
-
before do
|
35
|
-
matcher.convert_operator!(parenthesize_arg)
|
36
|
-
end
|
37
|
-
|
38
|
-
let(:parenthesize_arg) { true }
|
39
|
-
|
40
|
-
context 'with expression `== 1`' do
|
41
|
-
let(:source) do
|
42
|
-
<<-END
|
43
|
-
describe 'example' do
|
44
|
-
it 'is 1' do
|
45
|
-
subject.should == 1
|
46
|
-
end
|
47
|
-
end
|
48
|
-
END
|
49
|
-
end
|
50
|
-
|
51
|
-
let(:expected_source) do
|
52
|
-
<<-END
|
53
|
-
describe 'example' do
|
54
|
-
it 'is 1' do
|
55
|
-
subject.should eq(1)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
END
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'converts to `eq(1)` form' do
|
62
|
-
rewritten_source.should == expected_source
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'adds record `== expected` -> `eq(expected)`' do
|
66
|
-
record.old_syntax.should == '== expected'
|
67
|
-
record.new_syntax.should == 'eq(expected)'
|
68
|
-
record.annotation.should be_nil
|
69
|
-
end
|
70
|
-
|
71
|
-
# Operator methods allow their argument to be in the next line,
|
72
|
-
# but non-operator methods do not.
|
73
|
-
#
|
74
|
-
# [1] pry(main)> 1 ==
|
75
|
-
# [1] pry(main)* 1
|
76
|
-
# => true
|
77
|
-
# [2] pry(main)> 1.eql?
|
78
|
-
# ArgumentError: wrong number of arguments (0 for 1)
|
79
|
-
context 'and its argument is in the next line' do
|
80
|
-
let(:source) do
|
81
|
-
<<-END
|
82
|
-
describe 'example' do
|
83
|
-
it 'is 1' do
|
84
|
-
subject.should ==
|
85
|
-
1
|
86
|
-
end
|
87
|
-
end
|
88
|
-
END
|
89
|
-
end
|
90
|
-
|
91
|
-
let(:expected_source) do
|
92
|
-
<<-END
|
93
|
-
describe 'example' do
|
94
|
-
it 'is 1' do
|
95
|
-
subject.should eq(
|
96
|
-
1
|
97
|
-
)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
END
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'inserts parentheses properly' do
|
104
|
-
rewritten_source.should == expected_source
|
105
|
-
end
|
106
|
-
|
107
|
-
context 'and false is passed as `parenthesize_arg` argument' do
|
108
|
-
let(:parenthesize_arg) { false }
|
109
|
-
|
110
|
-
it 'inserts parentheses properly because they are necessary' do
|
111
|
-
rewritten_source.should == expected_source
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
context 'with expression `==1`' do
|
118
|
-
let(:source) do
|
119
|
-
<<-END
|
120
|
-
describe 'example' do
|
121
|
-
it 'is 1' do
|
122
|
-
subject.should==1
|
123
|
-
end
|
124
|
-
end
|
125
|
-
END
|
126
|
-
end
|
127
|
-
|
128
|
-
let(:expected_source) do
|
129
|
-
<<-END
|
130
|
-
describe 'example' do
|
131
|
-
it 'is 1' do
|
132
|
-
subject.should eq(1)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
END
|
136
|
-
end
|
137
|
-
|
138
|
-
it 'converts to `eq(1)` form' do
|
139
|
-
rewritten_source.should == expected_source
|
140
|
-
end
|
141
|
-
|
142
|
-
context 'and false is passed as `parenthesize_arg` argument' do
|
143
|
-
let(:parenthesize_arg) { false }
|
144
|
-
|
145
|
-
let(:expected_source) do
|
146
|
-
<<-END
|
147
|
-
describe 'example' do
|
148
|
-
it 'is 1' do
|
149
|
-
subject.should eq 1
|
150
|
-
end
|
151
|
-
end
|
152
|
-
END
|
153
|
-
end
|
154
|
-
|
155
|
-
it 'converts to `eq 1` form' do
|
156
|
-
rewritten_source.should == expected_source
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
context 'with expression `be == 1`' do
|
162
|
-
let(:source) do
|
163
|
-
<<-END
|
164
|
-
describe 'example' do
|
165
|
-
it 'is 1' do
|
166
|
-
subject.should be == 1
|
167
|
-
end
|
168
|
-
end
|
169
|
-
END
|
170
|
-
end
|
171
|
-
|
172
|
-
let(:expected_source) do
|
173
|
-
<<-END
|
174
|
-
describe 'example' do
|
175
|
-
it 'is 1' do
|
176
|
-
subject.should eq(1)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
END
|
180
|
-
end
|
181
|
-
|
182
|
-
it 'converts to `eq(1)` form' do
|
183
|
-
rewritten_source.should == expected_source
|
184
|
-
end
|
185
|
-
|
186
|
-
it 'adds record `== expected` -> `eq(expected)`' do
|
187
|
-
record.old_syntax.should == '== expected'
|
188
|
-
record.new_syntax.should == 'eq(expected)'
|
189
|
-
record.annotation.should be_nil
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
context 'with expression `be.==(1)`' do
|
194
|
-
let(:source) do
|
195
|
-
<<-END
|
196
|
-
describe 'example' do
|
197
|
-
it 'is 1' do
|
198
|
-
subject.should be.==(1)
|
199
|
-
end
|
200
|
-
end
|
201
|
-
END
|
202
|
-
end
|
203
|
-
|
204
|
-
let(:expected_source) do
|
205
|
-
<<-END
|
206
|
-
describe 'example' do
|
207
|
-
it 'is 1' do
|
208
|
-
subject.should eq(1)
|
209
|
-
end
|
210
|
-
end
|
211
|
-
END
|
212
|
-
end
|
213
|
-
|
214
|
-
it 'converts to `eq(1)` form' do
|
215
|
-
rewritten_source.should == expected_source
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
context 'with expression `== (2 - 1)`' do
|
220
|
-
let(:source) do
|
221
|
-
<<-END
|
222
|
-
describe 'example' do
|
223
|
-
it 'is 1' do
|
224
|
-
subject.should == (2 - 1)
|
225
|
-
end
|
226
|
-
end
|
227
|
-
END
|
228
|
-
end
|
229
|
-
|
230
|
-
let(:expected_source) do
|
231
|
-
<<-END
|
232
|
-
describe 'example' do
|
233
|
-
it 'is 1' do
|
234
|
-
subject.should eq(2 - 1)
|
235
|
-
end
|
236
|
-
end
|
237
|
-
END
|
238
|
-
end
|
239
|
-
|
240
|
-
it 'converts to `eq(2 - 1)` form without superfluous parentheses' do
|
241
|
-
rewritten_source.should == expected_source
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
context 'with expression `== (5 - 3) / (4 - 2)`' do
|
246
|
-
let(:source) do
|
247
|
-
<<-END
|
248
|
-
describe 'example' do
|
249
|
-
it 'is 1' do
|
250
|
-
subject.should == (5 - 3) / (4 - 2)
|
251
|
-
end
|
252
|
-
end
|
253
|
-
END
|
254
|
-
end
|
255
|
-
|
256
|
-
let(:expected_source) do
|
257
|
-
<<-END
|
258
|
-
describe 'example' do
|
259
|
-
it 'is 1' do
|
260
|
-
subject.should eq((5 - 3) / (4 - 2))
|
261
|
-
end
|
262
|
-
end
|
263
|
-
END
|
264
|
-
end
|
265
|
-
|
266
|
-
it 'converts to `eq((5 - 3) / (4 - 2))` form' do
|
267
|
-
rewritten_source.should == expected_source
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
context "with expression `== { 'key' => 'value' }`" do
|
272
|
-
let(:source) do
|
273
|
-
<<-END
|
274
|
-
describe 'example' do
|
275
|
-
it 'is the hash' do
|
276
|
-
subject.should == { 'key' => 'value' }
|
277
|
-
end
|
278
|
-
end
|
279
|
-
END
|
280
|
-
end
|
281
|
-
|
282
|
-
let(:expected_source) do
|
283
|
-
<<-END
|
284
|
-
describe 'example' do
|
285
|
-
it 'is the hash' do
|
286
|
-
subject.should eq({ 'key' => 'value' })
|
287
|
-
end
|
288
|
-
end
|
289
|
-
END
|
290
|
-
end
|
291
|
-
|
292
|
-
it "converts to `eq({ 'key' => 'value' })` form" do
|
293
|
-
rewritten_source.should == expected_source
|
294
|
-
end
|
295
|
-
|
296
|
-
context 'and false is passed as `parenthesize_arg` argument' do
|
297
|
-
let(:parenthesize_arg) { false }
|
298
|
-
|
299
|
-
it 'inserts parentheses to avoid the hash from be interpreted as a block' do
|
300
|
-
rewritten_source.should == expected_source
|
301
|
-
end
|
302
|
-
end
|
303
|
-
end
|
304
|
-
|
305
|
-
[
|
306
|
-
[:===, 'case-equals to'],
|
307
|
-
[:<, 'is less than'],
|
308
|
-
[:<=, 'is less than or equals to'],
|
309
|
-
[:>, 'is greater than'],
|
310
|
-
[:>=, 'is greater than or equals to']
|
311
|
-
].each do |operator, description|
|
312
|
-
context "with expression `#{operator} 1`" do
|
313
|
-
let(:source) do
|
314
|
-
<<-END
|
315
|
-
describe 'example' do
|
316
|
-
it '#{description} 1' do
|
317
|
-
subject.should #{operator} 1
|
318
|
-
end
|
319
|
-
end
|
320
|
-
END
|
321
|
-
end
|
322
|
-
|
323
|
-
let(:expected_source) do
|
324
|
-
<<-END
|
325
|
-
describe 'example' do
|
326
|
-
it '#{description} 1' do
|
327
|
-
subject.should be #{operator} 1
|
328
|
-
end
|
329
|
-
end
|
330
|
-
END
|
331
|
-
end
|
332
|
-
|
333
|
-
it "converts to `be #{operator} 1` form" do
|
334
|
-
rewritten_source.should == expected_source
|
335
|
-
end
|
336
|
-
|
337
|
-
it "adds record `#{operator} expected` -> `be #{operator} expected`" do
|
338
|
-
record.old_syntax.should == "#{operator} expected"
|
339
|
-
record.new_syntax.should == "be #{operator} expected"
|
340
|
-
record.annotation.should be_nil
|
341
|
-
end
|
342
|
-
end
|
343
|
-
|
344
|
-
context "with expression `be #{operator} 1`" do
|
345
|
-
let(:source) do
|
346
|
-
<<-END
|
347
|
-
describe 'example' do
|
348
|
-
it '#{description} 1' do
|
349
|
-
subject.should be #{operator} 1
|
350
|
-
end
|
351
|
-
end
|
352
|
-
END
|
353
|
-
end
|
354
|
-
|
355
|
-
it 'does nothing' do
|
356
|
-
rewritten_source.should == source
|
357
|
-
end
|
358
|
-
|
359
|
-
it 'reports nothing' do
|
360
|
-
matcher.report.records.should be_empty
|
361
|
-
end
|
362
|
-
end
|
363
|
-
end
|
364
|
-
|
365
|
-
context 'with expression `=~ /pattern/`' do
|
366
|
-
let(:source) do
|
367
|
-
<<-END
|
368
|
-
describe 'example' do
|
369
|
-
it 'matches the pattern' do
|
370
|
-
subject.should =~ /pattern/
|
371
|
-
end
|
372
|
-
end
|
373
|
-
END
|
374
|
-
end
|
375
|
-
|
376
|
-
let(:expected_source) do
|
377
|
-
<<-END
|
378
|
-
describe 'example' do
|
379
|
-
it 'matches the pattern' do
|
380
|
-
subject.should match(/pattern/)
|
381
|
-
end
|
382
|
-
end
|
383
|
-
END
|
384
|
-
end
|
385
|
-
|
386
|
-
it 'converts to `match(/pattern/)` form' do
|
387
|
-
rewritten_source.should == expected_source
|
388
|
-
end
|
389
|
-
|
390
|
-
it 'adds record `=~ /pattern/` -> `match(/pattern/)` without annotation' do
|
391
|
-
record.old_syntax.should == '=~ /pattern/'
|
392
|
-
record.new_syntax.should == 'match(/pattern/)'
|
393
|
-
record.annotation.should be_nil
|
394
|
-
end
|
395
|
-
end
|
396
|
-
|
397
|
-
context 'with expression `=~/pattern/`' do
|
398
|
-
let(:source) do
|
399
|
-
<<-END
|
400
|
-
describe 'example' do
|
401
|
-
it 'matches the pattern' do
|
402
|
-
subject.should=~/pattern/
|
403
|
-
end
|
404
|
-
end
|
405
|
-
END
|
406
|
-
end
|
407
|
-
|
408
|
-
let(:expected_source) do
|
409
|
-
<<-END
|
410
|
-
describe 'example' do
|
411
|
-
it 'matches the pattern' do
|
412
|
-
subject.should match(/pattern/)
|
413
|
-
end
|
414
|
-
end
|
415
|
-
END
|
416
|
-
end
|
417
|
-
|
418
|
-
it 'converts to `match(/pattern/)` form' do
|
419
|
-
rewritten_source.should == expected_source
|
420
|
-
end
|
421
|
-
end
|
422
|
-
|
423
|
-
context 'with expression `be =~ /pattern/`' do
|
424
|
-
let(:source) do
|
425
|
-
<<-END
|
426
|
-
describe 'example' do
|
427
|
-
it 'matches the pattern' do
|
428
|
-
subject.should be =~ /pattern/
|
429
|
-
end
|
430
|
-
end
|
431
|
-
END
|
432
|
-
end
|
433
|
-
|
434
|
-
let(:expected_source) do
|
435
|
-
<<-END
|
436
|
-
describe 'example' do
|
437
|
-
it 'matches the pattern' do
|
438
|
-
subject.should match(/pattern/)
|
439
|
-
end
|
440
|
-
end
|
441
|
-
END
|
442
|
-
end
|
443
|
-
|
444
|
-
it 'converts to `match(/pattern/)` form' do
|
445
|
-
rewritten_source.should == expected_source
|
446
|
-
end
|
447
|
-
end
|
448
|
-
|
449
|
-
context 'with expression `=~ [1, 2]`' do
|
450
|
-
let(:source) do
|
451
|
-
<<-END
|
452
|
-
describe 'example' do
|
453
|
-
it 'contains 1 and 2' do
|
454
|
-
subject.should =~ [1, 2]
|
455
|
-
end
|
456
|
-
end
|
457
|
-
END
|
458
|
-
end
|
459
|
-
|
460
|
-
let(:expected_source) do
|
461
|
-
<<-END
|
462
|
-
describe 'example' do
|
463
|
-
it 'contains 1 and 2' do
|
464
|
-
subject.should match_array([1, 2])
|
465
|
-
end
|
466
|
-
end
|
467
|
-
END
|
468
|
-
end
|
469
|
-
|
470
|
-
it 'converts to `match_array([1, 2])` form' do
|
471
|
-
rewritten_source.should == expected_source
|
472
|
-
end
|
473
|
-
|
474
|
-
it 'adds record `=~ [1, 2]` -> `match_array([1, 2])` without annotation' do
|
475
|
-
record.old_syntax.should == '=~ [1, 2]'
|
476
|
-
record.new_syntax.should == 'match_array([1, 2])'
|
477
|
-
record.annotation.should be_nil
|
478
|
-
end
|
479
|
-
end
|
480
|
-
|
481
|
-
context 'with expression `=~[1, 2]`' do
|
482
|
-
let(:source) do
|
483
|
-
<<-END
|
484
|
-
describe 'example' do
|
485
|
-
it 'contains 1 and 2' do
|
486
|
-
subject.should=~[1, 2]
|
487
|
-
end
|
488
|
-
end
|
489
|
-
END
|
490
|
-
end
|
491
|
-
|
492
|
-
let(:expected_source) do
|
493
|
-
<<-END
|
494
|
-
describe 'example' do
|
495
|
-
it 'contains 1 and 2' do
|
496
|
-
subject.should match_array([1, 2])
|
497
|
-
end
|
498
|
-
end
|
499
|
-
END
|
500
|
-
end
|
501
|
-
|
502
|
-
it 'converts to `match_array([1, 2])` form' do
|
503
|
-
rewritten_source.should == expected_source
|
504
|
-
end
|
505
|
-
end
|
506
|
-
|
507
|
-
context 'with expression `be =~ [1, 2]`' do
|
508
|
-
let(:source) do
|
509
|
-
<<-END
|
510
|
-
describe 'example' do
|
511
|
-
it 'contains 1 and 2' do
|
512
|
-
subject.should be =~ [1, 2]
|
513
|
-
end
|
514
|
-
end
|
515
|
-
END
|
516
|
-
end
|
517
|
-
|
518
|
-
let(:expected_source) do
|
519
|
-
<<-END
|
520
|
-
describe 'example' do
|
521
|
-
it 'contains 1 and 2' do
|
522
|
-
subject.should match_array([1, 2])
|
523
|
-
end
|
524
|
-
end
|
525
|
-
END
|
526
|
-
end
|
527
|
-
|
528
|
-
it 'converts to `match_array([1, 2])` form' do
|
529
|
-
rewritten_source.should == expected_source
|
530
|
-
end
|
531
|
-
end
|
532
|
-
|
533
|
-
context 'with expression `=~ variable`' do
|
534
|
-
context 'and runtime type of the variable is array' do
|
535
|
-
include_context 'dynamic analysis objects'
|
536
|
-
|
537
|
-
let(:source) do
|
538
|
-
<<-END
|
539
|
-
describe 'example' do
|
540
|
-
it 'contains 1 and 2' do
|
541
|
-
variable = [1, 2]
|
542
|
-
[2, 1].should =~ variable
|
543
|
-
end
|
544
|
-
end
|
545
|
-
END
|
546
|
-
end
|
547
|
-
|
548
|
-
let(:expected_source) do
|
549
|
-
<<-END
|
550
|
-
describe 'example' do
|
551
|
-
it 'contains 1 and 2' do
|
552
|
-
variable = [1, 2]
|
553
|
-
[2, 1].should match_array(variable)
|
554
|
-
end
|
555
|
-
end
|
556
|
-
END
|
557
|
-
end
|
558
|
-
|
559
|
-
it 'converts to `match_array(variable)` form' do
|
560
|
-
rewritten_source.should == expected_source
|
561
|
-
end
|
562
|
-
|
563
|
-
it 'adds record `=~ [1, 2]` -> `match_array([1, 2])` without annotation' do
|
564
|
-
record.old_syntax.should == '=~ [1, 2]'
|
565
|
-
record.new_syntax.should == 'match_array([1, 2])'
|
566
|
-
record.annotation.should be_nil
|
567
|
-
end
|
568
|
-
end
|
569
|
-
|
570
|
-
context 'and runtime type of the variable is regular expression' do
|
571
|
-
include_context 'dynamic analysis objects'
|
572
|
-
|
573
|
-
let(:source) do
|
574
|
-
<<-END
|
575
|
-
describe 'example' do
|
576
|
-
it 'matches to the pattern' do
|
577
|
-
variable = /^str/
|
578
|
-
'string'.should =~ variable
|
579
|
-
end
|
580
|
-
end
|
581
|
-
END
|
582
|
-
end
|
583
|
-
|
584
|
-
let(:expected_source) do
|
585
|
-
<<-END
|
586
|
-
describe 'example' do
|
587
|
-
it 'matches to the pattern' do
|
588
|
-
variable = /^str/
|
589
|
-
'string'.should match(variable)
|
590
|
-
end
|
591
|
-
end
|
592
|
-
END
|
593
|
-
end
|
594
|
-
|
595
|
-
it 'converts to `match(variable)` form' do
|
596
|
-
rewritten_source.should == expected_source
|
597
|
-
end
|
598
|
-
|
599
|
-
it 'adds record `=~ /pattern/` -> `match(/pattern/)` without annotation' do
|
600
|
-
record.old_syntax.should == '=~ /pattern/'
|
601
|
-
record.new_syntax.should == 'match(/pattern/)'
|
602
|
-
record.annotation.should be_nil
|
603
|
-
end
|
604
|
-
end
|
605
|
-
|
606
|
-
context 'and no runtime type information is provided' do
|
607
|
-
let(:source) do
|
608
|
-
<<-END
|
609
|
-
describe 'example' do
|
610
|
-
it 'matches the pattern' do
|
611
|
-
subject.should =~ variable
|
612
|
-
end
|
613
|
-
end
|
614
|
-
END
|
615
|
-
end
|
616
|
-
|
617
|
-
let(:expected_source) do
|
618
|
-
<<-END
|
619
|
-
describe 'example' do
|
620
|
-
it 'matches the pattern' do
|
621
|
-
subject.should match(variable)
|
622
|
-
end
|
623
|
-
end
|
624
|
-
END
|
625
|
-
end
|
626
|
-
|
627
|
-
it 'converts to `match(variable)` form' do
|
628
|
-
rewritten_source.should == expected_source
|
629
|
-
end
|
630
|
-
|
631
|
-
it 'adds record `=~ /pattern/` -> `match(/pattern/)` with annotation' do
|
632
|
-
record.old_syntax.should == '=~ /pattern/'
|
633
|
-
record.new_syntax.should == 'match(/pattern/)'
|
634
|
-
|
635
|
-
record.annotation.message.should ==
|
636
|
-
'The `=~ variable` has been converted but it might possibly be incorrect ' \
|
637
|
-
"due to a lack of runtime information. It's recommended to review the change carefully."
|
638
|
-
record.annotation.source_range.source.should == '=~ variable'
|
639
|
-
end
|
640
|
-
end
|
641
|
-
end
|
642
|
-
|
643
|
-
context 'with expression `be =~ variable`' do
|
644
|
-
context 'and no runtime type information is provided' do
|
645
|
-
let(:source) do
|
646
|
-
<<-END
|
647
|
-
describe 'example' do
|
648
|
-
it 'matches the pattern' do
|
649
|
-
subject.should be =~ variable
|
650
|
-
end
|
651
|
-
end
|
652
|
-
END
|
653
|
-
end
|
654
|
-
|
655
|
-
let(:expected_source) do
|
656
|
-
<<-END
|
657
|
-
describe 'example' do
|
658
|
-
it 'matches the pattern' do
|
659
|
-
subject.should match(variable)
|
660
|
-
end
|
661
|
-
end
|
662
|
-
END
|
663
|
-
end
|
664
|
-
|
665
|
-
it 'converts to `match(variable)` form' do
|
666
|
-
rewritten_source.should == expected_source
|
667
|
-
end
|
668
|
-
|
669
|
-
it 'adds record `=~ /pattern/` -> `match(/pattern/)` with annotation' do
|
670
|
-
record.old_syntax.should == '=~ /pattern/'
|
671
|
-
record.new_syntax.should == 'match(/pattern/)'
|
672
|
-
|
673
|
-
record.annotation.message.should ==
|
674
|
-
'The `be =~ variable` has been converted but it might possibly be incorrect ' \
|
675
|
-
"due to a lack of runtime information. It's recommended to review the change carefully."
|
676
|
-
record.annotation.source_range.source.should == 'be =~ variable'
|
677
|
-
end
|
678
|
-
end
|
679
|
-
end
|
680
|
-
end
|
681
|
-
|
682
|
-
describe '#parenthesize!' do
|
683
|
-
before do
|
684
|
-
matcher.parenthesize!(always)
|
685
|
-
end
|
686
|
-
|
687
|
-
let(:always) { true }
|
688
|
-
|
689
|
-
context 'when its argument is already in parentheses' do
|
690
|
-
let(:source) do
|
691
|
-
<<-END
|
692
|
-
describe 'example' do
|
693
|
-
it 'is 1' do
|
694
|
-
subject.should ==(1)
|
695
|
-
end
|
696
|
-
end
|
697
|
-
END
|
698
|
-
end
|
699
|
-
|
700
|
-
it 'does nothing' do
|
701
|
-
rewritten_source.should == source
|
702
|
-
end
|
703
|
-
end
|
704
|
-
|
705
|
-
context 'when its argument is not in parentheses' do
|
706
|
-
let(:source) do
|
707
|
-
<<-END
|
708
|
-
describe 'example' do
|
709
|
-
it 'is 1' do
|
710
|
-
subject.should == 1
|
711
|
-
end
|
712
|
-
end
|
713
|
-
END
|
714
|
-
end
|
715
|
-
|
716
|
-
context 'and true is passed as `always` argument' do
|
717
|
-
let(:always) { true }
|
718
|
-
|
719
|
-
let(:expected_source) do
|
720
|
-
<<-END
|
721
|
-
describe 'example' do
|
722
|
-
it 'is 1' do
|
723
|
-
subject.should ==(1)
|
724
|
-
end
|
725
|
-
end
|
726
|
-
END
|
727
|
-
end
|
728
|
-
|
729
|
-
it 'inserts parentheses' do
|
730
|
-
rewritten_source.should == expected_source
|
731
|
-
end
|
732
|
-
end
|
733
|
-
|
734
|
-
context 'and false is passed as `always` argument' do
|
735
|
-
let(:always) { false }
|
736
|
-
|
737
|
-
let(:expected_source) do
|
738
|
-
<<-END
|
739
|
-
describe 'example' do
|
740
|
-
it 'is 1' do
|
741
|
-
subject.should == 1
|
742
|
-
end
|
743
|
-
end
|
744
|
-
END
|
745
|
-
end
|
746
|
-
|
747
|
-
it 'does not nothing' do
|
748
|
-
rewritten_source.should == expected_source
|
749
|
-
end
|
750
|
-
end
|
751
|
-
end
|
752
|
-
|
753
|
-
context 'when its argument is a string literal' do
|
754
|
-
let(:source) do
|
755
|
-
<<-END
|
756
|
-
describe 'example' do
|
757
|
-
it "is 'string'" do
|
758
|
-
subject.should == 'string'
|
759
|
-
end
|
760
|
-
end
|
761
|
-
END
|
762
|
-
end
|
763
|
-
|
764
|
-
let(:expected_source) do
|
765
|
-
<<-END
|
766
|
-
describe 'example' do
|
767
|
-
it "is 'string'" do
|
768
|
-
subject.should ==('string')
|
769
|
-
end
|
770
|
-
end
|
771
|
-
END
|
772
|
-
end
|
773
|
-
|
774
|
-
it 'inserts parentheses' do
|
775
|
-
rewritten_source.should == expected_source
|
776
|
-
end
|
777
|
-
end
|
778
|
-
|
779
|
-
context 'when its argument is a here document' do
|
780
|
-
let(:source) do
|
781
|
-
<<-END
|
782
|
-
describe 'example' do
|
783
|
-
it 'returns the document' do
|
784
|
-
subject.should == <<-HEREDOC
|
785
|
-
foo
|
786
|
-
HEREDOC
|
787
|
-
end
|
788
|
-
end
|
789
|
-
END
|
790
|
-
end
|
791
|
-
|
792
|
-
# (block
|
793
|
-
# (send nil :it
|
794
|
-
# (str "returns the document"))
|
795
|
-
# (args)
|
796
|
-
# (send
|
797
|
-
# (send nil :subject) :should
|
798
|
-
# (send nil :eq
|
799
|
-
# (str " foo\n"))))
|
800
|
-
|
801
|
-
it 'does nothing' do
|
802
|
-
rewritten_source.should == source
|
803
|
-
end
|
804
|
-
end
|
805
|
-
|
806
|
-
context 'when its argument is a here document with chained method' do
|
807
|
-
let(:source) do
|
808
|
-
<<-END
|
809
|
-
describe 'example' do
|
810
|
-
it 'returns the document' do
|
811
|
-
subject.should == <<-HEREDOC.gsub('foo', 'bar')
|
812
|
-
foo
|
813
|
-
HEREDOC
|
814
|
-
end
|
815
|
-
end
|
816
|
-
END
|
817
|
-
end
|
818
|
-
|
819
|
-
# (block
|
820
|
-
# (send nil :it
|
821
|
-
# (str "returns the document"))
|
822
|
-
# (args)
|
823
|
-
# (send
|
824
|
-
# (send nil :subject) :should
|
825
|
-
# (send nil :eq
|
826
|
-
# (send
|
827
|
-
# (str " foo\n") :gsub
|
828
|
-
# (str "foo")
|
829
|
-
# (str "bar")))))
|
830
|
-
|
831
|
-
it 'does nothing' do
|
832
|
-
rewritten_source.should == source
|
833
|
-
end
|
834
|
-
end
|
835
|
-
|
836
|
-
context 'when its argument is a here document with interpolation' do
|
837
|
-
let(:source) do
|
838
|
-
<<-'END'
|
839
|
-
it 'returns the document' do
|
840
|
-
string = 'foo'
|
841
|
-
subject.should == <<-HEREDOC
|
842
|
-
#{string}
|
843
|
-
HEREDOC
|
844
|
-
end
|
845
|
-
END
|
846
|
-
end
|
847
|
-
|
848
|
-
# (block
|
849
|
-
# (send nil :it
|
850
|
-
# (str "returns the document"))
|
851
|
-
# (args)
|
852
|
-
# (begin
|
853
|
-
# (lvasgn :string
|
854
|
-
# (str "foo"))
|
855
|
-
# (send
|
856
|
-
# (send nil :subject) :should
|
857
|
-
# (send nil :eq
|
858
|
-
# (dstr
|
859
|
-
# (str " ")
|
860
|
-
# (begin
|
861
|
-
# (lvar :string))
|
862
|
-
# (str "\n"))))))
|
863
|
-
|
864
|
-
it 'does nothing' do
|
865
|
-
rewritten_source.should == source
|
866
|
-
end
|
867
|
-
end
|
868
|
-
end
|
869
|
-
end
|
870
|
-
end
|
871
|
-
end
|