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