rails5-spec-converter 1.0.5 → 1.0.6

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: f063f02a538854ce40ba052bee57619976d13984
4
- data.tar.gz: 2953c939e47421e564bb1c38009b25c7e55eab57
3
+ metadata.gz: 75759003b02014251aae8a73ba90520b0e449412
4
+ data.tar.gz: 90d16a171d1f9b20561f213611f34f0e6c7720dc
5
5
  SHA512:
6
- metadata.gz: caec295f2a297a1f7041d8cddb3129555f4ff20b886ae1ccf5baf85bd512008daca842885b608fae1ac0df2ff35ab92d3cfd1bd64d2db8e29e6631098d5c9ba6
7
- data.tar.gz: 38bd4a4c918a0cb108d20c3b7f120eac19caeae42bdfd31e0b79bed40d49cb4d84973110632707966e65b422e47a2b7bbea9f6fd900c031f4b70eb41255175aa
6
+ metadata.gz: 81753ebe7dd82067d0972ed3457f152f4461df3fc934573a3befbbb5dfe81d8481142f2f6ca21cf7900ce6101f39e870843e64e282ff46a59c8859b3e6557d64
7
+ data.tar.gz: 3a5e61d1fa027f4cba47220ba0b54222c0df770e655f586eaa89a59d88c864ecb3ac7ad7b5163e34c472588662ceb1031c553f4650963d0636997d93feb41893
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Rails5::SpecConverter
2
2
 
3
+ [![Build Status](https://travis-ci.org/tjgrathwell/rails5-spec-converter.svg?branch=master)](https://travis-ci.org/tjgrathwell/rails5-spec-converter)
4
+
3
5
  A script that fixes the syntax of your tests so Rails 5 will like them better. Inspired by [transpec](https://github.com/yujinakayama/transpec), the RSpec 2 -> 3 syntax conversion tool.
4
6
 
5
7
  If you write a test like this:
@@ -1,4 +1,5 @@
1
1
  require 'rails5/spec_converter/text_transformer'
2
+ require 'rails5/spec_converter/version'
2
3
  require 'optparse'
3
4
 
4
5
  module Rails5
@@ -9,6 +10,11 @@ module Rails5
9
10
  OptionParser.new do |opts|
10
11
  opts.banner = "Usage: rails5-spec-converter [options] [files]"
11
12
 
13
+ opts.on("--version", "Print version number") do |q|
14
+ puts Rails5::SpecConverter::VERSION
15
+ exit
16
+ end
17
+
12
18
  opts.on("-q", "--quiet", "Run quietly") do |q|
13
19
  @options[:quiet] = q
14
20
  end
@@ -95,7 +95,23 @@ module Rails5
95
95
  end
96
96
  end
97
97
 
98
+ def indent_before_first_pair(hash_node)
99
+ return nil unless hash_node.children.length > 0
100
+
101
+ text_before_first_pair = @content[hash_node.loc.expression.begin_pos...hash_node.children.first.loc.expression.begin_pos]
102
+ extract_indent(text_before_first_pair)
103
+ end
104
+
105
+ def indent_after_last_pair(hash_node)
106
+ return nil unless hash_node.children.length > 0
107
+
108
+ text_after_last_pair = @content[hash_node.children.last.loc.expression.begin_pos...hash_node.loc.expression.end_pos]
109
+ extract_indent(text_after_last_pair)
110
+ end
111
+
98
112
  def additional_indent(hash_node)
113
+ return nil if indent_before_first_pair(hash_node)
114
+
99
115
  joiner = joiner_between_pairs(hash_node)
100
116
  joiner && joiner.include?("\n") ? @indent : nil
101
117
  end
@@ -103,12 +119,13 @@ module Rails5
103
119
  def existing_indent(hash_node)
104
120
  previous_sibling = hash_node.parent.children[hash_node.sibling_index - 1]
105
121
  text_before_hash = text_between_siblings(previous_sibling, hash_node)
106
- whitespace_match = text_before_hash.match("\n(\s*)")
107
- return whitespace_match[1] if whitespace_match
122
+ whitespace_indent = extract_indent(text_before_hash)
123
+ return whitespace_indent if whitespace_indent
124
+
125
+ return indent_before_first_pair(hash_node) if indent_before_first_pair(hash_node)
108
126
 
109
127
  joiner = joiner_between_pairs(hash_node)
110
- pair_joiner_match = joiner.match("\n(\s*)") if joiner
111
- return pair_joiner_match[1] if pair_joiner_match
128
+ extract_indent(joiner)
112
129
  end
113
130
 
114
131
  def has_space_after_curly?(hash_node)
@@ -133,11 +150,16 @@ module Rails5
133
150
  end
134
151
 
135
152
  def appropriately_spaced_params_hash(hash_node:, pairs:)
136
- extra_indent = additional_indent(hash_node)
137
-
138
- if extra_indent
139
- base_indent = existing_indent(hash_node)
140
- "{\n#{restring_hash(pairs, indent: base_indent + extra_indent, joiner: ",\n")}\n#{base_indent}}"
153
+ inner_indent = additional_indent(hash_node)
154
+
155
+ if inner_indent || indent_before_first_pair(hash_node)
156
+ outer_indent = existing_indent(hash_node)
157
+ restrung_hash = restring_hash(
158
+ pairs,
159
+ indent: outer_indent + (inner_indent || ''),
160
+ joiner: ",\n"
161
+ )
162
+ "{\n#{restrung_hash}\n#{indent_after_last_pair(hash_node) || outer_indent}}"
141
163
  else
142
164
  curly_sep = has_space_after_curly?(hash_node) ? '' : ' '
143
165
  "{#{curly_sep}#{restring_hash(pairs)}#{curly_sep}}"
@@ -147,7 +169,7 @@ module Rails5
147
169
  def wrap_arg(source_rewriter, node, key)
148
170
  node_loc = node.loc.expression
149
171
  node_source = node_loc.source
150
- if node.hash_type? && !node_source.match(/^\s*\{.*\}$/)
172
+ if node.hash_type? && !node_source.match(/^\s*\{.*\}$/m)
151
173
  node_source = "{ #{node_source} }"
152
174
  end
153
175
  source_rewriter.replace(node_loc, "#{key}: #{node_source}")
@@ -157,6 +179,13 @@ module Rails5
157
179
  pairs.map { |pair| "#{indent}#{pair.loc.expression.source}" }.join(joiner)
158
180
  end
159
181
 
182
+ def extract_indent(str)
183
+ return unless str
184
+
185
+ match = str.match("\n(\s*)")
186
+ match[1] if match
187
+ end
188
+
160
189
  def log(str)
161
190
  return if @quiet
162
191
 
@@ -1,5 +1,5 @@
1
1
  module Rails5
2
2
  module SpecConverter
3
- VERSION = "1.0.5"
3
+ VERSION = "1.0.6"
4
4
  end
5
5
  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.5
4
+ version: 1.0.6
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-20 00:00:00.000000000 Z
11
+ date: 2016-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -139,9 +139,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  version: '0'
140
140
  requirements: []
141
141
  rubyforge_project:
142
- rubygems_version: 2.4.5
142
+ rubygems_version: 2.5.1
143
143
  signing_key:
144
144
  specification_version: 4
145
145
  summary: A tool to upgrade Rails 4-style specs to Rails 5-style
146
146
  test_files: []
147
- has_rdoc: