rails5-spec-converter 1.0.20 → 1.0.21

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: c39727a6db3accd9728ab2c8bfa6d815f643a4a8
4
- data.tar.gz: 9e5417f24316cc7e52e641a9326300a53076b860
3
+ metadata.gz: 2b243c703f835ef357017c5dd87464e345b44dca
4
+ data.tar.gz: a1acb2cea1494ccbcc37e7fcb3988d2924be9b5b
5
5
  SHA512:
6
- metadata.gz: 567c6d0ce3b8cb2ba351c66016cfca5b48237bb1a1320b75db87d422b8b666cf8bc0eeb20f16afa850a95da025b94445b58b366b9295e2c45f373dcb8baa294f
7
- data.tar.gz: 1d24dea46469e77d819a67351601b004ac25ed9b4ef5fe53cefa241e2a5e27cdbcdffdd73c471746490a4a1148215a9b81fbc75d651787bf4200bde3546fee4c
6
+ metadata.gz: 1cbaa53a1fcd05235f7cbd8e940879307e908003fbd8f83c0021fd338fdea0384d0456b743eb89c21fb4b335304beebfd59855ba92a3a2c0f80370fbf8658821
7
+ data.tar.gz: b6be580cefc1bd2bd3acea6624463d325285e17ed46f8fb728189199133f66938c059e672533686136ae988ece1aca658802f298e24dce9cc36d35b8f9add2b9
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Rails5::SpecConverter
1
+ # Rails5 Spec Converter
2
2
 
