sauerkraut 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5bb434c28c53b22154ef383692ef708c1a5915bd
4
- data.tar.gz: 8ebc4213c01eec7929cb2f70595fb2b2bee617b9
3
+ metadata.gz: 3f805ce797baa943041777e9c9d7a962d4e35193
4
+ data.tar.gz: 2fefa04558823bec9c95b4c5765b67a43c4920c1
5
5
  SHA512:
6
- metadata.gz: 6deb022974415c9d5248b43769ecc6033ecb8c20cb45fab0429cb7bce6a43f2d17c1268866fe1c5bd219ec2cb7959784f6044612a5436a6e2b28f56be2e5ab66
7
- data.tar.gz: 334719a454260a19d48ec0e156cb7457c34cd2c05f3626655eca79108efb12822ead62a0e525ae1e42e1288062d392c0a395d47c40889c71e6c55317de26df9a
6
+ metadata.gz: a90eb6f7631ad62c829670a007282822a85b589824d0395e74e73f47bdcbbc97c9fed65bd44939fb163eeddb86d7523ef8267124c431861fb5259ad23c2fbad6
7
+ data.tar.gz: d585f6ef70f834c32c1354a53cc20a7a83eedade9e35b8bd020df089b0eb8aa00f5a0865a9c59e7f6f1078a7036c9bee556bbaebef1201c2db5f2a76a37545d7
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ *.text
@@ -1,3 +1,3 @@
1
1
  module Sauerkraut
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/sauerkraut.rb CHANGED
@@ -6,7 +6,7 @@ module Sauerkraut
6
6
  @options = {
7
7
  :output => nil,
8
8
  }
9
- @banner = "\nUsage: sauerkraut FEATURE_FILE:N[:M] [-o FILE]".cyan
9
+ @banner = "\nUsage: sauerkraut FEATURE_FILE[:N][:M] [-o FILE]".cyan
10
10
 
11
11
  def self.display_help
12
12
  puts @banner
@@ -116,13 +116,30 @@ module Sauerkraut
116
116
  f.close
117
117
  end
118
118
 
