transpec 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +4 -0
- data/README.md +66 -25
- data/README.md.erb +65 -24
- data/lib/transpec/cli.rb +2 -1
- data/lib/transpec/configuration.rb +1 -0
- data/lib/transpec/converter.rb +7 -1
- data/lib/transpec/option_parser.rb +15 -1
- data/lib/transpec/syntax/have.rb +2 -13
- data/lib/transpec/syntax/method_stub.rb +7 -17
- data/lib/transpec/syntax/mixin/any_instance_block.rb +14 -0
- data/lib/transpec/syntax/mixin/owned_matcher.rb +27 -0
- data/lib/transpec/syntax/receive.rb +2 -13
- data/lib/transpec/syntax/rspec_configure.rb +8 -2
- data/lib/transpec/syntax/rspec_configure/expectations.rb +1 -1
- data/lib/transpec/syntax/rspec_configure/framework.rb +114 -105
- data/lib/transpec/syntax/rspec_configure/mocks.rb +1 -1
- data/lib/transpec/syntax/should_receive.rb +17 -37
- data/lib/transpec/util.rb +6 -0
- data/lib/transpec/version.rb +1 -1
- data/spec/transpec/configuration_spec.rb +1 -0
- data/spec/transpec/converter_spec.rb +61 -5
- data/spec/transpec/option_parser_spec.rb +9 -0
- data/spec/transpec/syntax/have_spec.rb +3 -3
- data/spec/transpec/syntax/method_stub_spec.rb +42 -10
- data/spec/transpec/syntax/oneliner_should_spec.rb +12 -12
- data/spec/transpec/syntax/raise_error_spec.rb +5 -5
- data/spec/transpec/syntax/receive_spec.rb +4 -4
- data/spec/transpec/syntax/rspec_configure_spec.rb +1 -1
- data/spec/transpec/syntax/should_receive_spec.rb +13 -13
- data/tasks/readme.rake +2 -1
- data/transpec.gemspec +1 -1
- metadata +11 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1947cf230f025d55b5b315662b49e4a0c6807199
|
4
|
+
data.tar.gz: 674a547e1df20db31651518199adc63889ae78b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff571e89b51badd2ad5ba7d26beef1651ec37686597653e4e647e4c6931aebf36090269f0e2eeea8081813f7d8fe3579523c817fdc260c0fa9b1b6af241eea7a
|
7
|
+
data.tar.gz: a5d24e1e775928e1e412d415faeaa62dd6fceb7c0a93589b49bf6c723c2a625d9f686d51d498d707e2d76c2b76f944430a261c05bda4fee6216f45ac8ddc1993
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
## Development
|
4
4
|
|
5
|
+
## v1.8.0
|
6
|
+
|
7
|
+
* Conversion of `obj.stub(:message => value)` to `allow(obj).to receive(:message).and_return(value)` is now opt-in with `-t/--convert-stub-with-hash` option when `receive_messages` is unavailable
|
8
|
+
|
5
9
|
## v1.7.0
|
6
10
|
|
7
11
|
* Support conversion of `any_instance` block
|
data/README.md
CHANGED
@@ -43,7 +43,7 @@ describe Account do
|
|
43
43
|
describe '#renew' do
|
44
44
|
context 'when the account is renewable and not closed' do
|
45
45
|
before do
|
46
|
-
account.stub(:
|
46
|
+
account.stub(:closed?).and_return(false)
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'does not raise error' do
|
@@ -79,7 +79,6 @@ describe Account do
|
|
79
79
|
describe '#renew' do
|
80
80
|
context 'when the account is renewable and not closed' do
|
81
81
|
before do
|
82
|
-
allow(account).to receive(:renewable?).and_return(true)
|
83
82
|
allow(account).to receive(:closed?).and_return(false)
|
84
83
|
end
|
85
84
|
|
@@ -145,7 +144,7 @@ After the conversion, run `rspec` again and check whether everything is green:
|
|
145
144
|
$ bundle exec rspec
|
146
145
|
```
|
147
146
|
|
148
|
-
If it's green, commit the changes with an auto-generated message
|
147
|
+
If it's green, commit the changes with an auto-generated message that describes the conversion summary:
|
149
148
|
|
150
149
|
```bash
|
151
150
|
$ git commit -aeF .git/COMMIT_EDITMSG
|
@@ -270,6 +269,14 @@ Note that this is not same as `--keep deprecated` since this configures `yield_r
|
|
270
269
|
|
271
270
|
See [Supported Conversions - `any_instance` implementation blocks](#any_instance-implementation-blocks) for more details.
|
272
271
|
|
272
|
+
### `-t/--convert-stub-with-hash`
|
273
|
+
|
274
|
+
Enable conversion of `obj.stub(:message => value)` to `allow(obj).to receive(:message).and_return(value)` when `receive_messages(:message => value)` is unavailable (prior to RSpec 3.0).
|
275
|
+
It will be converted to multiple statements if the hash includes multiple pairs.
|
276
|
+
This conversion is disabled by default.
|
277
|
+
|
278
|
+
See [Supported Conversions - Method stubs with a hash argument](#method-stubs-with-a-hash-argument) for more details.
|
279
|
+
|
273
280
|
### `-p/--no-parentheses-matcher-arg`
|
274
281
|
|
275
282
|
Suppress parenthesizing arguments of matchers when converting
|
@@ -401,6 +408,27 @@ The one-liner (implicit receiver) `should`:
|
|
401
408
|
|
402
409
|
## Supported Conversions
|
403
410
|
|
411
|
+
* [Standard expectations](#standard-expectations)
|
412
|
+
* [One-liner expectations](#one-liner-expectations)
|
413
|
+
* [Operator matchers](#operator-matchers)
|
414
|
+
* [Boolean matchers](#boolean-matchers)
|
415
|
+
* [`be_close` matcher](#be_close-matcher)
|
416
|
+
* [`have(n).items` matcher](#havenitems-matcher)
|
417
|
+
* [One-liner expectations with `have(n).items` matcher](#one-liner-expectations-with-havenitems-matcher)
|
418
|
+
* [Expectations on block](#expectations-on-block)
|
419
|
+
* [Negative error expectations with specific error](#negative-error-expectations-with-specific-error)
|
420
|
+
* [Message expectations](#message-expectations)
|
421
|
+
* [Message expectations that are actually method stubs](#message-expectations-that-are-actually-method-stubs)
|
422
|
+
* [Method stubs](#method-stubs)
|
423
|
+
* [Method stubs with a hash argument](#method-stubs-with-a-hash-argument)
|
424
|
+
* [Deprecated method stub aliases](#deprecated-method-stub-aliases)
|
425
|
+
* [Method stubs with deprecated specification of number of times](#method-stubs-with-deprecated-specification-of-number-of-times)
|
426
|
+
* [`any_instance` implementation blocks](#any_instance-implementation-blocks)
|
427
|
+
* [Deprecated test double aliases](#deprecated-test-double-aliases)
|
428
|
+
* [Expectations on attribute of subject with `its`](#expectations-on-attribute-of-subject-with-its)
|
429
|
+
* [Current example object](#current-example-object)
|
430
|
+
* [Custom matcher DSL](#custom-matcher-dsl)
|
431
|
+
|
404
432
|
### Standard expectations
|
405
433
|
|
406
434
|
Targets:
|
@@ -709,8 +737,6 @@ Targets:
|
|
709
737
|
obj.stub(:foo)
|
710
738
|
obj.stub!(:foo)
|
711
739
|
|
712
|
-
obj.stub(:foo => 1, :bar => 2)
|
713
|
-
|
714
740
|
obj.stub_chain(:foo, :bar, :baz)
|
715
741
|
|
716
742
|
Klass.any_instance.stub(:foo)
|
@@ -721,13 +747,6 @@ Will be converted to:
|
|
721
747
|
```ruby
|
722
748
|
allow(obj).to receive(:foo)
|
723
749
|
|
724
|
-
# If the target project's RSpec is prior to 3.0.0.beta1
|
725
|
-
allow(obj).to receive(:foo).and_return(1)
|
726
|
-
allow(obj).to receive(:bar).and_return(2)
|
727
|
-
|
728
|
-
# If the target project's RSpec is 3.0.0.beta1 or later
|
729
|
-
allow(obj).to receive_messages(:foo => 1, :bar => 2)
|
730
|
-
|
731
750
|
# Conversion from `stub_chain` to `receive_message_chain` is available
|
732
751
|
# only if the target project's RSpec is 3.0.0.beta2 (not yet released) or later
|
733
752
|
allow(obj).to receive_message_chain(:foo, :bar, :baz)
|
@@ -735,29 +754,51 @@ allow(obj).to receive_message_chain(:foo, :bar, :baz)
|
|
735
754
|
allow_any_instance_of(Klass).to receive(:foo)
|
736
755
|
```
|
737
756
|
|
738
|
-
#### No replacement for `unstub`
|
739
|
-
|
740
757
|
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.
|
741
758
|
|
742
|
-
|
759
|
+
* This conversion can be disabled by: `--keep stub`
|
760
|
+
* Deprecation: deprecated since RSpec 3.0
|
761
|
+
* See also:
|
762
|
+
* [RSpec's new message expectation syntax - Tea is awesome.](http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/)
|
763
|
+
* [Bring back stub_chain (receive_message_chain) · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/464)
|
764
|
+
|
765
|
+
### Method stubs with a hash argument
|
743
766
|
|
744
|
-
|
767
|
+
Targets:
|
768
|
+
|
769
|
+
```ruby
|
770
|
+
obj.stub(:foo => 1, :bar => 2)
|
771
|
+
```
|
772
|
+
|
773
|
+
Will be converted to:
|
774
|
+
|
775
|
+
```ruby
|
776
|
+
# If the target project's RSpec is 3.0.0.beta1 or later
|
777
|
+
allow(obj).to receive_messages(:foo => 1, :bar => 2)
|
778
|
+
|
779
|
+
# If the target project's RSpec is prior to 3.0.0.beta1
|
780
|
+
obj.stub(:foo => 1, :bar => 2) # No conversion
|
781
|
+
|
782
|
+
# If the target project's RSpec is prior to 3.0.0.beta1
|
783
|
+
# and `--convert-stub-with-hash` is specified
|
784
|
+
allow(obj).to receive(:foo).and_return(1)
|
785
|
+
allow(obj).to receive(:bar).and_return(2)
|
786
|
+
```
|
787
|
+
|
788
|
+
`allow(obj).to receive_messages(:foo => 1, :bar => 2)` which is designed to be the replacement for `obj.stub(:foo => 1, :bar => 2)` is available from RSpec 3.0.
|
789
|
+
|
790
|
+
So, if you're going to use Transpec in [the upgrade path to RSpec 3](http://myronmars.to/n/dev-blog/2013/07/the-plan-for-rspec-3#the_upgrade_path), you may need to follow these steps:
|
745
791
|
|
746
792
|
1. Upgrade to RSpec 2.99
|
747
|
-
2. Run `transpec
|
793
|
+
2. Run `transpec` (at this time `obj.stub(:message => value)` won't be converted)
|
748
794
|
3. Upgrade to RSpec 3.0
|
749
|
-
4. Run `transpec`
|
795
|
+
4. Run `transpec` again to convert `obj.stub(:message => value)`
|
750
796
|
|
751
|
-
|
752
|
-
|
753
|
-
---
|
797
|
+
Or if you're going to stay RSpec 2.14 for now but want to convert all `stub` to `allow` statements, run `transpec` with `--convert-stub-with-hash` option. Note that once the conversion is done, multiple statements cannot be merged into a `receive_messages`.
|
754
798
|
|
755
799
|
* This conversion can be disabled by: `--keep stub`
|
756
800
|
* Deprecation: deprecated since RSpec 3.0
|
757
|
-
* See also:
|
758
|
-
* [RSpec's new message expectation syntax - Tea is awesome.](http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/)
|
759
|
-
* [allow receive with multiple methods · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/368)
|
760
|
-
* [Bring back stub_chain (receive_message_chain) · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/464)
|
801
|
+
* See also: [allow receive with multiple methods · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/368)
|
761
802
|
|
762
803
|
### Deprecated method stub aliases
|
763
804
|
|
data/README.md.erb
CHANGED
@@ -45,7 +45,7 @@ describe Account do
|
|
45
45
|
describe '#renew' do
|
46
46
|
context 'when the account is renewable and not closed' do
|
47
47
|
before do
|
48
|
-
account.stub(:
|
48
|
+
account.stub(:closed?).and_return(false)
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'does not raise error' do
|
@@ -118,7 +118,7 @@ After the conversion, run `rspec` again and check whether everything is green:
|
|
118
118
|
$ bundle exec rspec
|
119
119
|
```
|
120
120
|
|
121
|
-
If it's green, commit the changes with an auto-generated message
|
121
|
+
If it's green, commit the changes with an auto-generated message that describes the conversion summary:
|
122
122
|
|
123
123
|
```bash
|
124
124
|
$ git commit -aeF .git/COMMIT_EDITMSG
|
@@ -261,6 +261,14 @@ Note that this is not same as `--keep deprecated` since this configures `yield_r
|
|
261
261
|
|
262
262
|
See [Supported Conversions - `any_instance` implementation blocks](#any_instance-implementation-blocks) for more details.
|
263
263
|
|
264
|
+
### `-t/--convert-stub-with-hash`
|
265
|
+
|
266
|
+
Enable conversion of `obj.stub(:message => value)` to `allow(obj).to receive(:message).and_return(value)` when `receive_messages(:message => value)` is unavailable (prior to RSpec 3.0).
|
267
|
+
It will be converted to multiple statements if the hash includes multiple pairs.
|
268
|
+
This conversion is disabled by default.
|
269
|
+
|
270
|
+
See [Supported Conversions - Method stubs with a hash argument](#method-stubs-with-a-hash-argument) for more details.
|
271
|
+
|
264
272
|
### `-p/--no-parentheses-matcher-arg`
|
265
273
|
|
266
274
|
Suppress parenthesizing arguments of matchers when converting
|
@@ -397,6 +405,26 @@ The one-liner (implicit receiver) `should`:
|
|
397
405
|
|
398
406
|
## Supported Conversions
|
399
407
|
|
408
|
+
<%=
|
409
|
+
|
410
|
+
sections = text.each_line.slice_before(/^## /)
|
411
|
+
|
412
|
+
supported_conversion_section = sections.find do |section|
|
413
|
+
section.first.include?('Supported Conversions')
|
414
|
+
end
|
415
|
+
|
416
|
+
titles = supported_conversion_section.map do |line|
|
417
|
+
next unless line.start_with?('### ')
|
418
|
+
line.sub(/^[#\s]*/, '').chomp
|
419
|
+
end.compact
|
420
|
+
|
421
|
+
titles.map do |title|
|
422
|
+
anchor = '#' + title.gsub(/[^\w_\- ]/, '').downcase.gsub(' ', '-')
|
423
|
+
"* [#{title}](#{anchor})"
|
424
|
+
end.join("\n")
|
425
|
+
|
426
|
+
%>
|
427
|
+
|
400
428
|
### Standard expectations
|
401
429
|
|
402
430
|
Targets:
|
@@ -705,8 +733,6 @@ Targets:
|
|
705
733
|
obj.stub(:foo)
|
706
734
|
obj.stub!(:foo)
|
707
735
|
|
708
|
-
obj.stub(:foo => 1, :bar => 2)
|
709
|
-
|
710
736
|
obj.stub_chain(:foo, :bar, :baz)
|
711
737
|
|
712
738
|
Klass.any_instance.stub(:foo)
|
@@ -717,13 +743,6 @@ Will be converted to:
|
|
717
743
|
```ruby
|
718
744
|
allow(obj).to receive(:foo)
|
719
745
|
|
720
|
-
# If the target project's RSpec is prior to <%= Transpec::RSpecVersion.receive_messages_available_version %>
|
721
|
-
allow(obj).to receive(:foo).and_return(1)
|
722
|
-
allow(obj).to receive(:bar).and_return(2)
|
723
|
-
|
724
|
-
# If the target project's RSpec is <%= Transpec::RSpecVersion.receive_messages_available_version %> or later
|
725
|
-
allow(obj).to receive_messages(:foo => 1, :bar => 2)
|
726
|
-
|
727
746
|
# Conversion from `stub_chain` to `receive_message_chain` is available
|
728
747
|
# only if the target project's RSpec is <%= Transpec::RSpecVersion.receive_message_chain_available_version %> (not yet released) or later
|
729
748
|
allow(obj).to receive_message_chain(:foo, :bar, :baz)
|
@@ -731,29 +750,51 @@ allow(obj).to receive_message_chain(:foo, :bar, :baz)
|
|
731
750
|
allow_any_instance_of(Klass).to receive(:foo)
|
732
751
|
```
|
733
752
|
|
734
|
-
#### No replacement for `unstub`
|
735
|
-
|
736
753
|
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.
|
737
754
|
|
738
|
-
|
755
|
+
* This conversion can be disabled by: `--keep stub`
|
756
|
+
* Deprecation: deprecated since RSpec 3.0
|
757
|
+
* See also:
|
758
|
+
* [RSpec's new message expectation syntax - Tea is awesome.](http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/)
|
759
|
+
* [Bring back stub_chain (receive_message_chain) · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/464)
|
760
|
+
|
761
|
+
### Method stubs with a hash argument
|
762
|
+
|
763
|
+
Targets:
|
764
|
+
|
765
|
+
```ruby
|
766
|
+
obj.stub(:foo => 1, :bar => 2)
|
767
|
+
```
|
768
|
+
|
769
|
+
Will be converted to:
|
770
|
+
|
771
|
+
```ruby
|
772
|
+
# If the target project's RSpec is <%= Transpec::RSpecVersion.receive_messages_available_version %> or later
|
773
|
+
allow(obj).to receive_messages(:foo => 1, :bar => 2)
|
774
|
+
|
775
|
+
# If the target project's RSpec is prior to <%= Transpec::RSpecVersion.receive_messages_available_version %>
|
776
|
+
obj.stub(:foo => 1, :bar => 2) # No conversion
|
777
|
+
|
778
|
+
# If the target project's RSpec is prior to <%= Transpec::RSpecVersion.receive_messages_available_version %>
|
779
|
+
# and `--convert-stub-with-hash` is specified
|
780
|
+
allow(obj).to receive(:foo).and_return(1)
|
781
|
+
allow(obj).to receive(:bar).and_return(2)
|
782
|
+
```
|
739
783
|
|
740
|
-
`allow(obj).to receive_messages(:foo => 1, :bar => 2)` which is designed to be the replacement for `obj.stub(:foo => 1, :bar => 2)` is available from RSpec 3.0
|
784
|
+
`allow(obj).to receive_messages(:foo => 1, :bar => 2)` which is designed to be the replacement for `obj.stub(:foo => 1, :bar => 2)` is available from RSpec 3.0.
|
785
|
+
|
786
|
+
So, if you're going to use Transpec in [the upgrade path to RSpec 3](http://myronmars.to/n/dev-blog/2013/07/the-plan-for-rspec-3#the_upgrade_path), you may need to follow these steps:
|
741
787
|
|
742
788
|
1. Upgrade to RSpec 2.99
|
743
|
-
2. Run `transpec
|
789
|
+
2. Run `transpec` (at this time `obj.stub(:message => value)` won't be converted)
|
744
790
|
3. Upgrade to RSpec 3.0
|
745
|
-
4. Run `transpec`
|
746
|
-
|
747
|
-
Otherwise `obj.stub(:foo => 1, :bar => 2)` will be converted to two `allow(obj).to receive(...).and_return(...)` expressions on RSpec 2.99.
|
791
|
+
4. Run `transpec` again to convert `obj.stub(:message => value)`
|
748
792
|
|
749
|
-
|
793
|
+
Or if you're going to stay RSpec 2.14 for now but want to convert all `stub` to `allow` statements, run `transpec` with `--convert-stub-with-hash` option. Note that once the conversion is done, multiple statements cannot be merged into a `receive_messages`.
|
750
794
|
|
751
795
|
* This conversion can be disabled by: `--keep stub`
|
752
796
|
* Deprecation: deprecated since RSpec 3.0
|
753
|
-
* See also:
|
754
|
-
* [RSpec's new message expectation syntax - Tea is awesome.](http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/)
|
755
|
-
* [allow receive with multiple methods · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/368)
|
756
|
-
* [Bring back stub_chain (receive_message_chain) · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/464)
|
797
|
+
* See also: [allow receive with multiple methods · rspec/rspec-mocks](https://github.com/rspec/rspec-mocks/issues/368)
|
757
798
|
|
758
799
|
### Deprecated method stub aliases
|
759
800
|
|
data/lib/transpec/cli.rb
CHANGED
@@ -9,6 +9,7 @@ require 'transpec/option_parser'
|
|
9
9
|
require 'transpec/project'
|
10
10
|
require 'transpec/report'
|
11
11
|
require 'rainbow'
|
12
|
+
require 'rainbow/ext/string' unless String.method_defined?(:color)
|
12
13
|
|
13
14
|
module Transpec
|
14
15
|
class CLI
|
@@ -111,7 +112,7 @@ module Transpec
|
|
111
112
|
Git.write_commit_message(commit_message.to_s)
|
112
113
|
|
113
114
|
puts
|
114
|
-
puts 'A commit message
|
115
|
+
puts 'A commit message that describes the conversion summary was generated to'.color(:cyan)
|
115
116
|
puts '.git/COMMIT_EDITMSG. To use the message, type the following command for'.color(:cyan)
|
116
117
|
puts 'the next commit:'.color(:cyan)
|
117
118
|
puts ' git commit -eF .git/COMMIT_EDITMSG'
|
@@ -16,6 +16,7 @@ module Transpec
|
|
16
16
|
[:convert_deprecated_method, true],
|
17
17
|
[:parenthesize_matcher_arg, true],
|
18
18
|
[:add_receiver_arg_to_any_instance_implementation_block, true],
|
19
|
+
[:convert_stub_with_hash_to_stub_and_return, false],
|
19
20
|
[:forced, false],
|
20
21
|
[:skip_dynamic_analysis, false]
|
21
22
|
].freeze
|
data/lib/transpec/converter.rb
CHANGED
@@ -111,7 +111,13 @@ module Transpec
|
|
111
111
|
|
112
112
|
def process_method_stub(method_stub)
|
113
113
|
if @configuration.convert_stub?
|
114
|
-
method_stub.
|
114
|
+
if !method_stub.hash_arg? ||
|
115
|
+
@rspec_version.receive_messages_available? ||
|
116
|
+
@configuration.convert_stub_with_hash_to_stub_and_return?
|
117
|
+
method_stub.allowize!(@rspec_version)
|
118
|
+
elsif @configuration.convert_deprecated_method?
|
119
|
+
method_stub.convert_deprecated_method!
|
120
|
+
end
|
115
121
|
elsif @configuration.convert_deprecated_method?
|
116
122
|
method_stub.convert_deprecated_method!
|
117
123
|
end
|
@@ -5,6 +5,7 @@ require 'transpec/git'
|
|
5
5
|
require 'transpec/version'
|
6
6
|
require 'optparse'
|
7
7
|
require 'rainbow'
|
8
|
+
require 'rainbow/ext/string' unless String.respond_to?(:color)
|
8
9
|
|
9
10
|
# rubocop:disable ClassLength
|
10
11
|
|
@@ -86,6 +87,10 @@ module Transpec
|
|
86
87
|
@configuration.add_receiver_arg_to_any_instance_implementation_block = false
|
87
88
|
end
|
88
89
|
|
90
|
+
define_option('-t', '--convert-stub-with-hash') do
|
91
|
+
@configuration.convert_stub_with_hash_to_stub_and_return = true
|
92
|
+
end
|
93
|
+
|
89
94
|
define_option('-p', '--no-parentheses-matcher-arg') do
|
90
95
|
@configuration.parenthesize_matcher_arg = false
|
91
96
|
end
|
@@ -162,6 +167,15 @@ module Transpec
|
|
162
167
|
"#{'any_instance'.underline} implementation blocks as the",
|
163
168
|
'first block argument.'
|
164
169
|
],
|
170
|
+
'-t' => [
|
171
|
+
"Enable conversion of #{'obj.stub(:msg => val)'.underline} to",
|
172
|
+
"#{'allow(obj).to receive(:msg).and_return(val)'.underline}",
|
173
|
+
"when #{'receive_messages(:msg => val)'.underline} is",
|
174
|
+
'unavailable (prior to RSpec 3.0). It will be',
|
175
|
+
'converted to multiple statements if the hash',
|
176
|
+
'includes multiple pairs. This conversion is',
|
177
|
+
'disabled by default.'
|
178
|
+
],
|
165
179
|
'-p' => [
|
166
180
|
'Suppress parenthesizing arguments of matchers',
|
167
181
|
"when converting #{'should'.underline} with operator matcher",
|
@@ -190,7 +204,7 @@ module Transpec
|
|
190
204
|
args.reject do |arg|
|
191
205
|
case arg
|
192
206
|
when '-m', '--generate-commit-message'
|
193
|
-
warn 'DEPRECATION: -m/--generate-commit-message option is deprecated. '
|
207
|
+
warn 'DEPRECATION: -m/--generate-commit-message option is deprecated. ' \
|
194
208
|
'A commit message will always be generated.'
|
195
209
|
true
|
196
210
|
else
|
data/lib/transpec/syntax/have.rb
CHANGED
@@ -2,11 +2,12 @@
|
|
2
2
|
|
3
3
|
require 'transpec/syntax'
|
4
4
|
require 'transpec/syntax/mixin/send'
|
5
|
+
require 'transpec/syntax/mixin/owned_matcher'
|
5
6
|
|
6
7
|
module Transpec
|
7
8
|
class Syntax
|
8
9
|
class Have < Syntax
|
9
|
-
include Mixin::Send
|
10
|
+
include Mixin::Send, Mixin::OwnedMatcher
|
10
11
|
|
11
12
|
# String#count is not query method, and there's no way to determine
|
12
13
|
# whether a method is query method.
|
@@ -19,10 +20,6 @@ module Transpec
|
|
19
20
|
|
20
21
|
attr_reader :expectation
|
21
22
|
|
22
|
-
def self.standalone?
|
23
|
-
false
|
24
|
-
end
|
25
|
-
|
26
23
|
def self.target_method?(have_node, items_method_name)
|
27
24
|
return false unless have_node
|
28
25
|
have_receiver_node, have_method_name, *_ = *have_node
|
@@ -30,14 +27,6 @@ module Transpec
|
|
30
27
|
[:have, :have_exactly, :have_at_least, :have_at_most].include?(have_method_name)
|
31
28
|
end
|
32
29
|
|
33
|
-
def initialize(node, expectation, source_rewriter = nil, runtime_data = nil, report = nil)
|
34
|
-
@node = node
|
35
|
-
@expectation = expectation
|
36
|
-
@source_rewriter = source_rewriter
|
37
|
-
@runtime_data = runtime_data
|
38
|
-
@report = report || Report.new
|
39
|
-
end
|
40
|
-
|
41
30
|
add_dynamic_analysis_request do |rewriter|
|
42
31
|
DynamicInspector.register_request(self, rewriter)
|
43
32
|
end
|