rails5-spec-converter 1.0.20 → 1.0.21
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/README.md +7 -3
 - data/lib/rails5/spec_converter/cli.rb +1 -1
 - data/lib/rails5/spec_converter/hash_rewriter.rb +11 -8
 - data/lib/rails5/spec_converter/test_type_identifier.rb +12 -3
 - data/lib/rails5/spec_converter/text_transformer.rb +1 -1
 - data/lib/rails5/spec_converter/version.rb +1 -1
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 2b243c703f835ef357017c5dd87464e345b44dca
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: a1acb2cea1494ccbcc37e7fcb3988d2924be9b5b
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 1cbaa53a1fcd05235f7cbd8e940879307e908003fbd8f83c0021fd338fdea0384d0456b743eb89c21fb4b335304beebfd59855ba92a3a2c0f80370fbf8658821
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: b6be580cefc1bd2bd3acea6624463d325285e17ed46f8fb728189199133f66938c059e672533686136ae988ece1aca658802f298e24dce9cc36d35b8f9add2b9
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # Rails5 
     | 
| 
      
 1 
     | 
    
         
            +
            # Rails5 Spec Converter
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            [](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  
     | 
| 
      
 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 
     | 
    
         
            -
               
     | 
| 
      
 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.
         
     | 
| 
         @@ -1,8 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'rails5/spec_converter/node_textifier'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            class HashRewriter
         
     | 
| 
       4 
     | 
    
         
            -
               
     | 
| 
       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  
     | 
| 
      
 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  
     | 
| 
      
 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") 
     | 
| 
      
 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 
     | 
| 
      
 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 
     | 
    
         
            -
                     
     | 
| 
       55 
     | 
    
         
            -
                    return nil unless  
     | 
| 
       56 
     | 
    
         
            -
                    DIRECTORY_TO_TYPE_MAP[dirs[ 
     | 
| 
      
 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 =  
     | 
| 
      
 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) }",
         
     |