transpec 0.0.4 → 0.0.5
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 +4 -0
- data/CHANGELOG.md +4 -0
- data/README.md +15 -0
- data/README.md.erb +15 -0
- data/Rakefile +42 -7
- data/lib/transpec/rewriter.rb +9 -1
- data/lib/transpec/syntax/any_number_of_timesable.rb +42 -0
- data/lib/transpec/syntax/expectizable.rb +8 -2
- data/lib/transpec/syntax/method_stub.rb +2 -1
- data/lib/transpec/syntax/should_receive.rb +34 -27
- data/lib/transpec/version.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/transpec/cli_spec.rb +4 -4
- data/spec/transpec/rewriter_spec.rb +307 -126
- data/spec/transpec/syntax/be_close_spec.rb +19 -17
- data/spec/transpec/syntax/matcher_spec.rb +6 -6
- data/spec/transpec/syntax/method_stub_spec.rb +98 -18
- data/spec/transpec/syntax/should_receive_spec.rb +128 -8
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9855e40cab5a33c95ac0c45e62ba2c8a166d1176
|
4
|
+
data.tar.gz: 1984df95dd4b3c84eedf68b93096f5b28b63ae83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 888b7c747f4f36905ebd892b72f391de1d25afa26b22b00c61d74634afdf88ab4ef70c90204d47412c896839d07f34ed3e0f9f9187e6e0e24d073f0529cf2969
|
7
|
+
data.tar.gz: 7d6df84751dcae9b33ec2f9a755207b22e7e0eaa99993d01e46fac69643dd278954b3dbc6f0aa02055a673a7011342f94b158ba26bf91b430beecaa48393ad27
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
## Master
|
4
4
|
|
5
|
+
## v0.0.5
|
6
|
+
|
7
|
+
* Support conversion of `any_number_of_times`
|
8
|
+
|
5
9
|
## v0.0.4
|
6
10
|
|
7
11
|
* Fix a bug where necessary parentheses were not added when converting operator matcher to non-operator matcher in some cases (e.g. `== (2 - 1) + (1 + 2)` was converted into `eq(2 - 1) + (1 + 2)` unintentionally)
|
data/README.md
CHANGED
@@ -123,6 +123,21 @@ After the conversion, run `rspec` again and check if all pass.
|
|
123
123
|
|
124
124
|
## Options
|
125
125
|
|
126
|
+
### `--force`
|
127
|
+
|
128
|
+
Force processing even if the current Git repository is not clean.
|
129
|
+
|
130
|
+
```bash
|
131
|
+
$ git status --short
|
132
|
+
M spec/spec_helper.rb
|
133
|
+
$ transpec
|
134
|
+
The current Git repository is not clean. Aborting.
|
135
|
+
$ transpec --force
|
136
|
+
Processing spec/spec_helper.rb
|
137
|
+
Processing spec/spec_spec.rb
|
138
|
+
Processing spec/support/file_helper.rb
|
139
|
+
```
|
140
|
+
|
126
141
|
### `-d/--disable`
|
127
142
|
|
128
143
|
Disable specific conversions.
|
data/README.md.erb
CHANGED
@@ -96,6 +96,21 @@ After the conversion, run `rspec` again and check if all pass.
|
|
96
96
|
|
97
97
|
## Options
|
98
98
|
|
99
|
+
### `--force`
|
100
|
+
|
101
|
+
Force processing even if the current Git repository is not clean.
|
102
|
+
|
103
|
+
```bash
|
104
|
+
$ git status --short
|
105
|
+
M spec/spec_helper.rb
|
106
|
+
$ transpec
|
107
|
+
The current Git repository is not clean. Aborting.
|
108
|
+
$ transpec --force
|
109
|
+
Processing spec/spec_helper.rb
|
110
|
+
Processing spec/spec_spec.rb
|
111
|
+
Processing spec/support/file_helper.rb
|
112
|
+
```
|
113
|
+
|
99
114
|
### `-d/--disable`
|
100
115
|
|
101
116
|
Disable specific conversions.
|
data/Rakefile
CHANGED
@@ -54,9 +54,11 @@ namespace :test do
|
|
54
54
|
projects.each do |name, url, ref, bundler_args|
|
55
55
|
desc "Test Transpec on #{name.to_s.capitalize} project"
|
56
56
|
task name do
|
57
|
-
|
57
|
+
tmpdir = 'tmp'
|
58
58
|
|
59
|
-
Dir.
|
59
|
+
Dir.mkdir(tmpdir) unless Dir.exist?(tmpdir)
|
60
|
+
|
61
|
+
Dir.chdir(tmpdir) do
|
60
62
|
test_on_project(name.to_s.capitalize, url, ref, bundler_args)
|
61
63
|
end
|
62
64
|
end
|
@@ -67,13 +69,9 @@ namespace :test do
|
|
67
69
|
|
68
70
|
puts " Testing on #{name} Project ".center(80, '=')
|
69
71
|
|
70
|
-
|
71
|
-
sh "git clone --no-checkout --depth 1 --branch #{ref} #{url}"
|
72
|
-
|
73
|
-
repo_dir = File.basename(url, '.git')
|
72
|
+
repo_dir = prepare_git_repo(url, ref)
|
74
73
|
|
75
74
|
Dir.chdir(repo_dir) do
|
76
|
-
sh "git checkout --quiet #{ref}"
|
77
75
|
with_clean_bundler_env do
|
78
76
|
sh "bundle install #{bundler_args}"
|
79
77
|
sh File.join(Transpec.root, 'bin', 'transpec')
|
@@ -82,6 +80,43 @@ namespace :test do
|
|
82
80
|
end
|
83
81
|
end
|
84
82
|
|
83
|
+
def prepare_git_repo(url, ref)
|
84
|
+
repo_dir = File.basename(url, '.git')
|
85
|
+
|
86
|
+
needs_clone = false
|
87
|
+
|
88
|
+
if Dir.exist?(repo_dir)
|
89
|
+
current_ref = nil
|
90
|
+
|
91
|
+
Dir.chdir(repo_dir) do
|
92
|
+
current_ref = `git describe --all`.chomp.sub(/\Aheads\//, '')
|
93
|
+
end
|
94
|
+
|
95
|
+
if current_ref == ref
|
96
|
+
Dir.chdir(repo_dir) do
|
97
|
+
sh 'git reset --hard'
|
98
|
+
end
|
99
|
+
else
|
100
|
+
require 'fileutils'
|
101
|
+
FileUtils.rm_rf(repo_dir)
|
102
|
+
needs_clone = true
|
103
|
+
end
|
104
|
+
else
|
105
|
+
needs_clone = true
|
106
|
+
end
|
107
|
+
|
108
|
+
if needs_clone
|
109
|
+
# Disabling checkout here to suppress "detached HEAD" warning.
|
110
|
+
sh "git clone --no-checkout --depth 1 --branch #{ref} #{url}"
|
111
|
+
|
112
|
+
Dir.chdir(repo_dir) do
|
113
|
+
sh "git checkout --quiet #{ref}"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
repo_dir
|
118
|
+
end
|
119
|
+
|
85
120
|
def with_clean_bundler_env
|
86
121
|
if defined?(Bundler)
|
87
122
|
Bundler.with_clean_env do
|
data/lib/transpec/rewriter.rb
CHANGED
@@ -99,7 +99,13 @@ module Transpec
|
|
99
99
|
|
100
100
|
def process_should_receive(should_receive)
|
101
101
|
if @configuration.convert_to_expect_to_receive?
|
102
|
-
should_receive.
|
102
|
+
if should_receive.any_number_of_times? && @configuration.replace_deprecated_method?
|
103
|
+
should_receive.allowize_any_number_of_times!(@configuration.negative_form_of_to)
|
104
|
+
else
|
105
|
+
should_receive.expectize!(@configuration.negative_form_of_to)
|
106
|
+
end
|
107
|
+
elsif should_receive.any_number_of_times? && @configuration.replace_deprecated_method?
|
108
|
+
should_receive.stubize_any_number_of_times!
|
103
109
|
end
|
104
110
|
end
|
105
111
|
|
@@ -113,6 +119,8 @@ module Transpec
|
|
113
119
|
elsif @configuration.replace_deprecated_method?
|
114
120
|
method_stub.replace_deprecated_method!
|
115
121
|
end
|
122
|
+
|
123
|
+
method_stub.remove_any_number_of_times! if @configuration.replace_deprecated_method?
|
116
124
|
end
|
117
125
|
|
118
126
|
def process_be_close(be_close)
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'transpec/syntax'
|
4
|
+
|
5
|
+
module Transpec
|
6
|
+
class Syntax
|
7
|
+
module AnyNumberOfTimesable
|
8
|
+
def any_number_of_times?
|
9
|
+
!any_number_of_times_node.nil?
|
10
|
+
end
|
11
|
+
|
12
|
+
def remove_any_number_of_times!
|
13
|
+
return unless any_number_of_times?
|
14
|
+
|
15
|
+
map = any_number_of_times_node.loc
|
16
|
+
dot_any_number_of_times_range = map.dot.join(map.selector)
|
17
|
+
remove(dot_any_number_of_times_range)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def any_number_of_times_node
|
23
|
+
each_following_chained_method_node do |chained_node|
|
24
|
+
method_name = chained_node.children[1]
|
25
|
+
return chained_node if method_name == :any_number_of_times
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def each_following_chained_method_node
|
30
|
+
return to_enum(__method__) unless block_given?
|
31
|
+
|
32
|
+
@ancestor_nodes.reverse.reduce(@node) do |child_node, parent_node|
|
33
|
+
return unless [:send, :block].include?(parent_node.type)
|
34
|
+
return unless parent_node.children.first == child_node
|
35
|
+
yield parent_node, child_node
|
36
|
+
parent_node
|
37
|
+
end
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -9,10 +9,16 @@ module Transpec
|
|
9
9
|
include SendNodeSyntax
|
10
10
|
|
11
11
|
def wrap_subject_in_expect!
|
12
|
+
wrap_subject_with_method!('expect')
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def wrap_subject_with_method!(method)
|
12
18
|
if Util.in_parentheses?(subject_node)
|
13
|
-
insert_before(subject_range,
|
19
|
+
insert_before(subject_range, method)
|
14
20
|
else
|
15
|
-
insert_before(subject_range,
|
21
|
+
insert_before(subject_range, "#{method}(")
|
16
22
|
insert_after(subject_range, ')')
|
17
23
|
end
|
18
24
|
end
|
@@ -2,13 +2,14 @@
|
|
2
2
|
|
3
3
|
require 'transpec/syntax'
|
4
4
|
require 'transpec/syntax/any_instanceable'
|
5
|
+
require 'transpec/syntax/any_number_of_timesable'
|
5
6
|
require 'transpec/util'
|
6
7
|
require 'English'
|
7
8
|
|
8
9
|
module Transpec
|
9
10
|
class Syntax
|
10
11
|
class MethodStub < Syntax
|
11
|
-
include AnyInstanceable, Util
|
12
|
+
include AnyInstanceable, AnyNumberOfTimesable, Util
|
12
13
|
|
13
14
|
def allowize!
|
14
15
|
# There's no way of unstubbing in #allow syntax.
|
@@ -3,25 +3,46 @@
|
|
3
3
|
require 'transpec/syntax'
|
4
4
|
require 'transpec/syntax/expectizable'
|
5
5
|
require 'transpec/syntax/any_instanceable'
|
6
|
+
require 'transpec/syntax/any_number_of_timesable'
|
6
7
|
|
7
8
|
module Transpec
|
8
9
|
class Syntax
|
9
10
|
class ShouldReceive < Syntax
|
10
|
-
include Expectizable, AnyInstanceable
|
11
|
+
include Expectizable, AnyInstanceable, AnyNumberOfTimesable
|
11
12
|
|
12
13
|
def positive?
|
13
14
|
method_name == :should_receive
|
14
15
|
end
|
15
16
|
|
16
17
|
def expectize!(negative_form = 'not_to')
|
18
|
+
convert_to_syntax!('expect', negative_form)
|
19
|
+
end
|
20
|
+
|
21
|
+
def allowize_any_number_of_times!(negative_form = 'not_to')
|
22
|
+
return unless any_number_of_times?
|
23
|
+
|
24
|
+
convert_to_syntax!('allow', negative_form)
|
25
|
+
remove_any_number_of_times!
|
26
|
+
end
|
27
|
+
|
28
|
+
def stubize_any_number_of_times!(negative_form = 'not_to')
|
29
|
+
return unless any_number_of_times?
|
30
|
+
|
31
|
+
replace(selector_range, 'stub')
|
32
|
+
remove_any_number_of_times!
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def convert_to_syntax!(syntax, negative_form)
|
17
38
|
unless in_example_group_context?
|
18
|
-
fail NotInExampleGroupContextError.new(expression_range, "##{method_name}",
|
39
|
+
fail NotInExampleGroupContextError.new(expression_range, "##{method_name}", "##{syntax}")
|
19
40
|
end
|
20
41
|
|
21
42
|
if any_instance?
|
22
43
|
wrap_class_in_expect_any_instance_of!
|
23
44
|
else
|
24
|
-
|
45
|
+
wrap_subject_with_method!(syntax)
|
25
46
|
end
|
26
47
|
|
27
48
|
replace(selector_range, "#{positive? ? 'to' : negative_form} receive")
|
@@ -40,8 +61,6 @@ module Transpec
|
|
40
61
|
end
|
41
62
|
end
|
42
63
|
|
43
|
-
private
|
44
|
-
|
45
64
|
def self.target_receiver_node?(node)
|
46
65
|
!node.nil?
|
47
66
|
end
|
@@ -60,7 +79,7 @@ module Transpec
|
|
60
79
|
def broken_block_nodes
|
61
80
|
@broken_block_nodes ||= [
|
62
81
|
block_node_taken_by_with_method_with_no_normal_args,
|
63
|
-
|
82
|
+
block_node_following_message_expectation_method
|
64
83
|
].compact.uniq
|
65
84
|
end
|
66
85
|
|
@@ -76,20 +95,12 @@ module Transpec
|
|
76
95
|
# (args
|
77
96
|
# (arg :block_arg)) nil)
|
78
97
|
def block_node_taken_by_with_method_with_no_normal_args
|
79
|
-
|
80
|
-
|
81
|
-
return nil unless
|
82
|
-
|
83
|
-
|
84
|
-
return nil unless child_node.children[1] == :with
|
85
|
-
return nil if child_node.children[2]
|
86
|
-
return parent_node
|
87
|
-
end
|
88
|
-
|
89
|
-
parent_node
|
98
|
+
each_following_chained_method_node do |chained_node, child_node|
|
99
|
+
next unless chained_node.type == :block
|
100
|
+
return nil unless child_node.children[1] == :with
|
101
|
+
return nil if child_node.children[2]
|
102
|
+
return chained_node
|
90
103
|
end
|
91
|
-
|
92
|
-
nil
|
93
104
|
end
|
94
105
|
|
95
106
|
# subject.should_receive(:method_name) do |block_arg|
|
@@ -102,15 +113,11 @@ module Transpec
|
|
102
113
|
# (sym :method_name))
|
103
114
|
# (args
|
104
115
|
# (arg :block_arg)) nil) :once)
|
105
|
-
def
|
106
|
-
|
107
|
-
|
108
|
-
return
|
109
|
-
return child_node if child_node.type == :block && parent_node.type == :send
|
110
|
-
parent_node
|
116
|
+
def block_node_following_message_expectation_method
|
117
|
+
each_following_chained_method_node do |chained_node, child_node|
|
118
|
+
next unless chained_node.type == :send
|
119
|
+
return child_node if child_node.type == :block
|
111
120
|
end
|
112
|
-
|
113
|
-
nil
|
114
121
|
end
|
115
122
|
end
|
116
123
|
end
|
data/lib/transpec/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/transpec/cli_spec.rb
CHANGED
@@ -164,7 +164,7 @@ module Transpec
|
|
164
164
|
context "when #{cli_type.inspect} is specified" do
|
165
165
|
let(:args) { ['--disable', cli_type] }
|
166
166
|
|
167
|
-
it "sets
|
167
|
+
it "sets Configuration##{config_attr} false" do
|
168
168
|
cli.parse_options(args)
|
169
169
|
cli.configuration.send(config_attr).should be_false
|
170
170
|
end
|
@@ -197,7 +197,7 @@ module Transpec
|
|
197
197
|
context "when #{form.inspect} is specified" do
|
198
198
|
let(:args) { ['--negative-form', form] }
|
199
199
|
|
200
|
-
it "sets
|
200
|
+
it "sets Configuration#negative_form_of_to? #{form.inspect}" do
|
201
201
|
cli.parse_options(args)
|
202
202
|
cli.configuration.negative_form_of_to.should == form
|
203
203
|
end
|
@@ -208,7 +208,7 @@ module Transpec
|
|
208
208
|
describe '-p/--no-parentheses-matcher-arg option' do
|
209
209
|
let(:args) { ['--no-parentheses-matcher-arg'] }
|
210
210
|
|
211
|
-
it 'sets
|
211
|
+
it 'sets Configuration#parenthesize_matcher_arg? false' do
|
212
212
|
cli.parse_options(args)
|
213
213
|
cli.configuration.parenthesize_matcher_arg.should be_false
|
214
214
|
end
|
@@ -282,7 +282,7 @@ module Transpec
|
|
282
282
|
context 'when a directory path is passed' do
|
283
283
|
let(:paths) { ['dir'] }
|
284
284
|
|
285
|
-
it 'returns file paths with .rb extension in the directory' do
|
285
|
+
it 'returns file paths with .rb extension in the directory recursively' do
|
286
286
|
should == ['dir/file.rb']
|
287
287
|
end
|
288
288
|
end
|