3
3
  [![Build Status](https://travis-ci.org/tjgrathwell/rails5-spec-converter.svg?branch=master)](https://travis-ci.org/tjgrathwell/rails5-spec-converter)
4
4
 
@@ -33,7 +33,7 @@ Make sure you've committed everything to Git first, then
33
33
  $ cd some-project
34
34
  $ rails5-spec-converter
35
35
 
36
- This will update all the files in that directory matching the glob `spec/**/*_spec.rb`. It should be idempotent.
36
+ This will update all the files in that directory matching the globs `spec/**/*_spec.rb` or `test/**/*_test.rb`.
37
37
 
38
38
  If you want to specify a specific set of files instead, you can run `rails5-spec-converter path_to_my_files`.
39
39
 
@@ -76,7 +76,7 @@ even though `format` should be **outside** the params hash.
76
76
  format: :json
77
77
  }
78
78
 
79
- _inner, _outer = all_the_params.partition { |k,v| %i{session flash method body xhr format}.include?(k) }.map { |a| Hash[a] }
79
+ _outer, _inner = all_the_params.partition { |k,v| %i{format}.include?(k) }.map { |a| Hash[a] }
80
80
  get :users, _outer.merge(params: _inner)
81
81
  ```
82
82
 
@@ -128,6 +128,10 @@ post :users, params: {user: {name: 'bayleef'}}
128
128
 
129
129
  * `--hash-spacing` will force hashes to be written **with** extra whitespace in all files regardless of context.
130
130
 
131
+ ## Compatibility
132
+
133
+ It **should** work for both RSpec and MiniTest, but who really knows?
134
+
131
135
  ## Development
132
136
 
133
137
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -41,7 +41,7 @@ module Rails5
41
41
  end
42
42
 
43
43
  def run
44
- paths = @files.length > 0 ? @files : ["spec/**/*_spec.rb"]
44
+ paths = @files.length > 0 ? @files : ["spec/**/*_spec.rb", "test/**/*_test.rb"]
45
45
 
46
46
  paths.each do |path|
47
47
  Dir.glob(path) do |file_path|
@@ -1,8 +1,7 @@
1
1
  require 'rails5/spec_converter/node_textifier'
2
2
 
3
3
  class HashRewriter
4
- # technically format is special
5
- ALLOWED_KWARG_KEYS = %i(params session flash method body xhr format)
4
+ OUTSIDE_PARAMS_KEYS = %i(format)
6
5
 
7
6
  attr_reader :hash_node, :original_indent
8
7
 
@@ -97,7 +96,7 @@ class HashRewriter
97
96
  hash_node.children.each do |pair|
98
97
  key = pair.children[0].children[0]
99
98
 
100
- if ALLOWED_KWARG_KEYS.include?(key)
99
+ if OUTSIDE_PARAMS_KEYS.include?(key)
101
100
  @pairs_that_belong_outside_params << pair
102
101
  else
103
102
  @pairs_that_belong_in_params << pair
@@ -138,11 +137,11 @@ class HashRewriter
138
137
  value_str_lines[1].match(/^(\s*)/)[1].sub(original_indent, '')
139
138
  end
140
139
 
141
- def additional_indent(hash_node)
140
+ def should_indent_restrung_content?(hash_node)
142
141
  return nil if indent_before_first_pair(hash_node)
143
142
 
144
143
  joiner = first_joiner_between_pairs
145
- joiner && joiner.include?("\n") ? @options.indent : nil
144
+ joiner && joiner.include?("\n")
146
145
  end
147
146
 
148
147
  def existing_indent(hash_node)
@@ -188,14 +187,18 @@ class HashRewriter
188
187
 
189
188
  def appropriately_indented_params_hash(pairs:)
190
189
  outer_indent = existing_indent(hash_node)
191
- middle_indent = indent_of_first_value_if_multiline(hash_node)
192
- inner_indent = additional_indent(hash_node)
193
190
 
194
191
  restrung_hash = restring_hash(
195
192
  pairs,
196
- indent: outer_indent + (inner_indent || ''),
193
+ indent: outer_indent,
197
194
  joiner: ",\n"
198
195
  )
196
+
197
+ if should_indent_restrung_content?(hash_node)
198
+ restrung_hash = add_indent(restrung_hash, @options.indent)
199
+ end
200
+
201
+ middle_indent = indent_of_first_value_if_multiline(hash_node)
199
202
  if middle_indent
200
203
  restrung_hash = original_indent + add_indent(restrung_hash, middle_indent)
201
204
  end
@@ -36,6 +36,15 @@ module Rails5
36
36
 
37
37
  def test_type_from_content
38
38
  root_node = @parser.parse(@source_buffer)
39
+ root_node.each_node(:class) do |node|
40
+ class_const_node, superclass_const_node = node.children
41
+ next unless superclass_const_node && superclass_const_node.const_type?
42
+
43
+ superclass_str = superclass_const_node.loc.expression.source
44
+ return :controller if superclass_str == "ActionController::TestCase"
45
+ return :request if superclass_str == "ActionDispatch::IntegrationTest"
46
+ end
47
+
39
48
  root_node.each_node(:send) do |node|
40
49
  target, method, test_name, params = node.children
41
50
  next unless target.nil? || target == :RSpec
@@ -51,9 +60,9 @@ module Rails5
51
60
  return nil unless @options.file_path
52
61
 
53
62
  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]]
63
+ folder_index = dirs.index('spec') || dirs.index('test')
64
+ return nil unless folder_index
65
+ DIRECTORY_TO_TYPE_MAP[dirs[folder_index + 1]]
57
66
  end
58
67
 
59
68
  def type_from_params_hash(params)
@@ -86,7 +86,7 @@ module Rails5
86
86
  end
87
87
 
88
88
  if @options.uglify_ambiguous_params?
89
- keys = (HashRewriter::ALLOWED_KWARG_KEYS - [:params]).join(' ')
89
+ keys = HashRewriter::OUTSIDE_PARAMS_KEYS.join(' ')
90
90
  partition_clause = [
91
91
  @textifier.node_to_string(args[0]),
92
92
  "partition { |k,v| %i{#{keys}}.include?(k) }",
@@ -1,5 +1,5 @@
1
1
  module Rails5
2
2
  module SpecConverter
3
- VERSION = "1.0.20"
3
+ VERSION = "1.0.21"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails5-spec-converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.20
4
+ version: 1.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Grathwell