119
+
120
+ def self.colorize_output(output)
121
+ output.map! do |line|
122
+ if line =~ /^#/
123
+ line.chomp.cyan
124
+ else
125
+ line
126
+ end
127
+ end
128
+ end
129
+
130
+
131
+ def self.highlight_bvar!(bvar, line)
132
+ #line.gsub!(/([\W])(#{bvar})(\W)/) {|m| "#{$1}" + "#{bvar}".magenta + "#{$3}"}
133
+ line.gsub!(/([\[\(-\/=\\& :\+\-])(#{bvar})([^\w]|\z)/) {|m| "#{$1}" + "#{bvar}".magenta + "#{$3}"}
134
+ end
135
+
119
136
  def self.run(args)
120
137
  @args = args
121
138
 
139
+ # PARSING
122
140
  exit_with_help("must specify a feature file") if no_feature_file?
123
141
  exit_with_help("must specify a valid feature file") if invalid_feature_file?
124
142
  exit_with_help("must specify an existing feature file") if !feature_file_exists?
125
- exit_with_help("must specify a line number") if no_line_number?
126
143
  exit_with_help("specify range with :N:M") if invalid_range?
127
144
 
128
145
  exit_with_help("must specify an output file") if no_output_file_specified?
@@ -130,42 +147,57 @@ module Sauerkraut
130
147
 
131
148
 
132
149
  # get feature file
133
- feature_file = @args[0].split(":").first
134
- line_number = @args[0].split(":")[1].to_i
135
- range_number = range? ? (@args[0].split(":").last.to_i) : nil
150
+ if no_line_number?
151
+ feature_file = @args[0]
152
+ line_number = 0
153
+ range_number = nil
154
+ else
155
+ feature_file = @args[0].split(":").first
156
+ line_number = @args[0].split(":")[1].to_i
157
+ range_number = range? ? (@args[0].split(":").last.to_i) : nil
158
+ end
136
159
  feature_file_array = IO.readlines feature_file
137
160
 
138
161
 
139
162
 
140
163
 
141
-
142
-
143
- # if one line, get scenario
144
- if !range?
145
- exit_with_help("specify a line number that is a scenario") if !is_line_scenario?(feature_file_array[line_number-1])
146
- scenario = feature_file_array[line_number-1]
164
+ # if no lines, get entire file
165
+ if no_line_number?
147
166
  steps = []
148
- feature_file_array[line_number..-1].each do |line|
149
- break if is_line_scenario?(line)
167
+ feature_file_array[0..-1].each do |line|
168
+ next if is_line_scenario?(line)
150
169
  steps << line.strip
151
170
  end
152
- end
171
+ else
153
172
 
154
- # if two lines, gather given when thens
155
- if range?
156
- steps = []
157
- feature_file_array[line_number..range_number].each do |line|
158
- next if is_line_scenario?(line)
159
- steps << line.strip
173
+
174
+ # if one line, get scenario
175
+ if !range?
176
+ exit_with_help("specify a line number that is a scenario") if !is_line_scenario?(feature_file_array[line_number-1])
177
+ scenario = feature_file_array[line_number-1]
178
+ steps = []
179
+ feature_file_array[line_number..-1].each do |line|
180
+ break if is_line_scenario?(line)
181
+ steps << line.strip
182
+ end
160
183
  end
184
+
185
+ # if two lines, gather given when thens
186
+ if range?
187
+ steps = []
188
+ feature_file_array[line_number..range_number].each do |line|
189
+ next if is_line_scenario?(line)
190
+ steps << line.strip
191
+ end
192
+ end
193
+
161
194
  end
162
195
 
163
196
 
164
197
  # get regexes
165
- pattern = /(?:Given|When|Then|And).+\/(.*)\/.+/
198
+ pattern = /(?:Given|When|Then|And|But).+\/(.*)\/.+/
166
199
  pattern2 = /\/(.*)\//
167
200
  all_the_regexes = []
168
- linenumber = 1
169
201
  stepfiles = File.join("**", "*steps.rb")
170
202
  Dir.glob(stepfiles) do |file|
171
203
  linenumber = 1
@@ -182,12 +214,17 @@ module Sauerkraut
182
214
 
183
215
  # use stepfinder to find sources
184
216
  # compute block variables
185
- stepdeflocations = []
217
+ headlands = []
186
218
  steps.each do |step|
187
219
  next if !is_step_def?(step)
188
220
  all_the_regexes.each do |regexarr|
189
221
  if remove_first_word(step) =~ regexarr.first
190
- stepdeflocations << {:step => step, :sourcefile => regexarr[1], :lineno => regexarr[2], :block_vars => remove_first_word(step).scan(regexarr[0]).flatten}
222
+ headlands << {
223
+ :step => step,
224
+ :sourcefile => regexarr[1],
225
+ :lineno => regexarr[2],
226
+ :block_vars => remove_first_word(step).scan(regexarr[0]).flatten,
227
+ }
191
228
  end
192
229
  end
193
230
  end
@@ -195,23 +232,23 @@ module Sauerkraut
195
232
 
196
233
 
197
234
  # get each code section from source
198
- stepdeflocations.each do |stepdeflocation|
235
+ headlands.each do |headland|
199
236
 
200
237
  # get code block
201
- code_barrel = IO.readlines stepdeflocation[:sourcefile]
202
- stepdeflocation[:step_def] = code_barrel[stepdeflocation[:lineno]-1]
238
+ patch = IO.readlines headland[:sourcefile]
239
+ headland[:step_def] = patch[ headland[:lineno]-1]
203
240
 
204
241
  # get block variables
205
- if has_block_variables?( code_barrel[stepdeflocation[:lineno]-1])
206
- stepdeflocation[:block_var_names] = code_barrel[stepdeflocation[:lineno]-1].reverse.scan(/\|(.*?)\|/).flatten.first.reverse.split(",").map{|v| v.strip}
242
+ if has_block_variables?( patch[headland[:lineno]-1])
243
+ headland[:block_var_names] = patch[ headland[:lineno]-1].reverse.scan(/\|(.*?)\|/).flatten.first.reverse.split(",").map{|v| v.strip}
207
244
  else
208
- stepdeflocation[:block_var_names] = nil
245
+ headland[:block_var_names] = nil
209
246
  end
210
247
 
211
248
  #step through until the next given when then,
212
249
  # collecting the lines
213
250
  cabbage = []
214
- code_barrel[stepdeflocation[:lineno]..-1].each do |line|
251
+ patch[ headland[:lineno]..-1].each do |line|
215
252
  break if (is_step_def?(line) || is_def?(line))
216
253
  cabbage << line
217
254
  end
@@ -231,7 +268,7 @@ module Sauerkraut
231
268
  end
232
269
  cabbage.reverse!
233
270
  array_trim(cabbage)
234
- stepdeflocation[:cabbage] = cabbage
271
+ headland[:cabbage] = cabbage
235
272
 
236
273
  end
237
274
 
@@ -242,19 +279,36 @@ module Sauerkraut
242
279
  # display cabbages
243
280
 
244
281
  output = []
245
- stepdeflocations.each do |stepdeflocation|
246
- output << "#{encomment stepdeflocation[:step_def]}"
282
+ headlands.each do |headland|
283
+ output << "#{encomment headland[:step_def]}"
284
+
285
+ if headland[:block_var_names]
286
+ output << "# block vars ------"
287
+ headland[:block_var_names].each_with_index do |name,i|
288
+ bvar = "#{name}"
289
+ bvar = bvar.magenta if !@options[:output]
290
+ line = bvar + " = #{enquote headland[ :block_vars][i]}"
291
+ output << line
292
+ end
293
+ output << "# -----------------"
294
+ end
247
295
 
248
- if stepdeflocation[:block_var_names]
249
- output << "# block vars"
250
- stepdeflocation[:block_var_names].each_with_index do |name,i|
251
- output << "#{name} = #{enquote stepdeflocation[:block_vars][i]}"
296
+ # search for block vars and highlight
297
+ if !@options[:output] && headland[:block_var_names]
298
+ cabbage = headland[:cabbage].map! do |line|
299
+ headland[:block_var_names].each do |bvar|
300
+ if line =~ /\W#{bvar}\W/
301
+ highlight_bvar!(bvar, line)
302
+ end
303
+ end
304
+ line
252
305
  end
253
- output << "# |"
254
- output << "# V"
306
+ else
307
+ cabbage = headland[:cabbage]
255
308
  end
256
309
 
257
- output += stepdeflocation[:cabbage]
310
+
311
+ output += cabbage
258
312
 
259
313
  output << "\n"
260
314
  end
@@ -267,7 +321,8 @@ module Sauerkraut
267
321
  write_array_to_file(output, @options[:output])
268
322
  puts "output written to #{@options[:output]}"
269
323
  else
270
- puts output
324
+ puts colorize_output output
325
+ #puts output
271
326
  end
272
327
 
273
328
  end
data/sauerkraut.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["rubycoder@example.com"]
11
11
  spec.summary = %q{Helps refactor cucumber steps.}
12
12
  spec.description = %q{Gathers all step definition source code for a given scenario or range, and outputs it in one place.}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/cartoloupe/sauerkraut"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -8,6 +8,7 @@ describe "parsing" do
8
8
  expect {Sauerkraut.run "blah.feature".split}.to raise_error
9
9
  expect {Sauerkraut.run "blah.feature:39".split}.to raise_error
10
10
  expect {Sauerkraut.run "features/test.feature:39".split}.to raise_error
11
+ expect {Sauerkraut.run "features/test.feature".split}.to_not raise_error
11
12
  expect {Sauerkraut.run "features/test.feature:15".split}.to_not raise_error
12
13
  expect {Sauerkraut.run "features/test.feature:15:".split}.to raise_error
13
14
  expect {Sauerkraut.run "features/test.feature:15:17".split}.to_not raise_error
data/test/runtest1.output CHANGED
@@ -1,39 +1,34 @@
1
1
  #Given(/^([\w]+) slices of vegetables$/) do |vegetable_size|
2
- # block vars
2
+ # block vars ------
3
3
  vegetable_size = "small"
4
- # |
5
- # V
4
+ # -----------------
6
5
  @vegetable_slice_size = vegetable_size.to_sym
7
6
 
8
7
  #Given(/^a(nother)? layer of vegetables is placed in the jar$/) do |repeat|
9
- # block vars
8
+ # block vars ------
10
9
  repeat = ""
11
- # |
12
- # V
10
+ # -----------------
13
11
  @jar ||= []
14
12
  put_vegetables_in_jar
15
13
 
16
14
  #Given(/^then (more )?salt is added$/) do |more|
17
- # block vars
15
+ # block vars ------
18
16
  more = ""
19
- # |
20
- # V
17
+ # -----------------
21
18
  @salt = 1
22
19
  @salt += 1 if more
23
20
 
24
21
  #Given(/^a(nother)? layer of vegetables is placed in the jar$/) do |repeat|
25
- # block vars
22
+ # block vars ------
26
23
  repeat = "nother"
27
- # |
28
- # V
24
+ # -----------------
29
25
  @jar ||= []
30
26
  put_vegetables_in_jar
31
27
 
32
28
  #Given(/^then (more )?salt is added$/) do |more|
33
- # block vars
29
+ # block vars ------
34
30
  more = "more "
35
- # |
36
- # V
31
+ # -----------------
37
32
  @salt = 1
38
33
  @salt += 1 if more
39
34
 
data/test/runtest2.output CHANGED
@@ -1,31 +1,27 @@
1
1
  #Given(/^([\w]+) slices of vegetables$/) do |vegetable_size|
2
- # block vars
2
+ # block vars ------
3
3
  vegetable_size = "small"
4
- # |
5
- # V
4
+ # -----------------
6
5
  @vegetable_slice_size = vegetable_size.to_sym
7
6
 
8
7
  #Given(/^a(nother)? layer of vegetables is placed in the jar$/) do |repeat|
9
- # block vars
8
+ # block vars ------
10
9
  repeat = ""
11
- # |
12
- # V
10
+ # -----------------
13
11
  @jar ||= []
14
12
  put_vegetables_in_jar
15
13
 
16
14
  #Given(/^then (more )?salt is added$/) do |more|
17
- # block vars
15
+ # block vars ------
18
16
  more = ""
19
- # |
20
- # V
17
+ # -----------------
21
18
  @salt = 1
22
19
  @salt += 1 if more
23
20
 
24
21
  #Given(/^a(nother)? layer of vegetables is placed in the jar$/) do |repeat|
25
- # block vars
22
+ # block vars ------
26
23
  repeat = "nother"
27
- # |
28
- # V
24
+ # -----------------
29
25
  @jar ||= []
30
26
  put_vegetables_in_jar
31
27
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sauerkraut
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasanth Pappu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-20 00:00:00.000000000 Z
11
+ date: 2014-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -104,7 +104,7 @@ files:
104
104
  - spec/sauerkraut_spec.rb
105
105
  - test/runtest1.output
106
106
  - test/runtest2.output
107
- homepage: ''
107
+ homepage: https://github.com/cartoloupe/sauerkraut
108
108
  licenses:
109
109
  - MIT
110
110
  metadata: {}
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  version: '0'
125
125
  requirements: []
126
126
  rubyforge_project:
127
- rubygems_version: 2.2.2
127
+ rubygems_version: 2.4.1
128
128
  signing_key:
129
129
  specification_version: 4
130
130
  summary: Helps refactor cucumber steps.
@@ -134,3 +134,4 @@ test_files:
134
134
  - spec/sauerkraut_spec.rb
135
135
  - test/runtest1.output
136
136
  - test/runtest2.output
137
+ has_rdoc: