rails5-spec-converter 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rails5/spec_converter/text_transformer.rb +42 -27
- data/lib/rails5/spec_converter/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a87dd8dccefd54232cff542938557421517353d6
|
4
|
+
data.tar.gz: b32a003889fef8fbb189461e52fd3296318f8396
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2d0dd74529daee5d8c96a2a48c99290b70d4b64d3c50539a8f9a078a5e5dafdea2827904230a78ea846850e838c7d8b57dd662a2bc0229ab8c093936cd55fa1
|
7
|
+
data.tar.gz: 1a6b4ed2701cca74c3263336ab88d6c6d2c4fda8dd59cc6bb74bbd7dbb0ed390012212e16da3486a9fce385955a234e7552bc4a5a10fb1984c5b916658a9740b
|
@@ -23,36 +23,51 @@ module Rails5
|
|
23
23
|
|
24
24
|
root_node = parser.parse(source_buffer)
|
25
25
|
root_node.each_node(:send) do |node|
|
26
|
-
target, verb, action,
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
26
|
+
target, verb, action, *args = node.children
|
27
|
+
next unless args.length > 0
|
28
|
+
next unless target.nil? && HTTP_VERBS.include?(verb)
|
29
|
+
|
30
|
+
first_argument = args.first
|
31
|
+
if args.length == 1 && !first_argument.hash_type?
|
32
|
+
source_rewriter.replace(
|
33
|
+
first_argument.loc.expression,
|
34
|
+
"params: #{first_argument.loc.expression.source}"
|
35
|
+
)
|
36
|
+
next
|
37
|
+
end
|
38
|
+
|
39
|
+
if first_argument.hash_type?
|
40
|
+
hash_node = first_argument
|
41
|
+
|
42
|
+
pairs_that_belong_in_params = []
|
43
|
+
pairs_that_belong_outside_params = []
|
44
|
+
|
45
|
+
hash_node.children.each do |pair|
|
46
|
+
key = pair.children[0].children[0]
|
47
|
+
|
48
|
+
if ALLOWED_KWARG_KEYS.include?(key)
|
49
|
+
pairs_that_belong_outside_params << pair
|
50
|
+
else
|
51
|
+
pairs_that_belong_in_params << pair
|
42
52
|
end
|
53
|
+
end
|
54
|
+
|
55
|
+
if pairs_that_belong_in_params.length == 0 && pairs_that_belong_outside_params.length == 0
|
56
|
+
source_rewriter.replace(hash_node.loc.expression, 'params: {}')
|
57
|
+
next
|
58
|
+
end
|
59
|
+
|
60
|
+
curly_sep = hash_node.parent.loc.expression.source.match(/{\S/) ? '' : ' '
|
43
61
|
|
44
|
-
|
45
|
-
|
46
|
-
if
|
47
|
-
rewritten_hashes
|
48
|
-
if pairs_that_belong_outside_params.length > 0
|
49
|
-
rewritten_hashes << restring_hash(pairs_that_belong_outside_params)
|
50
|
-
end
|
51
|
-
source_rewriter.replace(
|
52
|
-
hash_node.loc.expression,
|
53
|
-
rewritten_hashes.join(', ')
|
54
|
-
)
|
62
|
+
if pairs_that_belong_in_params.length > 0
|
63
|
+
rewritten_hashes = ["params: {#{curly_sep}#{restring_hash(pairs_that_belong_in_params)}#{curly_sep}}"]
|
64
|
+
if pairs_that_belong_outside_params.length > 0
|
65
|
+
rewritten_hashes << restring_hash(pairs_that_belong_outside_params)
|
55
66
|
end
|
67
|
+
source_rewriter.replace(
|
68
|
+
hash_node.loc.expression,
|
69
|
+
rewritten_hashes.join(', ')
|
70
|
+
)
|
56
71
|
end
|
57
72
|
end
|
58
73
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails5-spec-converter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis Grathwell
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
139
|
version: '0'
|
140
140
|
requirements: []
|
141
141
|
rubyforge_project:
|
142
|
-
rubygems_version: 2.5
|
142
|
+
rubygems_version: 2.4.5
|
143
143
|
signing_key:
|
144
144
|
specification_version: 4
|
145
145
|
summary: A tool to upgrade Rails 4-style specs to Rails 5-style
|