transpec 1.5.1 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/CHANGELOG.md +6 -0
- data/Gemfile +1 -1
- data/README.md +188 -90
- data/README.md.erb +190 -90
- data/lib/transpec/converter.rb +8 -13
- data/lib/transpec/dynamic_analyzer.rb +0 -1
- data/lib/transpec/dynamic_analyzer/rewriter.rb +6 -1
- data/lib/transpec/rspec_dsl.rb +15 -4
- data/lib/transpec/rspec_version.rb +6 -5
- data/lib/transpec/static_context_inspector.rb +25 -1
- data/lib/transpec/syntax.rb +7 -0
- data/lib/transpec/syntax/matcher_definition.rb +30 -0
- data/lib/transpec/syntax/mixin/send.rb +1 -1
- data/lib/transpec/util.rb +2 -4
- data/lib/transpec/version.rb +2 -2
- data/spec/transpec/converter_spec.rb +53 -14
- data/spec/transpec/dynamic_analyzer/rewriter_spec.rb +24 -45
- data/spec/transpec/rspec_version_spec.rb +2 -2
- data/spec/transpec/static_context_inspector_spec.rb +99 -47
- data/spec/transpec/syntax/matcher_definition_spec.rb +59 -0
- data/tasks/readme.rake +19 -2
- data/transpec.gemspec +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f1f0db34870cd389ff921e495718d2d4851acdf
|
4
|
+
data.tar.gz: d830228d9f96cae8a3dd249294c98d2ea0f41a69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8414386a89cab24f4f537786080bb7695375308bde074397a9958e3ad35c52b47e9b0b7e255c31be8070b91fed16c8352a8dba8a9113897930d78e233618398
|
7
|
+
data.tar.gz: 7feac364f4e30f95c2c00925afb73a84578ed28539b521612215a590e2fb1649e3cdce83cea55dfb6c61925263926c314f16b208ddfbf850414f747daede786a
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
## Development
|
4
4
|
|
5
|
+
## v1.6.0
|
6
|
+
|
7
|
+
* Native support for Ruby 2.1 syntax with Parser 2.1
|
8
|
+
* Support conversion of the custom matcher DSL ([#30](https://github.com/yujinakayama/transpec/issues/30))
|
9
|
+
* Support Capybara DSL in static context analysis (the logic used with `-s/--skip-dynamic-analysis`)
|
10
|
+
|
5
11
|
## v1.5.1
|
6
12
|
|
7
13
|
* Check whether a `stub` is RSpec's one or not with a static whitelist when there's no runtime data ([#33](https://github.com/yujinakayama/transpec/issues/33))
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
**Transpec** is a tool for converting your specs to the latest [RSpec](http://rspec.info/) syntax with static and dynamic code analysis.
|
6
6
|
|
7
|
-
This aims to facilitate smooth transition to RSpec 3, and it's now ready for RSpec 2.99 and 3.0 beta!
|
7
|
+
This aims to facilitate a smooth transition to RSpec 3, and it's now ready for RSpec 2.99 and 3.0 beta!
|
8
8
|
|
9
9
|
See the following pages for the new RSpec syntax and the plan for RSpec 3:
|
10
10
|
|
@@ -12,8 +12,8 @@ See the following pages for the new RSpec syntax and the plan for RSpec 3:
|
|
12
12
|
* [RSpec's new message expectation syntax - Tea is awesome.](http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/)
|
13
13
|
* [Myron Marston » The Plan for RSpec 3](http://myronmars.to/n/dev-blog/2013/07/the-plan-for-rspec-3)
|
14
14
|
|
15
|
-
Transpec now supports almost all
|
16
|
-
but the changes
|
15
|
+
Transpec now supports conversions for almost all of the RSpec 3 changes,
|
16
|
+
but the changes are not fixed and may vary in the future.
|
17
17
|
So it's recommended to follow updates of both RSpec and Transpec.
|
18
18
|
|
19
19
|
## Examples
|
@@ -115,7 +115,7 @@ Before converting your specs:
|
|
115
115
|
|
116
116
|
* Make sure your project has `rspec` gem dependency **2.14** or later. If not, change your `*.gemspec` or `Gemfile` to do so.
|
117
117
|
* Run `rspec` and check if all the specs pass.
|
118
|
-
* Ensure the Git repository is clean. (You don't want to mix up your changes and Transpec's changes,
|
118
|
+
* Ensure the Git repository is clean. (You don't want to mix up your changes and Transpec's changes, do you?)
|
119
119
|
|
120
120
|
Then, run `transpec` in the project root directory:
|
121
121
|
|
@@ -184,7 +184,7 @@ Skip dynamic analysis and convert with only static analysis. Note that specifyin
|
|
184
184
|
Specify a command to run your specs that is used for dynamic analysis.
|
185
185
|
|
186
186
|
Transpec needs to run your specs in a copied project directory for dynamic analysis.
|
187
|
-
If your project requires some special
|
187
|
+
If your project requires some special setup or commands to run specs, use this option.
|
188
188
|
`bundle exec rspec` is used by default.
|
189
189
|
|
190
190
|
```bash
|
@@ -331,31 +331,39 @@ Then run `transpec` again.
|
|
331
331
|
|
332
332
|
### Standard expectations
|
333
333
|
|
334
|
+
Targets:
|
335
|
+
|
334
336
|
```ruby
|
335
|
-
# Targets
|
336
337
|
obj.should matcher
|
337
338
|
obj.should_not matcher
|
339
|
+
```
|
340
|
+
|
341
|
+
Will be converted to:
|
338
342
|
|
339
|
-
|
343
|
+
```ruby
|
340
344
|
expect(obj).to matcher
|
341
345
|
expect(obj).not_to matcher
|
342
346
|
expect(obj).to_not matcher # with `--negative-form to_not`
|
343
347
|
```
|
344
348
|
|
345
|
-
*
|
346
|
-
* Deprecation:
|
349
|
+
* This conversion can be disabled by: `--keep should`
|
350
|
+
* Deprecation: deprecated since RSpec 3.0
|
347
351
|
* See also: [Myron Marston » RSpec's New Expectation Syntax](http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax)
|
348
352
|
|
349
353
|
### One-liner expectations
|
350
354
|
|
351
|
-
**This conversion is available only if your project
|
355
|
+
**This conversion is available only if your project's RSpec is `2.99.0.beta2` (not yet released) or later.**
|
356
|
+
|
357
|
+
Targets:
|
352
358
|
|
353
359
|
```ruby
|
354
|
-
# Targets
|
355
360
|
it { should matcher }
|
356
361
|
it { should_not matcher }
|
362
|
+
```
|
357
363
|
|
358
|
-
|
364
|
+
Will be converted to:
|
365
|
+
|
366
|
+
```ruby
|
359
367
|
it { is_expected.to matcher }
|
360
368
|
it { is_expected.not_to matcher }
|
361
369
|
it { is_expected.to_not matcher } # with `--negative-form to_not`
|
@@ -367,21 +375,25 @@ and available even if the `should` syntax is disabled with `RSpec.configure`.
|
|
367
375
|
So if you think `is_expected.to` is verbose,
|
368
376
|
feel free to disable this conversion and continue using the one-liner `should`.
|
369
377
|
|
370
|
-
*
|
378
|
+
* This conversion can be disabled by: `--keep oneliner`
|
371
379
|
* Deprecation: Not deprecated
|
372
380
|
* See also: [Add `is_expected` for expect-based one-liner syntax. by myronmarston · rspec/rspec-core](https://github.com/rspec/rspec-core/pull/1180)
|
373
381
|
|
374
382
|
### Operator matchers
|
375
383
|
|
384
|
+
Targets:
|
385
|
+
|
376
386
|
```ruby
|
377
|
-
# Targets
|
378
387
|
1.should == 1
|
379
388
|
1.should < 2
|
380
389
|
Integer.should === 1
|
381
390
|
'string'.should =~ /^str/
|
382
391
|
[1, 2, 3].should =~ [2, 1, 3]
|
392
|
+
```
|
393
|
+
|
394
|
+
Will be converted to:
|
383
395
|
|
384
|
-
|
396
|
+
```ruby
|
385
397
|
expect(1).to eq(1)
|
386
398
|
expect(1).to be < 2
|
387
399
|
expect(Integer).to be === 1
|
@@ -395,14 +407,18 @@ This conversion is combined with the conversion of [standard expectations](#stan
|
|
395
407
|
|
396
408
|
### Boolean matchers
|
397
409
|
|
398
|
-
**This conversion is available only if your project
|
410
|
+
**This conversion is available only if your project's RSpec is `2.99.0.beta1` or later.**
|
411
|
+
|
412
|
+
Targets:
|
399
413
|
|
400
414
|
```ruby
|
401
|
-
# Targets
|
402
415
|
expect(obj).to be_true
|
403
416
|
expect(obj).to be_false
|
417
|
+
```
|
404
418
|
|
405
|
-
|
419
|
+
Will be converted to:
|
420
|
+
|
421
|
+
```ruby
|
406
422
|
expect(obj).to be_truthy
|
407
423
|
expect(obj).to be_falsey
|
408
424
|
|
@@ -421,34 +437,39 @@ expect(obj).to be false
|
|
421
437
|
* `be_truthy` and `be_falsey` matchers are renamed version of `be_true` and `be_false` and their behaviors are same.
|
422
438
|
* `be true` and `be false` are not new things. These are combinations of `be` matcher and boolean literals. These pass if expectation subject is exactly equal to boolean value.
|
423
439
|
|
424
|
-
So, converting `be_true`/`be_false` to `be_truthy`/`be_falsey` never breaks your specs and this is
|
440
|
+
So, converting `be_true`/`be_false` to `be_truthy`/`be_falsey` never breaks your specs and this is Transpec's default. If you are willing to test boolean values strictly, you can convert them to `be true`/`be false` with `--boolean-matcher true,false` option. Note that this may break your specs if your application code don't return exact boolean values.
|
425
441
|
|
426
442
|
---
|
427
443
|
|
428
|
-
*
|
429
|
-
* Deprecation:
|
444
|
+
* This conversion can be disabled by: `--keep deprecated`
|
445
|
+
* Deprecation: deprecated since RSpec 2.99, removed in RSpec 3.0
|
430
446
|
* See also: [Consider renaming `be_true` and `be_false` to `be_truthy` and `be_falsey` · rspec/rspec-expectations](https://github.com/rspec/rspec-expectations/issues/283)
|
431
447
|
|
432
448
|
### `be_close` matcher
|
433
449
|
|
450
|
+
Targets:
|
451
|
+
|
434
452
|
```ruby
|
435
|
-
# Targets
|
436
453
|
expect(1.0 / 3.0).to be_close(0.333, 0.001)
|
454
|
+
```
|
455
|
+
|
456
|
+
Will be converted to:
|
437
457
|
|
438
|
-
|
458
|
+
```ruby
|
439
459
|
expect(1.0 / 3.0).to be_within(0.001).of(0.333)
|
440
460
|
```
|
441
461
|
|
442
|
-
*
|
443
|
-
* Deprecation:
|
462
|
+
* This conversion can be disabled by: `--keep deprecated`
|
463
|
+
* Deprecation: deprecated since RSpec 2.1, removed in RSpec 3.0
|
444
464
|
* See also: [New be within matcher and RSpec.deprecate fix · rspec/rspec-expectations](https://github.com/rspec/rspec-expectations/pull/32)
|
445
465
|
|
446
466
|
### `have(n).items` matcher
|
447
467
|
|
448
468
|
**This conversion will be disabled automatically if `rspec-collection_matchers` or `rspec-rails` is loaded in your spec.**
|
449
469
|
|
470
|
+
Targets:
|
471
|
+
|
450
472
|
```ruby
|
451
|
-
# Targets
|
452
473
|
expect(collection).to have(3).items
|
453
474
|
expect(collection).to have_exactly(3).items
|
454
475
|
expect(collection).to have_at_least(3).items
|
@@ -460,8 +481,11 @@ expect(team).to have(3).players
|
|
460
481
|
|
461
482
|
# Assume #players is a private method.
|
462
483
|
expect(team).to have(3).players
|
484
|
+
```
|
485
|
+
|
486
|
+
Will be converted to:
|
463
487
|
|
464
|
-
|
488
|
+
```ruby
|
465
489
|
expect(collection.size).to eq(3)
|
466
490
|
expect(collection.size).to be >= 3
|
467
491
|
expect(collection.size).to be <= 3
|
@@ -473,8 +497,8 @@ expect(team.players.size).to eq(3)
|
|
473
497
|
expect(team.send(:players).size).to eq(3)
|
474
498
|
```
|
475
499
|
|
476
|
-
There's an option to continue using `have(n).items` matcher with [rspec-collection_matchers](https://github.com/rspec/rspec-collection_matchers)
|
477
|
-
If you choose so, disable this conversion by either:
|
500
|
+
There's an option to continue using `have(n).items` matcher with [rspec-collection_matchers](https://github.com/rspec/rspec-collection_matchers) which is a gem extracted from `rspec-expectations`.
|
501
|
+
If you choose to do so, disable this conversion by either:
|
478
502
|
|
479
503
|
* Specify `--keep have_items` option manually.
|
480
504
|
* Require `rspec-collection_matchers` or `rspec-rails` in your spec so that Transpec automatically disables this conversion.
|
@@ -483,20 +507,24 @@ Note: `rspec-rails` 3.0 [still uses `have(n).items` matcher with `rspec-collecti
|
|
483
507
|
|
484
508
|
---
|
485
509
|
|
486
|
-
*
|
487
|
-
* Deprecation:
|
510
|
+
* This conversion can be disabled by: `--keep have_items`
|
511
|
+
* Deprecation: deprecated since RSpec 2.99, removed in RSpec 3.0
|
488
512
|
* See also: [Expectations: have(x).items matchers will be moved into an external gem - The Plan for RSpec 3](http://myronmars.to/n/dev-blog/2013/07/the-plan-for-rspec-3#expectations__matchers_will_be_moved_into_an_external_gem)
|
489
513
|
|
490
514
|
### One-liner expectations with `have(n).items` matcher
|
491
515
|
|
492
516
|
**This conversion will be disabled automatically if `rspec-collection_matchers` or `rspec-rails` is loaded in your spec.**
|
493
517
|
|
518
|
+
Targets:
|
519
|
+
|
494
520
|
```ruby
|
495
|
-
# Targets
|
496
521
|
it { should have(3).items }
|
497
522
|
it { should have_at_least(3).players }
|
523
|
+
```
|
498
524
|
|
499
|
-
|
525
|
+
Will be converted to:
|
526
|
+
|
527
|
+
```ruby
|
500
528
|
it 'has 3 items' do
|
501
529
|
expect(subject.size).to eq(3)
|
502
530
|
end
|
@@ -511,69 +539,85 @@ it 'has at least 3 players' do
|
|
511
539
|
end
|
512
540
|
```
|
513
541
|
|
514
|
-
*
|
542
|
+
* This conversion can be disabled by: `--keep have_items`
|
515
543
|
|
516
544
|
### Expectations on block
|
517
545
|
|
546
|
+
Targets:
|
547
|
+
|
518
548
|
```ruby
|
519
|
-
# Targets
|
520
549
|
lambda { do_something }.should raise_error
|
521
550
|
proc { do_something }.should raise_error
|
522
551
|
-> { do_something }.should raise_error
|
552
|
+
```
|
553
|
+
|
554
|
+
Will be converted to:
|
523
555
|
|
524
|
-
|
556
|
+
```ruby
|
525
557
|
expect { do_something }.to raise_error
|
526
558
|
```
|
527
559
|
|
528
|
-
*
|
529
|
-
* Deprecation:
|
560
|
+
* This conversion can be disabled by: `--keep should`
|
561
|
+
* Deprecation: deprecated since RSpec 3.0
|
530
562
|
* See also: [Unification of Block vs. Value Syntaxes - RSpec's New Expectation Syntax](http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax#unification_of_block_vs_value_syntaxes)
|
531
563
|
|
532
564
|
### Negative error expectations with specific error
|
533
565
|
|
566
|
+
Targets:
|
567
|
+
|
534
568
|
```ruby
|
535
|
-
# Targets
|
536
569
|
expect { do_something }.not_to raise_error(SomeErrorClass)
|
537
570
|
expect { do_something }.not_to raise_error('message')
|
538
571
|
expect { do_something }.not_to raise_error(SomeErrorClass, 'message')
|
539
572
|
lambda { do_something }.should_not raise_error(SomeErrorClass)
|
573
|
+
```
|
540
574
|
|
541
|
-
|
575
|
+
Will be converted to:
|
576
|
+
|
577
|
+
```ruby
|
542
578
|
expect { do_something }.not_to raise_error
|
543
579
|
lambda { do_something }.should_not raise_error # with `--keep should`
|
544
580
|
```
|
545
581
|
|
546
|
-
*
|
547
|
-
* Deprecation:
|
582
|
+
* This conversion can be disabled by: `--keep deprecated`
|
583
|
+
* Deprecation: deprecated since RSpec 2.14, removed in RSpec 3.0
|
548
584
|
* See also: [Consider deprecating `expect { }.not_to raise_error(SpecificErrorClass)` · rspec/rspec-expectations](https://github.com/rspec/rspec-expectations/issues/231)
|
549
585
|
|
550
586
|
### Message expectations
|
551
587
|
|
588
|
+
Targets:
|
589
|
+
|
552
590
|
```ruby
|
553
|
-
# Targets
|
554
591
|
obj.should_receive(:foo)
|
555
592
|
Klass.any_instance.should_receive(:foo)
|
593
|
+
```
|
594
|
+
|
595
|
+
Will be converted to:
|
556
596
|
|
557
|
-
|
597
|
+
```ruby
|
558
598
|
expect(obj).to receive(:foo)
|
559
599
|
expect_any_instance_of(Klass).to receive(:foo)
|
560
600
|
```
|
561
601
|
|
562
|
-
*
|
563
|
-
* Deprecation:
|
602
|
+
* This conversion can be disabled by: `--keep should_receive`
|
603
|
+
* Deprecation: deprecated since RSpec 3.0
|
564
604
|
* See also: [RSpec's new message expectation syntax - Tea is awesome.](http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/)
|
565
605
|
|
566
606
|
### Message expectations that are actually method stubs
|
567
607
|
|
608
|
+
Targets:
|
609
|
+
|
568
610
|
```ruby
|
569
|
-
# Targets
|
570
611
|
obj.should_receive(:foo).any_number_of_times
|
571
612
|
obj.should_receive(:foo).at_least(0)
|
572
613
|
|
573
614
|
Klass.any_instance.should_receive(:foo).any_number_of_times
|
574
615
|
Klass.any_instance.should_receive(:foo).at_least(0)
|
616
|
+
```
|
617
|
+
|
618
|
+
Will be converted to:
|
575
619
|
|
576
|
-
|
620
|
+
```ruby
|
577
621
|
allow(obj).to receive(:foo)
|
578
622
|
obj.stub(:foo) # with `--keep stub`
|
579
623
|
|
@@ -581,14 +625,15 @@ allow_any_instance_of(Klass).to receive(:foo)
|
|
581
625
|
Klass.any_instance.stub(:foo) # with `--keep stub`
|
582
626
|
```
|
583
627
|
|
584
|
-
*
|
585
|
-
* Deprecation:
|
628
|
+
* This conversion can be disabled by: `--keep deprecated`
|
629
|
+
* Deprecation: deprecated since RSpec 2.14, removed in RSpec 3.0
|
586
630
|
* See also: [Don't allow at_least(0) · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/133)
|
587
631
|
|
588
632
|
### Method stubs
|
589
633
|
|
634
|
+
Targets:
|
635
|
+
|
590
636
|
```ruby
|
591
|
-
# Targets
|
592
637
|
obj.stub(:foo)
|
593
638
|
obj.stub!(:foo)
|
594
639
|
|
@@ -597,19 +642,22 @@ obj.stub(:foo => 1, :bar => 2)
|
|
597
642
|
obj.stub_chain(:foo, :bar, :baz)
|
598
643
|
|
599
644
|
Klass.any_instance.stub(:foo)
|
645
|
+
```
|
600
646
|
|
601
|
-
|
647
|
+
Will be converted to:
|
648
|
+
|
649
|
+
```ruby
|
602
650
|
allow(obj).to receive(:foo)
|
603
651
|
|
604
|
-
# If the target project's
|
652
|
+
# If the target project's RSpec is prior to 3.0.0.beta1
|
605
653
|
allow(obj).to receive(:foo).and_return(1)
|
606
654
|
allow(obj).to receive(:bar).and_return(2)
|
607
655
|
|
608
|
-
# If the target project's
|
656
|
+
# If the target project's RSpec is 3.0.0.beta1 or later
|
609
657
|
allow(obj).to receive_messages(:foo => 1, :bar => 2)
|
610
658
|
|
611
659
|
# Conversion from `stub_chain` to `receive_message_chain` is available
|
612
|
-
# only if the target project's
|
660
|
+
# only if the target project's RSpec is 3.0.0.beta2 (not yet released) or later
|
613
661
|
allow(obj).to receive_message_chain(:foo, :bar, :baz)
|
614
662
|
|
615
663
|
allow_any_instance_of(Klass).to receive(:foo)
|
@@ -617,7 +665,7 @@ allow_any_instance_of(Klass).to receive(:foo)
|
|
617
665
|
|
618
666
|
#### No replacement for `unstub`
|
619
667
|
|
620
|
-
There's no replacement for `unstub` in the `expect` syntax. See [
|
668
|
+
There's no replacement for `unstub` in the `expect` syntax. See [this discussion](https://github.com/rspec/rspec-mocks/issues/153#issuecomment-12208638) for more details.
|
621
669
|
|
622
670
|
#### Steps to upgrade `obj.stub(:foo => 1, :bar => 2)`
|
623
671
|
|
@@ -632,8 +680,8 @@ Otherwise `obj.stub(:foo => 1, :bar => 2)` will be converted to two `allow(obj).
|
|
632
680
|
|
633
681
|
---
|
634
682
|
|
635
|
-
*
|
636
|
-
* Deprecation:
|
683
|
+
* This conversion can be disabled by: `--keep stub`
|
684
|
+
* Deprecation: deprecated since RSpec 3.0
|
637
685
|
* See also:
|
638
686
|
* [RSpec's new message expectation syntax - Tea is awesome.](http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/)
|
639
687
|
* [allow receive with multiple methods · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/368)
|
@@ -641,65 +689,81 @@ Otherwise `obj.stub(:foo => 1, :bar => 2)` will be converted to two `allow(obj).
|
|
641
689
|
|
642
690
|
### Deprecated method stub aliases
|
643
691
|
|
692
|
+
Targets:
|
693
|
+
|
644
694
|
```ruby
|
645
|
-
# Targets
|
646
695
|
obj.stub!(:foo)
|
647
696
|
obj.unstub!(:foo)
|
697
|
+
```
|
698
|
+
|
699
|
+
Will be converted to:
|
648
700
|
|
649
|
-
|
701
|
+
```ruby
|
650
702
|
obj.stub(:foo) # with `--keep stub`
|
651
703
|
obj.unstub(:foo)
|
652
704
|
```
|
653
705
|
|
654
|
-
*
|
655
|
-
* Deprecation:
|
706
|
+
* This conversion can be disabled by: `--keep deprecated`
|
707
|
+
* Deprecation: deprecated since RSpec 2.14, removed in RSpec 3.0
|
656
708
|
* See also: [Consider deprecating and/or removing #stub! and #unstub! at some point · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/122)
|
657
709
|
|
658
710
|
### Method stubs with deprecated specification of number of times
|
659
711
|
|
712
|
+
Targets:
|
713
|
+
|
660
714
|
```ruby
|
661
|
-
# Targets
|
662
715
|
obj.stub(:foo).any_number_of_times
|
663
716
|
obj.stub(:foo).at_least(0)
|
717
|
+
```
|
664
718
|
|
665
|
-
|
719
|
+
Will be converted to:
|
720
|
+
|
721
|
+
```ruby
|
666
722
|
allow(obj).to receive(:foo)
|
667
723
|
obj.stub(:foo) # with `--keep stub`
|
668
724
|
```
|
669
725
|
|
670
|
-
*
|
671
|
-
* Deprecation:
|
726
|
+
* This conversion can be disabled by: `--keep deprecated`
|
727
|
+
* Deprecation: deprecated since RSpec 2.14, removed in RSpec 3.0
|
672
728
|
* See also: [Don't allow at_least(0) · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/133)
|
673
729
|
|
674
730
|
### Deprecated test double aliases
|
675
731
|
|
732
|
+
Targets:
|
733
|
+
|
676
734
|
```ruby
|
677
|
-
# Targets
|
678
735
|
stub('something')
|
679
736
|
mock('something')
|
737
|
+
```
|
738
|
+
|
739
|
+
Will be converted to:
|
680
740
|
|
681
|
-
|
741
|
+
```ruby
|
682
742
|
double('something')
|
683
743
|
```
|
684
744
|
|
685
|
-
*
|
686
|
-
* Deprecation:
|
745
|
+
* This conversion can be disabled by: `--keep deprecated`
|
746
|
+
* Deprecation: deprecated since RSpec 2.14, removed in RSpec 3.0
|
687
747
|
* See also: [myronmarston / why_double.md - Gist](https://gist.github.com/myronmarston/6576665)
|
688
748
|
|
689
749
|
### Expectations on attribute of subject with `its`
|
690
750
|
|
691
751
|
**This conversion will be disabled automatically if `rspec-its` is loaded in your spec.**
|
692
752
|
|
753
|
+
Targets:
|
754
|
+
|
693
755
|
```ruby
|
694
|
-
# Targets
|
695
756
|
describe 'example' do
|
696
757
|
subject { { foo: 1, bar: 2 } }
|
697
758
|
its(:size) { should == 2 }
|
698
759
|
its([:foo]) { should == 1 }
|
699
760
|
its('keys.first') { should == :foo }
|
700
761
|
end
|
762
|
+
```
|
763
|
+
|
764
|
+
Will be converted to:
|
701
765
|
|
702
|
-
|
766
|
+
```ruby
|
703
767
|
describe 'example' do
|
704
768
|
subject { { foo: 1, bar: 2 } }
|
705
769
|
|
@@ -723,24 +787,25 @@ describe 'example' do
|
|
723
787
|
end
|
724
788
|
```
|
725
789
|
|
726
|
-
There's an option to continue using `its` with [rspec-its](https://github.com/rspec/rspec-its)
|
727
|
-
If you choose so, disable this conversion by either:
|
790
|
+
There's an option to continue using `its` with [rspec-its](https://github.com/rspec/rspec-its) which is a gem extracted from `rspec-core`.
|
791
|
+
If you choose to do so, disable this conversion by either:
|
728
792
|
|
729
793
|
* Specify `--keep its` option manually.
|
730
794
|
* Require `rspec-its` in your spec so that Transpec automatically disables this conversion.
|
731
795
|
|
732
796
|
---
|
733
797
|
|
734
|
-
*
|
735
|
-
* Deprecation:
|
798
|
+
* This conversion can be disabled by: `--keep its`
|
799
|
+
* Deprecation: deprecated since RSpec 2.99, removed in RSpec 3.0
|
736
800
|
* See also: [Core: its will be moved into an external gem - The Plan for RSpec 3](http://myronmars.to/n/dev-blog/2013/07/the-plan-for-rspec-3#core__will_be_moved_into_an_external_gem)
|
737
801
|
|
738
802
|
### Current example object
|
739
803
|
|
740
|
-
**This conversion is available only if your project
|
804
|
+
**This conversion is available only if your project's RSpec is `2.99.0.beta1` or later.**
|
805
|
+
|
806
|
+
Targets:
|
741
807
|
|
742
808
|
```ruby
|
743
|
-
# Targets
|
744
809
|
module ScreenshotHelper
|
745
810
|
def save_failure_screenshot
|
746
811
|
return unless example.exception
|
@@ -754,8 +819,11 @@ describe 'example page' do
|
|
754
819
|
let(:user) { User.find(example.metadata[:user_id]) }
|
755
820
|
# ...
|
756
821
|
end
|
822
|
+
```
|
757
823
|
|
758
|
-
|
824
|
+
Will be converted to:
|
825
|
+
|
826
|
+
```ruby
|
759
827
|
module ScreenshotHelper
|
760
828
|
def save_failure_screenshot
|
761
829
|
return unless RSpec.current_example.exception
|
@@ -773,24 +841,54 @@ end
|
|
773
841
|
|
774
842
|
Here's an excerpt from [the warning for `RSpec::Core::ExampleGroup#example` and `#running_example` in RSpec 2.99](https://github.com/rspec/rspec-core/blob/7d6d2ca/lib/rspec/core/example_group.rb#L513-L527):
|
775
843
|
|
776
|
-
|
844
|
+
> `RSpec::Core::ExampleGroup#example` is deprecated and will be removed in RSpec 3. There are a few options for what you can use instead:
|
777
845
|
>
|
778
|
-
|
779
|
-
|
780
|
-
|
846
|
+
> - `rspec-core`'s DSL methods (`it`, `before`, `after`, `let`, `subject`, etc) now yield the example as a block argument, and that is the recommended way to access the current example from those contexts.
|
847
|
+
> - The current example is now exposed via `RSpec.current_example`, which is accessible from any context.
|
848
|
+
> - If you can't update the code at this call site (e.g. because it is in an extension gem), you can use this snippet to continue making this method available in RSpec 2.99 and RSpec 3:
|
781
849
|
>
|
782
|
-
|
783
|
-
>RSpec.configure do |c|
|
784
|
-
>
|
785
|
-
>end
|
786
|
-
|
850
|
+
> ```ruby
|
851
|
+
> RSpec.configure do |c|
|
852
|
+
> c.expose_current_running_example_as :example
|
853
|
+
> end
|
854
|
+
> ```
|
787
855
|
|
788
856
|
---
|
789
857
|
|
790
|
-
*
|
791
|
-
* Deprecation:
|
858
|
+
* This conversion can be disabled by: `--keep deprecated`
|
859
|
+
* Deprecation: deprecated since RSpec 2.99, removed in RSpec 3.0
|
792
860
|
* See also: [Core: DSL methods will yield the example - The Plan for RSpec 3](http://myronmars.to/n/dev-blog/2013/07/the-plan-for-rspec-3#core_dsl_methods_will_yield_the_example)
|
793
861
|
|
862
|
+
### Custom matcher DSL
|
863
|
+
|
864
|
+
**This conversion is available only if your project's RSpec is `3.0.0.beta2` (not yet released) or later.**
|
865
|
+
|
866
|
+
Targets:
|
867
|
+
|
868
|
+
```ruby
|
869
|
+
RSpec::Matchers.define :be_awesome do
|
870
|
+
match_for_should { }
|
871
|
+
match_for_should_not { }
|
872
|
+
failure_message_for_should { }
|
873
|
+
failure_message_for_should_not { }
|
874
|
+
end
|
875
|
+
```
|
876
|
+
|
877
|
+
Will be converted to:
|
878
|
+
|
879
|
+
```ruby
|
880
|
+
RSpec::Matchers.define :be_awesome do
|
881
|
+
match { }
|
882
|
+
match_when_negated { }
|
883
|
+
failure_message { }
|
884
|
+
failure_message_when_negated { }
|
885
|
+
end
|
886
|
+
```
|
887
|
+
|
888
|
+
* This conversion can be disabled by: `--keep deprecated`
|
889
|
+
* Deprecation: deprecated since RSpec 3.0
|
890
|
+
* See also: [Expectations: Matcher protocol and custom matcher API changes - The Plan for RSpec 3](http://myronmars.to/n/dev-blog/2013/07/the-plan-for-rspec-3#expectations_matcher_protocol_and_custom_matcher_api_changes)
|
891
|
+
|
794
892
|
## Compatibility
|
795
893
|
|
796
894
|
Tested on MRI 1.9, MRI 2.0 and JRuby in 1.9 mode.
|