rails5-spec-converter 1.0.18 → 1.0.19
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8ed726d17eeded2ad212304686feb640a5a87e0
|
4
|
+
data.tar.gz: 5c3b38ee09a37981a347ff0e88fa432edf4f60f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3526ec24e89a2ede5ba18da2cf814a23578f062f1206de35befae62fd49a35f2ce0a8d2b2a87f5ff1856cab5c3598e21c3dac1869f2586de9347c98622c0457d
|
7
|
+
data.tar.gz: 990cf71407cdf8017c3299b9639176cdd54056cc47e981cbcac027c3e7bf3482b7c2fca8bc5873c0a72c44b3a6a89abdd91a41564c3868896c8a2634d18acccb
|
data/README.md
CHANGED
@@ -124,9 +124,9 @@ becomes
|
|
124
124
|
post :users, params: {user: {name: 'bayleef'}}
|
125
125
|
```
|
126
126
|
|
127
|
-
|
127
|
+
* `--no-hash-spacing` will force hashes to be written **without** extra whitespace in all files regardless of context.
|
128
128
|
|
129
|
-
|
129
|
+
* `--hash-spacing` will force hashes to be written **with** extra whitespace in all files regardless of context.
|
130
130
|
|
131
131
|
## Development
|
132
132
|
|
@@ -136,6 +136,9 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
136
136
|
|
137
137
|
Bug reports and pull requests are welcome on GitHub at https://github.com/tjgrathwell/rails5-spec-converter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
138
138
|
|
139
|
+
## Contact
|
140
|
+
|
141
|
+
If this Gem helped you out at all, or it didn't help because you wanted it to do something different or it broke all your computer code, please let me know on twitter [@tjgrathwell](http://twitter.com/tjgrathwell)
|
139
142
|
|
140
143
|
## License
|
141
144
|
|
@@ -32,8 +32,8 @@ module Rails5
|
|
32
32
|
@options.strategy = strategy.to_sym
|
33
33
|
end
|
34
34
|
|
35
|
-
opts.on("--warn-if-ambiguous", "Emit warnings when hash parameters are unknowable (see README)") do |
|
36
|
-
@options.warn_if_ambiguous =
|
35
|
+
opts.on("--warn-if-ambiguous", "Emit warnings when hash parameters are unknowable (see README)") do |warn_if_ambiguous|
|
36
|
+
@options.warn_if_ambiguous = warn_if_ambiguous
|
37
37
|
end
|
38
38
|
end.parse!
|
39
39
|
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'parser/current'
|
2
|
+
require 'astrolabe/builder'
|
3
|
+
|
4
|
+
module Rails5
|
5
|
+
module SpecConverter
|
6
|
+
class TestTypeIdentifier
|
7
|
+
DIRECTORY_TO_TYPE_MAP = {
|
8
|
+
'controllers' => :controller,
|
9
|
+
'requests' => :request,
|
10
|
+
'integration' => :request,
|
11
|
+
'api' => :request
|
12
|
+
}
|
13
|
+
|
14
|
+
def initialize(content, options = TextTransformerOptions.new)
|
15
|
+
@options = options
|
16
|
+
@content = content
|
17
|
+
|
18
|
+
@source_buffer = Parser::Source::Buffer.new('(string)')
|
19
|
+
@source_buffer.source = @content
|
20
|
+
|
21
|
+
ast_builder = Astrolabe::Builder.new
|
22
|
+
@parser = Parser::CurrentRuby.new(ast_builder)
|
23
|
+
|
24
|
+
@source_rewriter = Parser::Source::Rewriter.new(@source_buffer)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_type
|
28
|
+
test_type_from_content || test_type_from_filename || test_type_default
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def test_type_default
|
34
|
+
:request
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_type_from_content
|
38
|
+
root_node = @parser.parse(@source_buffer)
|
39
|
+
root_node.each_node(:send) do |node|
|
40
|
+
target, method, test_name, params = node.children
|
41
|
+
next unless target.nil? || target == :RSpec
|
42
|
+
next unless method == :describe
|
43
|
+
|
44
|
+
return type_from_params_hash(params)
|
45
|
+
end
|
46
|
+
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_type_from_filename
|
51
|
+
return nil unless @options.file_path
|
52
|
+
|
53
|
+
dirs = @options.file_path.split('/')
|
54
|
+
spec_folder_index = dirs.index('spec')
|
55
|
+
return nil unless spec_folder_index
|
56
|
+
DIRECTORY_TO_TYPE_MAP[dirs[spec_folder_index + 1]]
|
57
|
+
end
|
58
|
+
|
59
|
+
def type_from_params_hash(params)
|
60
|
+
return nil unless params && params.hash_type?
|
61
|
+
|
62
|
+
params.children.each do |node|
|
63
|
+
if node.pair_type? && node.children.all?(&:sym_type?)
|
64
|
+
key, value = node.children.map { |sym| sym.children.first }
|
65
|
+
return :controller if key == :type && value == :controller
|
66
|
+
return :request if key == :type && value == :request
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'parser/current'
|
2
2
|
require 'astrolabe/builder'
|
3
|
+
require 'rails5/spec_converter/test_type_identifier'
|
3
4
|
require 'rails5/spec_converter/text_transformer_options'
|
4
5
|
require 'rails5/spec_converter/hash_rewriter'
|
5
6
|
|
@@ -62,7 +63,7 @@ module Rails5
|
|
62
63
|
handle_ambiguous_method_call!(node)
|
63
64
|
end
|
64
65
|
|
65
|
-
|
66
|
+
wrap_extra_positional_args!(args) if args.length > 1
|
66
67
|
end
|
67
68
|
|
68
69
|
@source_rewriter.process
|
@@ -142,6 +143,16 @@ module Rails5
|
|
142
143
|
hash_node.children.any? { |pair| pair.children[0].children[0] == key }
|
143
144
|
end
|
144
145
|
|
146
|
+
def wrap_extra_positional_args!(args)
|
147
|
+
if test_type == :controller
|
148
|
+
wrap_arg(args[1], 'session') if args[1]
|
149
|
+
wrap_arg(args[2], 'flash') if args[2]
|
150
|
+
end
|
151
|
+
if test_type == :request
|
152
|
+
wrap_arg(args[1], 'headers') if args[1]
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
145
156
|
def wrap_arg(node, key)
|
146
157
|
node_loc = node.loc.expression
|
147
158
|
node_source = node_loc.source
|
@@ -161,6 +172,10 @@ module Rails5
|
|
161
172
|
node.loc.expression.source_line.match(/^(\s*)/)[1]
|
162
173
|
end
|
163
174
|
|
175
|
+
def test_type
|
176
|
+
@test_type ||= TestTypeIdentifier.new(@content, @options).test_type
|
177
|
+
end
|
178
|
+
|
164
179
|
def log(str)
|
165
180
|
return if @options.quiet?
|
166
181
|
|
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.19
|
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-
|
11
|
+
date: 2016-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- lib/rails5/spec_converter/cli.rb
|
119
119
|
- lib/rails5/spec_converter/hash_rewriter.rb
|
120
120
|
- lib/rails5/spec_converter/node_textifier.rb
|
121
|
+
- lib/rails5/spec_converter/test_type_identifier.rb
|
121
122
|
- lib/rails5/spec_converter/text_transformer.rb
|
122
123
|
- lib/rails5/spec_converter/text_transformer_options.rb
|
123
124
|
- lib/rails5/spec_converter/version.rb
|