transpec 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.travis.yml +1 -3
- data/CHANGELOG.md +9 -0
- data/README.md +141 -24
- data/README.md.erb +136 -24
- data/lib/transpec/ast/node.rb +7 -3
- data/lib/transpec/cli.rb +1 -1
- data/lib/transpec/configuration.rb +1 -0
- data/lib/transpec/converter.rb +31 -2
- data/lib/transpec/dynamic_analyzer.rb +1 -1
- data/lib/transpec/option_parser.rb +12 -9
- data/lib/transpec/project.rb +23 -12
- data/lib/transpec/rspec_version.rb +18 -4
- data/lib/transpec/static_context_inspector.rb +0 -15
- data/lib/transpec/syntax/example.rb +83 -0
- data/lib/transpec/syntax/expect.rb +5 -0
- data/lib/transpec/syntax/have.rb +111 -54
- data/lib/transpec/syntax/method_stub.rb +58 -37
- data/lib/transpec/syntax/mixin/allow_no_message.rb +2 -0
- data/lib/transpec/syntax/mixin/any_instance.rb +2 -0
- data/lib/transpec/syntax/mixin/should_base.rb +39 -0
- data/lib/transpec/syntax/oneliner_should.rb +218 -0
- data/lib/transpec/syntax/operator_matcher.rb +1 -0
- data/lib/transpec/syntax/should.rb +3 -30
- data/lib/transpec/util.rb +54 -0
- data/lib/transpec/version.rb +2 -2
- data/spec/support/shared_context.rb +21 -29
- data/spec/transpec/ast/node_spec.rb +1 -1
- data/spec/transpec/commit_message_spec.rb +29 -23
- data/spec/transpec/configuration_spec.rb +1 -0
- data/spec/transpec/converter_spec.rb +208 -5
- data/spec/transpec/dynamic_analyzer_spec.rb +2 -2
- data/spec/transpec/option_parser_spec.rb +1 -0
- data/spec/transpec/project_spec.rb +10 -0
- data/spec/transpec/rspec_version_spec.rb +52 -28
- data/spec/transpec/static_context_inspector_spec.rb +2 -2
- data/spec/transpec/syntax/be_boolean_spec.rb +6 -13
- data/spec/transpec/syntax/be_close_spec.rb +2 -9
- data/spec/transpec/syntax/double_spec.rb +2 -9
- data/spec/transpec/syntax/example_spec.rb +249 -0
- data/spec/transpec/syntax/expect_spec.rb +1 -1
- data/spec/transpec/syntax/have_spec.rb +127 -22
- data/spec/transpec/syntax/its_spec.rb +9 -18
- data/spec/transpec/syntax/method_stub_spec.rb +193 -158
- data/spec/transpec/syntax/oneliner_should_spec.rb +653 -0
- data/spec/transpec/syntax/operator_matcher_spec.rb +7 -8
- data/spec/transpec/syntax/raise_error_spec.rb +6 -13
- data/spec/transpec/syntax/rspec_configure_spec.rb +1 -8
- data/spec/transpec/syntax/should_receive_spec.rb +19 -28
- data/spec/transpec/syntax/should_spec.rb +18 -16
- data/spec/transpec/util_spec.rb +30 -0
- data/transpec.gemspec +8 -7
- metadata +49 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3bc90b69deb7ecd6c16aad1ea76d165efafe220
|
4
|
+
data.tar.gz: 27ea84e9492410a212bd0bf12f24d05ac6c578d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a84904de40d64efeacd01ea3b987e7be6ba3ec684cd6c3c583b582ff85af474d9ee10a3b194b201aebe91b172a6cfa9ce141b3d2d04b9e2753485f72765f512c
|
7
|
+
data.tar.gz: 65b09567e243ee63bf39b2a35d3ce068e5573c5328e62bfe20f757b098fdc856eae83938355ae8eb980a0593b792a1c9d974c942151afe64fdd6ab3ecfeac232
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,15 @@
|
|
2
2
|
|
3
3
|
## Development
|
4
4
|
|
5
|
+
## v1.4.0
|
6
|
+
|
7
|
+
* Support conversion of `RSpec::Core::ExampleGroup#example` ([#23](https://github.com/yujinakayama/transpec/issues/23))
|
8
|
+
* Support conversion of one-liner syntax ([#25](https://github.com/yujinakayama/transpec/issues/25))
|
9
|
+
* Support conversion of one-liner syntax with `have(n).items` matcher
|
10
|
+
* Support conversion of `stub_chain`
|
11
|
+
* Fix a bug where `-p/--no-parentheses-matcher-arg` was not applied to the conversion of `have(n).items` with `expect`
|
12
|
+
* Fix a bug where conversion summaries of `have(n).item` with negative expectation were reported as positive expectations
|
13
|
+
|
5
14
|
## v1.3.1
|
6
15
|
|
7
16
|
* Proceed to conversion even if `rspec` didn't pass in dynamic analysis
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# Transpec
|
4
4
|
|
5
|
-
**Transpec** automatically converts your specs
|
5
|
+
**Transpec** automatically converts your specs to the latest [RSpec](http://rspec.info/) syntax with static and dynamic code analysis.
|
6
6
|
|
7
7
|
This aims to facilitate smooth transition to RSpec 3, and it's now ready for RSpec 2.99 and 3.0 beta!
|
8
8
|
|
@@ -184,7 +184,7 @@ Skip dynamic analysis and convert with only static analysis. Note that specifyin
|
|
184
184
|
|
185
185
|
Specify command to run RSpec that is used for dynamic analysis.
|
186
186
|
|
187
|
-
Transpec needs to run your specs in copied project directory for dynamic analysis.
|
187
|
+
Transpec needs to run your specs in a copied project directory for dynamic analysis.
|
188
188
|
If your project requires some special setup or commands to run specs, use this option.
|
189
189
|
`bundle exec rspec` is used by default.
|
190
190
|
|
@@ -216,6 +216,7 @@ $ transpec --keep should_receive,stub
|
|
216
216
|
Type | Target Syntax | Converted Syntax
|
217
217
|
-----------------|----------------------------------|-----------------------------------
|
218
218
|
`should` | `obj.should matcher` | `expect(obj).to matcher`
|
219
|
+
`oneliner` | `it { should ... }` | `it { is_expected.to ... }`
|
219
220
|
`should_receive` | `obj.should_receive` | `expect(obj).to receive`
|
220
221
|
`stub` | `obj.stub` | `allow(obj).to receive`
|
221
222
|
`have_items` | `expect(obj).to have(x).items` | `expect(obj.size).to eq(x)`
|
@@ -236,7 +237,7 @@ $ transpec --negative-form to_not
|
|
236
237
|
|
237
238
|
### `-b/--boolean-matcher`
|
238
239
|
|
239
|
-
Specify matcher type that `be_true` and `be_false` will be converted to.
|
240
|
+
Specify a matcher type that `be_true` and `be_false` will be converted to.
|
240
241
|
Any of `truthy,falsey`, `truthy,falsy` or `true,false` can be specified.
|
241
242
|
`truthy,falsey` is used by default.
|
242
243
|
|
@@ -248,7 +249,7 @@ See [Supported Conversions - Boolean matchers](#boolean-matchers) for more detai
|
|
248
249
|
|
249
250
|
### `-p/--no-parentheses-matcher-arg`
|
250
251
|
|
251
|
-
Suppress parenthesizing
|
252
|
+
Suppress parenthesizing arguments of matchers when converting
|
252
253
|
`should` with operator matcher to `expect` with non-operator matcher
|
253
254
|
(the `expect` syntax does not directly support the operator matchers).
|
254
255
|
Note that it will be parenthesized even if this option is specified
|
@@ -297,7 +298,7 @@ Cannot convert #should into #expect since #expect is not available in the contex
|
|
297
298
|
spec/awesome_spec.rb:4: 1.should == 1
|
298
299
|
```
|
299
300
|
|
300
|
-
This message would be shown with specs like
|
301
|
+
This message would be shown with specs like:
|
301
302
|
|
302
303
|
```ruby
|
303
304
|
describe '#should that cannot be converted to #expect' do
|
@@ -357,6 +358,31 @@ expect(obj).to_not matcher # with `--negative-form to_not`
|
|
357
358
|
* Deprecation: Deprecated since RSpec 3.0
|
358
359
|
* See also: [Myron Marston » RSpec's New Expectation Syntax](http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax)
|
359
360
|
|
361
|
+
### One-liner expectations
|
362
|
+
|
363
|
+
**This conversion is available only if your project has `rspec` gem dependency `2.99.0.beta2` or later.**
|
364
|
+
|
365
|
+
```ruby
|
366
|
+
# Targets
|
367
|
+
it { should matcher }
|
368
|
+
it { should_not matcher }
|
369
|
+
|
370
|
+
# Converted
|
371
|
+
it { is_expected.to matcher }
|
372
|
+
it { is_expected.not_to matcher }
|
373
|
+
it { is_expected.to_not matcher } # with `--negative-form to_not`
|
374
|
+
```
|
375
|
+
|
376
|
+
`is_expected.to` is designed for the consistency with the `expect` syntax.
|
377
|
+
However the one-liner `should` is still _not_ deprecated in RSpec 3.0
|
378
|
+
and available even if the `should` syntax is disabled in `RSpec.configure`.
|
379
|
+
So if you think `is_expected.to` is verbose,
|
380
|
+
feel free to disable this conversion and continue using the one-liner `should`.
|
381
|
+
|
382
|
+
* Conversion can be disabled by: `--keep oneliner`
|
383
|
+
* Deprecation: Not deprecated
|
384
|
+
* See also: [Add `is_expected` for expect-based one-liner syntax. by myronmarston · rspec/rspec-core](https://github.com/rspec/rspec-core/pull/1180)
|
385
|
+
|
360
386
|
### Operator matchers
|
361
387
|
|
362
388
|
```ruby
|
@@ -375,13 +401,13 @@ expect('string').to match(/^str/)
|
|
375
401
|
expect([1, 2, 3]).to match_array([2, 1, 3])
|
376
402
|
```
|
377
403
|
|
378
|
-
This conversion is combined with the conversion of [
|
404
|
+
This conversion is combined with the conversion of [standard expectations](#standard-expecatations) and cannot be disabled separately because the `expect` syntax does not directly support the operator matchers.
|
379
405
|
|
380
406
|
* See also: [(Almost) All Matchers Are Supported - RSpec's New Expectation Syntax](http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax#almost_all_matchers_are_supported)
|
381
407
|
|
382
408
|
### Boolean matchers
|
383
409
|
|
384
|
-
**This conversion is available only if your project has `rspec` gem dependency `2.99` or later.**
|
410
|
+
**This conversion is available only if your project has `rspec` gem dependency `2.99.0.beta1` or later.**
|
385
411
|
|
386
412
|
```ruby
|
387
413
|
# Targets
|
@@ -412,7 +438,7 @@ So, converting `be_true`/`be_false` to `be_truthy`/`be_falsey` never breaks your
|
|
412
438
|
---
|
413
439
|
|
414
440
|
* Conversion can be disabled by: `--keep deprecated`
|
415
|
-
* Deprecation: Deprecated since RSpec 2.99, removed
|
441
|
+
* Deprecation: Deprecated since RSpec 2.99, removed in RSpec 3.0
|
416
442
|
* 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)
|
417
443
|
|
418
444
|
### `be_close` matcher
|
@@ -426,7 +452,7 @@ expect(1.0 / 3.0).to be_within(0.001).of(0.333)
|
|
426
452
|
```
|
427
453
|
|
428
454
|
* Conversion can be disabled by: `--keep deprecated`
|
429
|
-
* Deprecation: Deprecated since RSpec 2.1, removed
|
455
|
+
* Deprecation: Deprecated since RSpec 2.1, removed in RSpec 3.0
|
430
456
|
* See also: [New be within matcher and RSpec.deprecate fix · rspec/rspec-expectations](https://github.com/rspec/rspec-expectations/pull/32)
|
431
457
|
|
432
458
|
### `have(n).items` matcher
|
@@ -459,7 +485,7 @@ expect(team.players.size).to eq(3)
|
|
459
485
|
expect(team.send(:players).size).to eq(3)
|
460
486
|
```
|
461
487
|
|
462
|
-
There's an option to continue using `have(n).items` matcher with [rspec-collection_matchers](https://github.com/rspec/rspec-collection_matchers) that is
|
488
|
+
There's an option to continue using `have(n).items` matcher with [rspec-collection_matchers](https://github.com/rspec/rspec-collection_matchers) that is a gem extracted from `rspec-expectations`.
|
463
489
|
If you choose so, disable this conversion by either:
|
464
490
|
|
465
491
|
* Specify `--keep have_items` option manually.
|
@@ -470,9 +496,35 @@ Note: `rspec-rails` 3.0 [still uses `have(n).items` matcher with `rspec-collecti
|
|
470
496
|
---
|
471
497
|
|
472
498
|
* Conversion can be disabled by: `--keep have_items`
|
473
|
-
* Deprecation: Deprecated since RSpec 2.99, removed
|
499
|
+
* Deprecation: Deprecated since RSpec 2.99, removed in RSpec 3.0
|
474
500
|
* 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)
|
475
501
|
|
502
|
+
### One-liner expectations with `have(n).items` matcher
|
503
|
+
|
504
|
+
**This conversion will be disabled automatically if `rspec-collection_matchers` or `rspec-rails` is loaded in your spec.**
|
505
|
+
|
506
|
+
```ruby
|
507
|
+
# Targets
|
508
|
+
it { should have(3).items }
|
509
|
+
it { should have_at_least(3).players }
|
510
|
+
|
511
|
+
# Converted
|
512
|
+
it 'has 3 items' do
|
513
|
+
expect(subject.size).to eq(3)
|
514
|
+
end
|
515
|
+
|
516
|
+
# With `--keep should`
|
517
|
+
it 'has 3 items' do
|
518
|
+
subject.size.should == 3
|
519
|
+
end
|
520
|
+
|
521
|
+
it 'has at least 3 players' do
|
522
|
+
expect(subject.players.size).to be >= 3
|
523
|
+
end
|
524
|
+
```
|
525
|
+
|
526
|
+
* Conversion can be disabled by: `--keep have_items`
|
527
|
+
|
476
528
|
### Expectations on block
|
477
529
|
|
478
530
|
```ruby
|
@@ -504,7 +556,7 @@ lambda { do_something }.should_not raise_error # with `--keep should`
|
|
504
556
|
```
|
505
557
|
|
506
558
|
* Conversion can be disabled by: `--keep deprecated`
|
507
|
-
* Deprecation: Deprecated since RSpec 2.14, removed
|
559
|
+
* Deprecation: Deprecated since RSpec 2.14, removed in RSpec 3.0
|
508
560
|
* See also: [Consider deprecating `expect { }.not_to raise_error(SpecificErrorClass)` · rspec/rspec-expectations](https://github.com/rspec/rspec-expectations/issues/231)
|
509
561
|
|
510
562
|
### Message expectations
|
@@ -542,7 +594,7 @@ Klass.any_instance.stub(:foo) # with `--keep stub`
|
|
542
594
|
```
|
543
595
|
|
544
596
|
* Conversion can be disabled by: `--keep deprecated`
|
545
|
-
* Deprecation: Deprecated since RSpec 2.14, removed
|
597
|
+
* Deprecation: Deprecated since RSpec 2.14, removed in RSpec 3.0
|
546
598
|
* See also: [Don't allow at_least(0) · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/133)
|
547
599
|
|
548
600
|
### Method stubs
|
@@ -550,29 +602,38 @@ Klass.any_instance.stub(:foo) # with `--keep stub`
|
|
550
602
|
```ruby
|
551
603
|
# Targets
|
552
604
|
obj.stub(:foo)
|
553
|
-
|
554
605
|
obj.stub!(:foo)
|
555
606
|
|
556
607
|
obj.stub(:foo => 1, :bar => 2)
|
557
608
|
|
609
|
+
obj.stub_chain(:foo, :bar, :baz)
|
610
|
+
|
558
611
|
Klass.any_instance.stub(:foo)
|
559
612
|
|
560
613
|
# Converted
|
561
614
|
allow(obj).to receive(:foo)
|
562
615
|
|
563
|
-
|
564
|
-
|
565
|
-
# If the target project's rspec gem dependency is prior to 3.0
|
616
|
+
# If the target project's rspec gem dependency is prior to 3.0.0.beta1
|
566
617
|
allow(obj).to receive(:foo).and_return(1)
|
567
618
|
allow(obj).to receive(:bar).and_return(2)
|
568
619
|
|
569
|
-
# If the target project's rspec gem dependency is 3.0 or later
|
620
|
+
# If the target project's rspec gem dependency is 3.0.0.beta1 or later
|
570
621
|
allow(obj).to receive_messages(:foo => 1, :bar => 2)
|
571
622
|
|
623
|
+
# Conversion from `stub_chain` to `receive_message_chain` is available
|
624
|
+
# only if the target project's rspec gem dependency is 2.99.0.beta2 or later
|
625
|
+
allow(obj).to receive_message_chain(:foo, :bar, :baz)
|
626
|
+
|
572
627
|
allow_any_instance_of(Klass).to receive(:foo)
|
573
628
|
```
|
574
629
|
|
575
|
-
|
630
|
+
#### No replacement for `unstub`
|
631
|
+
|
632
|
+
There's no replacement for `unstub` in the `expect` syntax. See [the discussion](https://github.com/rspec/rspec-mocks/issues/153#issuecomment-12208638) for more details.
|
633
|
+
|
634
|
+
#### Steps to upgrade `obj.stub(:foo => 1, :bar => 2)`
|
635
|
+
|
636
|
+
`allow(obj).to receive_messages(:foo => 1, :bar => 2)` that is designed to be the replacement for `obj.stub(:foo => 1, :bar => 2)` is available from RSpec 3.0 (though [it's now being considered to be backported to RSpec 2.99](https://github.com/rspec/rspec-mocks/issues/454)). So, in [the upgrade path to RSpec 3](http://myronmars.to/n/dev-blog/2013/07/the-plan-for-rspec-3#the_upgrade_path), if you want to convert them with keeping the syntax correspondence, you need to follow these steps:
|
576
637
|
|
577
638
|
1. Upgrade to RSpec 2.99
|
578
639
|
2. Run `transpec --keep stub`
|
@@ -602,7 +663,7 @@ obj.unstub(:foo)
|
|
602
663
|
```
|
603
664
|
|
604
665
|
* Conversion can be disabled by: `--keep deprecated`
|
605
|
-
* Deprecation: Deprecated since RSpec 2.14, removed
|
666
|
+
* Deprecation: Deprecated since RSpec 2.14, removed in RSpec 3.0
|
606
667
|
* See also: [Consider deprecating and/or removing #stub! and #unstub! at some point · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/122)
|
607
668
|
|
608
669
|
### Method stubs with deprecated specification of number of times
|
@@ -618,7 +679,7 @@ obj.stub(:foo) # with `--keep stub`
|
|
618
679
|
```
|
619
680
|
|
620
681
|
* Conversion can be disabled by: `--keep deprecated`
|
621
|
-
* Deprecation: Deprecated since RSpec 2.14, removed
|
682
|
+
* Deprecation: Deprecated since RSpec 2.14, removed in RSpec 3.0
|
622
683
|
* See also: [Don't allow at_least(0) · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/133)
|
623
684
|
|
624
685
|
### Deprecated test double aliases
|
@@ -633,7 +694,7 @@ double('something')
|
|
633
694
|
```
|
634
695
|
|
635
696
|
* Conversion can be disabled by: `--keep deprecated`
|
636
|
-
* Deprecation: Deprecated since RSpec 2.14, removed
|
697
|
+
* Deprecation: Deprecated since RSpec 2.14, removed in RSpec 3.0
|
637
698
|
* See also: [myronmarston / why_double.md - Gist](https://gist.github.com/myronmarston/6576665)
|
638
699
|
|
639
700
|
### Expectations on attribute of subject with `its`
|
@@ -673,7 +734,7 @@ describe 'example' do
|
|
673
734
|
end
|
674
735
|
```
|
675
736
|
|
676
|
-
There's an option to continue using `its` with [rspec-its](https://github.com/rspec/rspec-its) that is
|
737
|
+
There's an option to continue using `its` with [rspec-its](https://github.com/rspec/rspec-its) that is a gem extracted from `rspec-core`.
|
677
738
|
If you choose so, disable this conversion by either:
|
678
739
|
|
679
740
|
* Specify `--keep its` option manually.
|
@@ -682,9 +743,65 @@ If you choose so, disable this conversion by either:
|
|
682
743
|
---
|
683
744
|
|
684
745
|
* Conversion can be disabled by: `--keep its`
|
685
|
-
* Deprecation: Deprecated since RSpec 2.99, removed
|
746
|
+
* Deprecation: Deprecated since RSpec 2.99, removed in RSpec 3.0
|
686
747
|
* 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)
|
687
748
|
|
749
|
+
### Current example object
|
750
|
+
|
751
|
+
**This conversion is available only if your project has `rspec` gem dependency `2.99.0.beta1` or later.**
|
752
|
+
|
753
|
+
```ruby
|
754
|
+
# Targets
|
755
|
+
module ScreenshotHelper
|
756
|
+
def save_failure_screenshot
|
757
|
+
return unless example.exception
|
758
|
+
# ...
|
759
|
+
end
|
760
|
+
end
|
761
|
+
|
762
|
+
describe 'example page' do
|
763
|
+
include ScreenshotHelper
|
764
|
+
after { save_failure_screenshot }
|
765
|
+
let(:user) { User.find(example.metadata[:user_id]) }
|
766
|
+
# ...
|
767
|
+
end
|
768
|
+
|
769
|
+
# Converted
|
770
|
+
module ScreenshotHelper
|
771
|
+
def save_failure_screenshot
|
772
|
+
return unless RSpec.current_example.exception
|
773
|
+
# ...
|
774
|
+
end
|
775
|
+
end
|
776
|
+
|
777
|
+
describe 'example page' do
|
778
|
+
include ScreenshotHelper
|
779
|
+
after { save_failure_screenshot }
|
780
|
+
let(:user) { |example| User.find(example.metadata[:user_id]) }
|
781
|
+
# ...
|
782
|
+
end
|
783
|
+
```
|
784
|
+
|
785
|
+
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):
|
786
|
+
|
787
|
+
>`RSpec::Core::ExampleGroup#example` is deprecated and will be removed in RSpec 3. There are a few options for what you can use instead:
|
788
|
+
>
|
789
|
+
>- `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.
|
790
|
+
>- The current example is now exposed via `RSpec.current_example`, which is accessible from any context.
|
791
|
+
>- 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:
|
792
|
+
>
|
793
|
+
>```ruby
|
794
|
+
>RSpec.configure do |c|
|
795
|
+
> c.expose_current_running_example_as :example
|
796
|
+
>end
|
797
|
+
>```
|
798
|
+
|
799
|
+
---
|
800
|
+
|
801
|
+
* Conversion can be disabled by: `--keep deprecated`
|
802
|
+
* Deprecation: Deprecated since RSpec 2.99, removed in RSpec 3.0
|
803
|
+
* 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)
|
804
|
+
|
688
805
|
## Compatibility
|
689
806
|
|
690
807
|
Tested on MRI 1.9, MRI 2.0 and JRuby in 1.9 mode.
|
data/README.md.erb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# Transpec
|
4
4
|
|
5
|
-
**Transpec** automatically converts your specs
|
5
|
+
**Transpec** automatically converts your specs to the latest [RSpec](http://rspec.info/) syntax with static and dynamic code analysis.
|
6
6
|
|
7
7
|
This aims to facilitate smooth transition to RSpec 3, and it's now ready for RSpec 2.99 and 3.0 beta!
|
8
8
|
|
@@ -157,7 +157,7 @@ Skip dynamic analysis and convert with only static analysis. Note that specifyin
|
|
157
157
|
|
158
158
|
Specify command to run RSpec that is used for dynamic analysis.
|
159
159
|
|
160
|
-
Transpec needs to run your specs in copied project directory for dynamic analysis.
|
160
|
+
Transpec needs to run your specs in a copied project directory for dynamic analysis.
|
161
161
|
If your project requires some special setup or commands to run specs, use this option.
|
162
162
|
`bundle exec rspec` is used by default.
|
163
163
|
|
@@ -191,6 +191,7 @@ Type | Target Syntax | Converted Syntax
|
|
191
191
|
<%=
|
192
192
|
conversion_type_table = <<END
|
193
193
|
`should` | `obj.should matcher` | `expect(obj).to matcher`
|
194
|
+
`oneliner` | `it { should ... }` | `it { is_expected.to ... }`
|
194
195
|
`should_receive` | `obj.should_receive` | `expect(obj).to receive`
|
195
196
|
`stub` | `obj.stub` | `allow(obj).to receive`
|
196
197
|
`have_items` | `expect(obj).to have(x).items` | `expect(obj.size).to eq(x)`
|
@@ -227,7 +228,7 @@ $ transpec --negative-form to_not
|
|
227
228
|
|
228
229
|
### `-b/--boolean-matcher`
|
229
230
|
|
230
|
-
Specify matcher type that `be_true` and `be_false` will be converted to.
|
231
|
+
Specify a matcher type that `be_true` and `be_false` will be converted to.
|
231
232
|
Any of `truthy,falsey`, `truthy,falsy` or `true,false` can be specified.
|
232
233
|
`truthy,falsey` is used by default.
|
233
234
|
|
@@ -239,7 +240,7 @@ See [Supported Conversions - Boolean matchers](#boolean-matchers) for more detai
|
|
239
240
|
|
240
241
|
### `-p/--no-parentheses-matcher-arg`
|
241
242
|
|
242
|
-
Suppress parenthesizing
|
243
|
+
Suppress parenthesizing arguments of matchers when converting
|
243
244
|
`should` with operator matcher to `expect` with non-operator matcher
|
244
245
|
(the `expect` syntax does not directly support the operator matchers).
|
245
246
|
Note that it will be parenthesized even if this option is specified
|
@@ -293,7 +294,7 @@ Cannot convert #should into #expect since #expect is not available in the contex
|
|
293
294
|
spec/awesome_spec.rb:4: 1.should == 1
|
294
295
|
```
|
295
296
|
|
296
|
-
This message would be shown with specs like
|
297
|
+
This message would be shown with specs like:
|
297
298
|
|
298
299
|
```ruby
|
299
300
|
describe '#should that cannot be converted to #expect' do
|
@@ -353,6 +354,31 @@ expect(obj).to_not matcher # with `--negative-form to_not`
|
|
353
354
|
* Deprecation: Deprecated since RSpec 3.0
|
354
355
|
* See also: [Myron Marston » RSpec's New Expectation Syntax](http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax)
|
355
356
|
|
357
|
+
### One-liner expectations
|
358
|
+
|
359
|
+
**This conversion is available only if your project has `rspec` gem dependency `2.99.0.beta2` or later.**
|
360
|
+
|
361
|
+
```ruby
|
362
|
+
# Targets
|
363
|
+
it { should matcher }
|
364
|
+
it { should_not matcher }
|
365
|
+
|
366
|
+
# Converted
|
367
|
+
it { is_expected.to matcher }
|
368
|
+
it { is_expected.not_to matcher }
|
369
|
+
it { is_expected.to_not matcher } # with `--negative-form to_not`
|
370
|
+
```
|
371
|
+
|
372
|
+
`is_expected.to` is designed for the consistency with the `expect` syntax.
|
373
|
+
However the one-liner `should` is still _not_ deprecated in RSpec 3.0
|
374
|
+
and available even if the `should` syntax is disabled in `RSpec.configure`.
|
375
|
+
So if you think `is_expected.to` is verbose,
|
376
|
+
feel free to disable this conversion and continue using the one-liner `should`.
|
377
|
+
|
378
|
+
* Conversion can be disabled by: `--keep oneliner`
|
379
|
+
* Deprecation: Not deprecated
|
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)
|
381
|
+
|
356
382
|
### Operator matchers
|
357
383
|
|
358
384
|
```ruby
|
@@ -371,13 +397,13 @@ expect('string').to match(/^str/)
|
|
371
397
|
expect([1, 2, 3]).to match_array([2, 1, 3])
|
372
398
|
```
|
373
399
|
|
374
|
-
This conversion is combined with the conversion of [
|
400
|
+
This conversion is combined with the conversion of [standard expectations](#standard-expecatations) and cannot be disabled separately because the `expect` syntax does not directly support the operator matchers.
|
375
401
|
|
376
402
|
* See also: [(Almost) All Matchers Are Supported - RSpec's New Expectation Syntax](http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax#almost_all_matchers_are_supported)
|
377
403
|
|
378
404
|
### Boolean matchers
|
379
405
|
|
380
|
-
**This conversion is available only if your project has `rspec` gem dependency `2.99` or later.**
|
406
|
+
**This conversion is available only if your project has `rspec` gem dependency `2.99.0.beta1` or later.**
|
381
407
|
|
382
408
|
```ruby
|
383
409
|
# Targets
|
@@ -408,7 +434,7 @@ So, converting `be_true`/`be_false` to `be_truthy`/`be_falsey` never breaks your
|
|
408
434
|
---
|
409
435
|
|
410
436
|
* Conversion can be disabled by: `--keep deprecated`
|
411
|
-
* Deprecation: Deprecated since RSpec 2.99, removed
|
437
|
+
* Deprecation: Deprecated since RSpec 2.99, removed in RSpec 3.0
|
412
438
|
* 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)
|
413
439
|
|
414
440
|
### `be_close` matcher
|
@@ -422,7 +448,7 @@ expect(1.0 / 3.0).to be_within(0.001).of(0.333)
|
|
422
448
|
```
|
423
449
|
|
424
450
|
* Conversion can be disabled by: `--keep deprecated`
|
425
|
-
* Deprecation: Deprecated since RSpec 2.1, removed
|
451
|
+
* Deprecation: Deprecated since RSpec 2.1, removed in RSpec 3.0
|
426
452
|
* See also: [New be within matcher and RSpec.deprecate fix · rspec/rspec-expectations](https://github.com/rspec/rspec-expectations/pull/32)
|
427
453
|
|
428
454
|
### `have(n).items` matcher
|
@@ -455,7 +481,7 @@ expect(team.players.size).to eq(3)
|
|
455
481
|
expect(team.send(:players).size).to eq(3)
|
456
482
|
```
|
457
483
|
|
458
|
-
There's an option to continue using `have(n).items` matcher with [rspec-collection_matchers](https://github.com/rspec/rspec-collection_matchers) that is
|
484
|
+
There's an option to continue using `have(n).items` matcher with [rspec-collection_matchers](https://github.com/rspec/rspec-collection_matchers) that is a gem extracted from `rspec-expectations`.
|
459
485
|
If you choose so, disable this conversion by either:
|
460
486
|
|
461
487
|
* Specify `--keep have_items` option manually.
|
@@ -466,9 +492,35 @@ Note: `rspec-rails` 3.0 [still uses `have(n).items` matcher with `rspec-collecti
|
|
466
492
|
---
|
467
493
|
|
468
494
|
* Conversion can be disabled by: `--keep have_items`
|
469
|
-
* Deprecation: Deprecated since RSpec 2.99, removed
|
495
|
+
* Deprecation: Deprecated since RSpec 2.99, removed in RSpec 3.0
|
470
496
|
* 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)
|
471
497
|
|
498
|
+
### One-liner expectations with `have(n).items` matcher
|
499
|
+
|
500
|
+
**This conversion will be disabled automatically if `rspec-collection_matchers` or `rspec-rails` is loaded in your spec.**
|
501
|
+
|
502
|
+
```ruby
|
503
|
+
# Targets
|
504
|
+
it { should have(3).items }
|
505
|
+
it { should have_at_least(3).players }
|
506
|
+
|
507
|
+
# Converted
|
508
|
+
it 'has 3 items' do
|
509
|
+
expect(subject.size).to eq(3)
|
510
|
+
end
|
511
|
+
|
512
|
+
# With `--keep should`
|
513
|
+
it 'has 3 items' do
|
514
|
+
subject.size.should == 3
|
515
|
+
end
|
516
|
+
|
517
|
+
it 'has at least 3 players' do
|
518
|
+
expect(subject.players.size).to be >= 3
|
519
|
+
end
|
520
|
+
```
|
521
|
+
|
522
|
+
* Conversion can be disabled by: `--keep have_items`
|
523
|
+
|
472
524
|
### Expectations on block
|
473
525
|
|
474
526
|
```ruby
|
@@ -500,7 +552,7 @@ lambda { do_something }.should_not raise_error # with `--keep should`
|
|
500
552
|
```
|
501
553
|
|
502
554
|
* Conversion can be disabled by: `--keep deprecated`
|
503
|
-
* Deprecation: Deprecated since RSpec 2.14, removed
|
555
|
+
* Deprecation: Deprecated since RSpec 2.14, removed in RSpec 3.0
|
504
556
|
* See also: [Consider deprecating `expect { }.not_to raise_error(SpecificErrorClass)` · rspec/rspec-expectations](https://github.com/rspec/rspec-expectations/issues/231)
|
505
557
|
|
506
558
|
### Message expectations
|
@@ -538,7 +590,7 @@ Klass.any_instance.stub(:foo) # with `--keep stub`
|
|
538
590
|
```
|
539
591
|
|
540
592
|
* Conversion can be disabled by: `--keep deprecated`
|
541
|
-
* Deprecation: Deprecated since RSpec 2.14, removed
|
593
|
+
* Deprecation: Deprecated since RSpec 2.14, removed in RSpec 3.0
|
542
594
|
* See also: [Don't allow at_least(0) · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/133)
|
543
595
|
|
544
596
|
### Method stubs
|
@@ -546,29 +598,38 @@ Klass.any_instance.stub(:foo) # with `--keep stub`
|
|
546
598
|
```ruby
|
547
599
|
# Targets
|
548
600
|
obj.stub(:foo)
|
549
|
-
|
550
601
|
obj.stub!(:foo)
|
551
602
|
|
552
603
|
obj.stub(:foo => 1, :bar => 2)
|
553
604
|
|
605
|
+
obj.stub_chain(:foo, :bar, :baz)
|
606
|
+
|
554
607
|
Klass.any_instance.stub(:foo)
|
555
608
|
|
556
609
|
# Converted
|
557
610
|
allow(obj).to receive(:foo)
|
558
611
|
|
559
|
-
|
560
|
-
|
561
|
-
# If the target project's rspec gem dependency is prior to 3.0
|
612
|
+
# If the target project's rspec gem dependency is prior to 3.0.0.beta1
|
562
613
|
allow(obj).to receive(:foo).and_return(1)
|
563
614
|
allow(obj).to receive(:bar).and_return(2)
|
564
615
|
|
565
|
-
# If the target project's rspec gem dependency is 3.0 or later
|
616
|
+
# If the target project's rspec gem dependency is 3.0.0.beta1 or later
|
566
617
|
allow(obj).to receive_messages(:foo => 1, :bar => 2)
|
567
618
|
|
619
|
+
# Conversion from `stub_chain` to `receive_message_chain` is available
|
620
|
+
# only if the target project's rspec gem dependency is 2.99.0.beta2 or later
|
621
|
+
allow(obj).to receive_message_chain(:foo, :bar, :baz)
|
622
|
+
|
568
623
|
allow_any_instance_of(Klass).to receive(:foo)
|
569
624
|
```
|
570
625
|
|
571
|
-
|
626
|
+
#### No replacement for `unstub`
|
627
|
+
|
628
|
+
There's no replacement for `unstub` in the `expect` syntax. See [the discussion](https://github.com/rspec/rspec-mocks/issues/153#issuecomment-12208638) for more details.
|
629
|
+
|
630
|
+
#### Steps to upgrade `obj.stub(:foo => 1, :bar => 2)`
|
631
|
+
|
632
|
+
`allow(obj).to receive_messages(:foo => 1, :bar => 2)` that is designed to be the replacement for `obj.stub(:foo => 1, :bar => 2)` is available from RSpec 3.0 (though [it's now being considered to be backported to RSpec 2.99](https://github.com/rspec/rspec-mocks/issues/454)). So, in [the upgrade path to RSpec 3](http://myronmars.to/n/dev-blog/2013/07/the-plan-for-rspec-3#the_upgrade_path), if you want to convert them with keeping the syntax correspondence, you need to follow these steps:
|
572
633
|
|
573
634
|
1. Upgrade to RSpec 2.99
|
574
635
|
2. Run `transpec --keep stub`
|
@@ -598,7 +659,7 @@ obj.unstub(:foo)
|
|
598
659
|
```
|
599
660
|
|
600
661
|
* Conversion can be disabled by: `--keep deprecated`
|
601
|
-
* Deprecation: Deprecated since RSpec 2.14, removed
|
662
|
+
* Deprecation: Deprecated since RSpec 2.14, removed in RSpec 3.0
|
602
663
|
* See also: [Consider deprecating and/or removing #stub! and #unstub! at some point · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/122)
|
603
664
|
|
604
665
|
### Method stubs with deprecated specification of number of times
|
@@ -614,7 +675,7 @@ obj.stub(:foo) # with `--keep stub`
|
|
614
675
|
```
|
615
676
|
|
616
677
|
* Conversion can be disabled by: `--keep deprecated`
|
617
|
-
* Deprecation: Deprecated since RSpec 2.14, removed
|
678
|
+
* Deprecation: Deprecated since RSpec 2.14, removed in RSpec 3.0
|
618
679
|
* See also: [Don't allow at_least(0) · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/133)
|
619
680
|
|
620
681
|
### Deprecated test double aliases
|
@@ -629,7 +690,7 @@ double('something')
|
|
629
690
|
```
|
630
691
|
|
631
692
|
* Conversion can be disabled by: `--keep deprecated`
|
632
|
-
* Deprecation: Deprecated since RSpec 2.14, removed
|
693
|
+
* Deprecation: Deprecated since RSpec 2.14, removed in RSpec 3.0
|
633
694
|
* See also: [myronmarston / why_double.md - Gist](https://gist.github.com/myronmarston/6576665)
|
634
695
|
|
635
696
|
### Expectations on attribute of subject with `its`
|
@@ -653,7 +714,7 @@ END
|
|
653
714
|
<%= Transpec::Converter.new.convert(its_target) -%>
|
654
715
|
```
|
655
716
|
|
656
|
-
There's an option to continue using `its` with [rspec-its](https://github.com/rspec/rspec-its) that is
|
717
|
+
There's an option to continue using `its` with [rspec-its](https://github.com/rspec/rspec-its) that is a gem extracted from `rspec-core`.
|
657
718
|
If you choose so, disable this conversion by either:
|
658
719
|
|
659
720
|
* Specify `--keep its` option manually.
|
@@ -662,9 +723,60 @@ If you choose so, disable this conversion by either:
|
|
662
723
|
---
|
663
724
|
|
664
725
|
* Conversion can be disabled by: `--keep its`
|
665
|
-
* Deprecation: Deprecated since RSpec 2.99, removed
|
726
|
+
* Deprecation: Deprecated since RSpec 2.99, removed in RSpec 3.0
|
666
727
|
* 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)
|
667
728
|
|
729
|
+
### Current example object
|
730
|
+
|
731
|
+
**This conversion is available only if your project has `rspec` gem dependency `2.99.0.beta1` or later.**
|
732
|
+
|
733
|
+
```ruby
|
734
|
+
# Targets
|
735
|
+
<%=
|
736
|
+
example_target = <<END
|
737
|
+
module ScreenshotHelper
|
738
|
+
def save_failure_screenshot
|
739
|
+
return unless example.exception
|
740
|
+
# ...
|
741
|
+
end
|
742
|
+
end
|
743
|
+
|
744
|
+
describe 'example page' do
|
745
|
+
include ScreenshotHelper
|
746
|
+
after { save_failure_screenshot }
|
747
|
+
let(:user) { User.find(example.metadata[:user_id]) }
|
748
|
+
# ...
|
749
|
+
end
|
750
|
+
END
|
751
|
+
-%>
|
752
|
+
|
753
|
+
# Converted
|
754
|
+
<%=
|
755
|
+
rspec_version = Transpec::RSpecVersion.new('2.99')
|
756
|
+
Transpec::Converter.new(nil, rspec_version).convert(example_target)
|
757
|
+
-%>
|
758
|
+
```
|
759
|
+
|
760
|
+
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):
|
761
|
+
|
762
|
+
>`RSpec::Core::ExampleGroup#example` is deprecated and will be removed in RSpec 3. There are a few options for what you can use instead:
|
763
|
+
>
|
764
|
+
>- `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.
|
765
|
+
>- The current example is now exposed via `RSpec.current_example`, which is accessible from any context.
|
766
|
+
>- 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:
|
767
|
+
>
|
768
|
+
>```ruby
|
769
|
+
>RSpec.configure do |c|
|
770
|
+
> c.expose_current_running_example_as :example
|
771
|
+
>end
|
772
|
+
>```
|
773
|
+
|
774
|
+
---
|
775
|
+
|
776
|
+
* Conversion can be disabled by: `--keep deprecated`
|
777
|
+
* Deprecation: Deprecated since RSpec 2.99, removed in RSpec 3.0
|
778
|
+
* 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)
|
779
|
+
|
668
780
|
## Compatibility
|
669
781
|
|
670
782
|
Tested on MRI 1.9, MRI 2.0 and JRuby in 1.9 mode.
|