cuke_cataloger 1.3.1 → 1.4.0

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: 827609d20ecbc5d2e4d2786e742a1ba7f8f72a9a
4
- data.tar.gz: 0942116e5fc16b864b8a257b0cdad895084cbf68
3
+ metadata.gz: 30eaf9d9662dd4487ca55a63d56c3911c852e1d8
4
+ data.tar.gz: 42302cb72e6d57fd83afb9494b8b88fc0400f137
5
5
  SHA512:
6
- metadata.gz: 3e628724c39985b33ef58610f5b09312166bf40e0bc0f3dae780b6e481d21741e3d6c70ac7e5a9449765350c3708a6eaba2ba961871515384d7f55a1f452f8d1
7
- data.tar.gz: 92632d986a95cf0449f3763a05f44dc07ebf6167a69a5e6896d71662e4d190cc591c576882f51293fe1b7ca547d6bb46ab4b2d965681d90f00b1bad4fcf6b42a
6
+ metadata.gz: 0b9adbdc69989580d77ca66d151287c248c5cb55983c73fa51f9c91a345cc1d7290591de2190d7bde6050d26e89173ef1ba639511850d4a7e22d48ce68297d98
7
+ data.tar.gz: 89ffe919e0773c884908785a116e90460e037f70e2330f16c86e724fb3ef4139a6b000c2a55e73913ffe387f4365d6a4f9fc033a23d2e7e9ef37177a7a43f19e
@@ -1,12 +1,32 @@
1
+ os:
2
+ - linux
3
+ - osx
4
+
1
5
  language: ruby
2
6
  rvm:
3
7
  - 1.8.7
4
8
  - 1.9.3
5
9
  - 2.2.2
10
+ - 2.4.0
11
+
12
+ matrix:
13
+ exclude:
14
+ # Travis does not provide 1.8.7 on OSX
15
+ - rvm: 1.8.7
16
+ os: osx
17
+ # Rake 11.x does not support Ruby 1.8.7
18
+ - rvm: 1.8.7
19
+ gemfile: testing/gemfiles/rake11.gemfile
20
+ # Rake 12.x does not support Ruby 1.8.7
21
+ - rvm: 1.8.7
22
+ gemfile: testing/gemfiles/rake12.gemfile
6
23
 
7
24
  gemfile:
8
25
  - testing/gemfiles/cuke_modeler0.gemfile
9
26
  - testing/gemfiles/cuke_modeler1.gemfile
27
+ - testing/gemfiles/rake10.gemfile
28
+ - testing/gemfiles/rake11.gemfile
29
+ - testing/gemfiles/rake12.gemfile
10
30
 
11
31
  # todo - Remove this once TravisCI fixes their bundler issue (https://github.com/alphagov/govuk_template/pull/186)
12
32
  before_install:
data/Gemfile CHANGED
@@ -19,4 +19,4 @@ if RUBY_VERSION =~ /^1\./
19
19
  gem 'term-ansicolor', '< 1.4' # The 'term-ansicolor' gem requires Ruby 2.x on/after this version
20
20
  end
21
21
 
22
- gem 'cuke_modeler', '~> 1.0'
22
+ gem 'cuke_modeler', '< 2.0'
data/History.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Release history
2
2
 
3
+ ### Version 1.4.0 / 2017-04-18
4
+
5
+ - Both cataloging and validation can now be used without including outline rows, if desired.
6
+
7
+ - The column header used for outline row ids is now configurable.
8
+
9
+
3
10
  ### Version 1.3.1 / 2017-01-11
4
11
 
5
12
  - Bug fix: Added missing shebang line to the gem's executable file.
data/README.md CHANGED
@@ -2,8 +2,9 @@
2
2
 
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/cuke_cataloger.svg)](http://badge.fury.io/rb/cuke_cataloger)
5
- [![Build Status](https://travis-ci.org/enkessler/cuke_cataloger.svg?branch=master)](https://travis-ci.org/enkessler/cuke_cataloger)
6
- [![Coverage Status](https://coveralls.io/repos/enkessler/cuke_cataloger/badge.svg?branch=master&service=github)](https://coveralls.io/github/enkessler/cuke_cataloger?branch=master)
5
+ [![Build Status](https://travis-ci.org/enkessler/cuke_cataloger.svg?branch=dev)](https://travis-ci.org/enkessler/cuke_cataloger)
6
+ [![Build status](https://ci.appveyor.com/api/projects/status/9a7gw3r5ddfugtf0/branch/dev?svg=true)](https://ci.appveyor.com/project/enkessler/cuke-cataloger/branch/dev)
7
+ [![Coverage Status](https://coveralls.io/repos/enkessler/cuke_cataloger/badge.svg?branch=dev&service=github)](https://coveralls.io/github/enkessler/cuke_cataloger?branch=dev)
7
8
  [![Code Climate](https://codeclimate.com/github/enkessler/cuke_cataloger/badges/gpa.svg)](https://codeclimate.com/github/enkessler/cuke_cataloger)
8
9
  [![Project License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/enkessler/cuke_cataloger/blob/master/LICENSE.txt)
9
10
 
@@ -30,11 +31,12 @@ In addition to using the provided classes in any regular Ruby script, the gem's
30
31
 
31
32
  ### Command Line
32
33
 
33
- cuke_cataloger catalog_test_cases [--location=LOCATION] [--prefix=PREFIX]
34
+ cuke_cataloger catalog_test_cases [--location=LOCATION] [--prefix=PREFIX][--[no-]row-id] [--id-column-name=ID_COLUMN_NAME]
34
35
 
35
36
  and
36
37
 
37
- cuke_cataloger validate_test_cases [--location=LOCATION] [--prefix=PREFIX] [--file=FILE]
38
+ cuke_cataloger validate_test_cases [--location=LOCATION] [--prefix=PREFIX] [--[no-]row-id] [--id-column-name=ID_COLUMN_NAME] [--file=FILE]
39
+
38
40
 
39
41
  ### Rake Task
40
42
 
@@ -76,6 +78,33 @@ The the validating functionality scans a given directory for any problems relate
76
78
 
77
79
  The above example would result in a report called `validation_results.txt` being generated for any test in the `tests` directory that had problems related to their id (e.g. did not have an id tag, had the same id tag as another test, etc.), based up the id prefix `@my_prefix_`.
78
80
 
81
+
82
+ ### Shallow cataloging
83
+
84
+ The cataloging and validation process can be limited to the test level instead of also checking individual rows in outlines.
85
+
86
+ `cuke_cataloger catalog_test_cases --no-row-id`
87
+
88
+ `cuke_cataloger validate_test_cases --no-row-id`
89
+
90
+ `Rake::Task['tag_tests'].invoke('./features','@test_case_', false) # 3rd argument is the row flag`
91
+
92
+ `Rake::Task['validate_tests'].invoke('./features','@test_case_',nil, false) # 4th argument is the row flag`
93
+
94
+
95
+ ### Custom id column name
96
+
97
+ By default, the cataloging and validation process uses `test_case_id` as the column name for outline rows but an alternative name can be provided.
98
+
99
+ `cuke_cataloger catalog_test_cases --id-column-name my_special_column_id`
100
+
101
+ `cuke_cataloger validate_test_cases --id-column-name my_special_column_id`
102
+
103
+ `Rake::Task['tag_tests'].invoke('./features','@test_case_', true, 'my_special_column_id') # 4th argument is the id column name`
104
+
105
+ `Rake::Task['validate_tests'].invoke('./features','@test_case_',nil, true, 'my_special_column_id') # 5th argument is the id column name`
106
+
107
+
79
108
  ## Contributing
80
109
 
81
110
  1. Fork it `http://github.com/<my-github-username>/cuke_cataloger/fork`
@@ -0,0 +1,69 @@
1
+ version: '1.0.{build}'
2
+
3
+ environment:
4
+ matrix:
5
+ - RUBY_VERSION: 187-x64
6
+ BUNDLE_GEMFILE: testing/gemfiles/cuke_modeler0.gemfile
7
+ - RUBY_VERSION: 193-x64
8
+ BUNDLE_GEMFILE: testing/gemfiles/cuke_modeler0.gemfile
9
+ - RUBY_VERSION: 200-x64
10
+ BUNDLE_GEMFILE: testing/gemfiles/cuke_modeler0.gemfile
11
+ - RUBY_VERSION: 21-x64
12
+ BUNDLE_GEMFILE: testing/gemfiles/cuke_modeler0.gemfile
13
+ - RUBY_VERSION: 22-x64
14
+ BUNDLE_GEMFILE: testing/gemfiles/cuke_modeler0.gemfile
15
+
16
+ - RUBY_VERSION: 187-x64
17
+ BUNDLE_GEMFILE: testing/gemfiles/cuke_modeler1.gemfile
18
+ - RUBY_VERSION: 193-x64
19
+ BUNDLE_GEMFILE: testing/gemfiles/cuke_modeler1.gemfile
20
+ - RUBY_VERSION: 200-x64
21
+ BUNDLE_GEMFILE: testing/gemfiles/cuke_modeler1.gemfile
22
+ - RUBY_VERSION: 21-x64
23
+ BUNDLE_GEMFILE: testing/gemfiles/cuke_modeler1.gemfile
24
+ - RUBY_VERSION: 22-x64
25
+ BUNDLE_GEMFILE: testing/gemfiles/cuke_modeler1.gemfile
26
+
27
+ - RUBY_VERSION: 187-x64
28
+ BUNDLE_GEMFILE: testing/gemfiles/rake10.gemfile
29
+ - RUBY_VERSION: 193-x64
30
+ BUNDLE_GEMFILE: testing/gemfiles/rake10.gemfile
31
+ - RUBY_VERSION: 200-x64
32
+ BUNDLE_GEMFILE: testing/gemfiles/rake10.gemfile
33
+ - RUBY_VERSION: 21-x64
34
+ BUNDLE_GEMFILE: testing/gemfiles/rake10.gemfile
35
+ - RUBY_VERSION: 22-x64
36
+ BUNDLE_GEMFILE: testing/gemfiles/rake10.gemfile
37
+
38
+ - RUBY_VERSION: 193-x64
39
+ BUNDLE_GEMFILE: testing/gemfiles/rake11.gemfile
40
+ - RUBY_VERSION: 200-x64
41
+ BUNDLE_GEMFILE: testing/gemfiles/rake11.gemfile
42
+ - RUBY_VERSION: 21-x64
43
+ BUNDLE_GEMFILE: testing/gemfiles/rake11.gemfile
44
+ - RUBY_VERSION: 22-x64
45
+ BUNDLE_GEMFILE: testing/gemfiles/rake11.gemfile
46
+
47
+ - RUBY_VERSION: 193-x64
48
+ BUNDLE_GEMFILE: testing/gemfiles/rake12.gemfile
49
+ - RUBY_VERSION: 200-x64
50
+ BUNDLE_GEMFILE: testing/gemfiles/rake12.gemfile
51
+ - RUBY_VERSION: 21-x64
52
+ BUNDLE_GEMFILE: testing/gemfiles/rake12.gemfile
53
+ - RUBY_VERSION: 22-x64
54
+ BUNDLE_GEMFILE: testing/gemfiles/rake12.gemfile
55
+
56
+
57
+ install:
58
+ - set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH%
59
+ - bundle install
60
+
61
+ build: off
62
+
63
+ before_test:
64
+ - ruby -v
65
+ - gem -v
66
+ - bundle -v
67
+
68
+ test_script:
69
+ - bundle exec rake
@@ -10,23 +10,29 @@ class CLI < Thor
10
10
  desc 'catalog_test_cases', 'Catalog the test cases in LOCATION with an id based on PREFIX'
11
11
  option :location, :default => '.'
12
12
  option :prefix, :default => '@test_case_'
13
+ option :row_id, :type => :boolean, :default => true
14
+ option :id_column_name, :default => 'test_case_id'
13
15
 
14
16
  def catalog_test_cases
15
17
  puts "Tagging tests in '#{options[:location]}' with tag '#{options[:prefix]}'\n"
18
+ puts "Including outline rows\n" if options[:row_id]
16
19
 
17
20
  tagger = CukeCataloger::UniqueTestCaseTagger.new
18
- tagger.tag_tests(options[:location], options[:prefix])
21
+ tagger.tag_tests(options[:location], options[:prefix], {}, options[:row_id], options[:id_column_name])
19
22
  end
20
23
 
21
24
  desc 'validate_test_cases', 'Validate the test cases in LOCATION with an id based on PREFIX. Will output the report to FILE, if provided.'
22
25
  option :location, :default => '.'
23
26
  option :prefix, :default => '@test_case_'
27
+ option :row_id, :type => :boolean, :default => true
28
+ option :id_column_name, :default => 'test_case_id'
24
29
  option :file
25
30
 
26
31
  def validate_test_cases
27
32
  puts "Validating tests in '#{options[:location]}' with tag '#{options[:prefix]}'\n"
33
+ puts "Including outline rows\n" if options[:row_id]
28
34
 
29
- results = CukeCataloger::UniqueTestCaseTagger.new.validate_test_ids(options[:location], options[:prefix])
35
+ results = CukeCataloger::UniqueTestCaseTagger.new.validate_test_ids(options[:location], options[:prefix], options[:row_id], options[:id_column_name])
30
36
  report_text = "Validation Results\nProblems found: #{results.count}\n\n"
31
37
 
32
38
 
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_runtime_dependency 'cuke_modeler', '>= 0.2', '< 2.0'
22
22
  spec.add_runtime_dependency 'cql', '~>1.0', '>= 1.0.1'
23
- spec.add_runtime_dependency 'rake', '< 12.0'
23
+ spec.add_runtime_dependency 'rake', '< 13.0'
24
24
  spec.add_runtime_dependency 'thor', '~> 0.0'
25
25
 
26
26
  spec.add_development_dependency 'bundler', '~> 1.5'
@@ -14,24 +14,30 @@ module CukeCataloger
14
14
  def self.create_tasks
15
15
 
16
16
  desc 'Add unique id tags to tests in the given directory'
17
- task 'tag_tests', [:directory, :prefix] do |t, args|
17
+ task 'tag_tests', [:directory, :prefix, :row_id, :id_column_name] do |t, args|
18
18
  location = args[:directory] || '.'
19
19
  prefix = args[:prefix] || '@test_case_'
20
+ tag_rows = args[:row_id].nil? ? true : args[:row_id]
21
+ id_column_name = args[:id_column_name] || 'test_case_id'
20
22
 
21
23
  puts "Tagging tests in '#{location}' with tag '#{prefix}'\n"
24
+ puts "Including outline rows\n" if tag_rows
22
25
 
23
26
  tagger = CukeCataloger::UniqueTestCaseTagger.new
24
- tagger.tag_tests(location, prefix)
27
+ tagger.tag_tests(location, prefix, {}, tag_rows, id_column_name)
25
28
  end
26
29
 
27
30
  desc 'Scan tests in the given directory for id problems'
28
- task 'validate_tests', [:directory, :prefix, :out_file] do |t, args|
31
+ task 'validate_tests', [:directory, :prefix, :out_file, :row_id, :id_column_name] do |t, args|
29
32
  location = args[:directory] || '.'
30
33
  prefix = args[:prefix] || '@test_case_'
34
+ tag_rows = args[:row_id].nil? ? true : args[:row_id]
35
+ id_column_name = args[:id_column_name] || 'test_case_id'
31
36
 
32
37
  puts "Validating tests in '#{location}' with tag '#{prefix}'\n"
38
+ puts "Including outline rows\n" if tag_rows
33
39
 
34
- results = CukeCataloger::UniqueTestCaseTagger.new.validate_test_ids(location, prefix)
40
+ results = CukeCataloger::UniqueTestCaseTagger.new.validate_test_ids(location, prefix, tag_rows, id_column_name)
35
41
  report_text = "Validation Results\nProblems found: #{results.count}\n\n"
36
42
 
37
43
 
@@ -13,7 +13,7 @@ module CukeCataloger
13
13
  @tag_location = :adjacent
14
14
  end
15
15
 
16
- def tag_tests(feature_directory, tag_prefix, explicit_indexes = {})
16
+ def tag_tests(feature_directory, tag_prefix, explicit_indexes = {}, tag_rows = true, id_column_name = 'test_case_id')
17
17
  warn("This script will potentially rewrite all of your feature files. Please be patient and remember to tip your source control system.")
18
18
 
19
19
  @known_id_tags = {}
@@ -21,7 +21,7 @@ module CukeCataloger
21
21
  set_id_tag(tag_prefix)
22
22
  set_test_suite_model(feature_directory)
23
23
 
24
- @start_indexes = merge_indexes(default_start_indexes(determine_known_ids(feature_directory, tag_prefix)), explicit_indexes)
24
+ @start_indexes = merge_indexes(default_start_indexes(determine_known_ids(feature_directory, tag_prefix, id_column_name)), explicit_indexes)
25
25
  @next_index = @start_indexes[:primary]
26
26
 
27
27
  # Analysis and output
@@ -30,14 +30,14 @@ module CukeCataloger
30
30
  when test.is_a?(CukeModeler::Scenario)
31
31
  process_scenario(test)
32
32
  when test.is_a?(CukeModeler::Outline)
33
- process_outline(test)
33
+ process_outline(test, tag_rows, id_column_name)
34
34
  else
35
35
  raise("Unknown test type: #{test.class.to_s}")
36
36
  end
37
37
  end
38
38
  end
39
39
 
40
- def scan_for_tagged_tests(feature_directory, tag_prefix)
40
+ def scan_for_tagged_tests(feature_directory, tag_prefix, id_column_name = 'test_case_id')
41
41
  @results = []
42
42
  @known_id_tags = {}
43
43
 
@@ -49,9 +49,9 @@ module CukeCataloger
49
49
 
50
50
  if test.is_a?(CukeModeler::Outline)
51
51
  test.examples.each do |example|
52
- if has_id_parameter?(example)
52
+ if has_id_parameter?(example, id_column_name)
53
53
  example_rows_for(example).each do |row|
54
- add_to_results(row) if has_row_id?(row)
54
+ add_to_results(row) if has_row_id?(row, id_column_name)
55
55
  end
56
56
  end
57
57
  end
@@ -61,7 +61,7 @@ module CukeCataloger
61
61
  @results
62
62
  end
63
63
 
64
- def validate_test_ids(feature_directory, tag_prefix)
64
+ def validate_test_ids(feature_directory, tag_prefix, tag_rows = true, id_column_name = 'test_case_id')
65
65
  @results = []
66
66
  @known_id_tags = {}
67
67
 
@@ -69,19 +69,19 @@ module CukeCataloger
69
69
  set_test_suite_model(feature_directory)
70
70
 
71
71
  @features.each { |feature| validate_feature(feature) }
72
- @tests.each { |test| validate_test(test) }
72
+ @tests.each { |test| validate_test(test, tag_rows, id_column_name) }
73
73
 
74
74
  @results
75
75
  end
76
76
 
77
- def determine_known_ids(feature_directory, tag_prefix)
77
+ def determine_known_ids(feature_directory, tag_prefix, id_column_name = 'test_case_id')
78
78
  known_ids = []
79
79
 
80
- found_tagged_objects = scan_for_tagged_tests(feature_directory, tag_prefix).collect { |result| result[:object] }
80
+ found_tagged_objects = scan_for_tagged_tests(feature_directory, tag_prefix, id_column_name).collect { |result| result[:object] }
81
81
 
82
82
  found_tagged_objects.each do |element|
83
83
  if element.is_a?(CukeModeler::Row)
84
- row_id = row_id_for(element)
84
+ row_id = row_id_for(element, id_column_name)
85
85
  known_ids << row_id if well_formed_sub_id?(row_id)
86
86
  else
87
87
  known_ids << test_id_for(element)
@@ -121,17 +121,17 @@ module CukeCataloger
121
121
  check_for_feature_level_test_tag(feature)
122
122
  end
123
123
 
124
- def validate_test(test)
124
+ def validate_test(test, tag_rows, id_column_name)
125
125
  check_for_missing_test_tag(test)
126
126
  check_for_multiple_test_id_tags(test)
127
127
  check_for_duplicated_test_id_tags(test)
128
128
 
129
129
  if test.is_a?(CukeModeler::Outline)
130
- check_for_missing_id_columns(test)
131
- check_for_missing_row_tags(test)
132
- check_for_duplicated_row_tags(test)
133
- check_for_mismatched_row_tags(test)
134
- check_for_malformed_row_tags(test)
130
+ check_for_missing_id_columns(test, id_column_name) if tag_rows
131
+ check_for_missing_row_tags(test, id_column_name) if tag_rows
132
+ check_for_duplicated_row_tags(test, id_column_name) if tag_rows
133
+ check_for_mismatched_row_tags(test, id_column_name) if tag_rows
134
+ check_for_malformed_row_tags(test, id_column_name) if tag_rows
135
135
  end
136
136
  end
137
137
 
@@ -170,42 +170,42 @@ module CukeCataloger
170
170
  add_to_results(test, :missing_tag) unless has_id_tag?(test)
171
171
  end
172
172
 
173
- def check_for_missing_id_columns(test)
173
+ def check_for_missing_id_columns(test, id_column_name)
174
174
  test.examples.each do |example|
175
- add_to_results(example, :missing_id_column) unless has_id_column?(example)
175
+ add_to_results(example, :missing_id_column) unless has_id_column?(example, id_column_name)
176
176
  end
177
177
  end
178
178
 
179
- def check_for_duplicated_row_tags(test)
180
- validate_rows(test, :duplicate_row_id, false, :has_duplicate_row_id?)
179
+ def check_for_duplicated_row_tags(test, id_column_name)
180
+ validate_rows(test, :duplicate_row_id, false, :has_duplicate_row_id?, id_column_name)
181
181
  end
182
182
 
183
- def check_for_missing_row_tags(test)
184
- validate_rows(test, :missing_row_id, true, :has_row_id?)
183
+ def check_for_missing_row_tags(test, id_column_name)
184
+ validate_rows(test, :missing_row_id, true, :has_row_id?, id_column_name)
185
185
  end
186
186
 
187
- def check_for_mismatched_row_tags(test)
188
- validate_rows(test, :mismatched_row_id, true, :has_matching_id?)
187
+ def check_for_mismatched_row_tags(test, id_column_name)
188
+ validate_rows(test, :mismatched_row_id, true, :has_matching_id?, id_column_name)
189
189
  end
190
190
 
191
- def check_for_malformed_row_tags(test)
191
+ def check_for_malformed_row_tags(test, id_column_name)
192
192
  test.examples.each do |example|
193
- if has_id_column?(example)
193
+ if has_id_column?(example, id_column_name)
194
194
  example_rows_for(example).each do |row|
195
- add_to_results(row, :malformed_sub_id) if (has_row_id?(row) && !well_formed_sub_id?(row_id_for(row)))
195
+ add_to_results(row, :malformed_sub_id) if (has_row_id?(row, id_column_name) && !well_formed_sub_id?(row_id_for(row, id_column_name)))
196
196
  end
197
197
  end
198
198
  end
199
199
  end
200
200
 
201
- def validate_rows(test, rule, desired, row_check)
201
+ def validate_rows(test, rule, desired, row_check, id_column_name)
202
202
  test.examples.each do |example|
203
- if has_id_column?(example)
203
+ if has_id_column?(example, id_column_name)
204
204
  example_rows_for(example).each do |row|
205
205
  if desired
206
- add_to_results(row, rule) unless self.send(row_check, row)
206
+ add_to_results(row, rule) unless self.send(row_check, row, id_column_name)
207
207
  else
208
- add_to_results(row, rule) if self.send(row_check, row)
208
+ add_to_results(row, rule) if self.send(row_check, row, id_column_name)
209
209
  end
210
210
  end
211
211
  end
@@ -216,10 +216,12 @@ module CukeCataloger
216
216
  apply_tag_if_needed(test)
217
217
  end
218
218
 
219
- def process_outline(test)
219
+ def process_outline(test, tag_rows, id_column_name)
220
220
  apply_tag_if_needed(test)
221
- update_parameters_if_needed(test)
222
- update_rows_if_needed(test, determine_next_sub_id(test))
221
+ if tag_rows
222
+ update_parameters_if_needed(test, id_column_name)
223
+ update_rows_if_needed(test, determine_next_sub_id(test), id_column_name)
224
+ end
223
225
  end
224
226
 
225
227
  def apply_tag_if_needed(test)
@@ -235,12 +237,12 @@ module CukeCataloger
235
237
  !!fast_id_tag_for(test)
236
238
  end
237
239
 
238
- def has_id_column?(example)
239
- example.parameters.any? { |param| param =~ /test_case_id/ }
240
+ def has_id_column?(example, id_column_name)
241
+ example.parameters.any? { |param| param == id_column_name }
240
242
  end
241
243
 
242
- def row_id_for(row)
243
- id_index = determine_row_id_cell_index(row)
244
+ def row_id_for(row, id_column_name)
245
+ id_index = determine_row_id_cell_index(row, id_column_name)
244
246
 
245
247
  if id_index
246
248
  cell_value = row.cells[id_index]
@@ -250,16 +252,16 @@ module CukeCataloger
250
252
  end
251
253
  end
252
254
 
253
- def has_row_id?(row)
254
- !!row_id_for(row)
255
+ def has_row_id?(row, id_column_name)
256
+ !!row_id_for(row, id_column_name)
255
257
  end
256
258
 
257
259
  def well_formed_sub_id?(id)
258
260
  !!(id =~ SUB_ID_PATTERN)
259
261
  end
260
262
 
261
- def has_matching_id?(row)
262
- row_id = row_id_for(row)
263
+ def has_matching_id?(row, id_column_name)
264
+ row_id = row_id_for(row, id_column_name)
263
265
 
264
266
  # A lack of id counts as 'matching'
265
267
  return true if row_id.nil?
@@ -275,12 +277,12 @@ module CukeCataloger
275
277
  end
276
278
  end
277
279
 
278
- def has_duplicate_row_id?(row)
279
- row_id = row_id_for(row)
280
+ def has_duplicate_row_id?(row, id_column_name)
281
+ row_id = row_id_for(row, id_column_name)
280
282
 
281
283
  return false unless row_id && well_formed_sub_id?(row_id)
282
284
 
283
- existing_ids = determine_used_sub_ids(row.get_ancestor(:test))
285
+ existing_ids = determine_used_sub_ids(row.get_ancestor(:test), id_column_name)
284
286
  matching_ids = existing_ids.select { |id| id == row_id[/\d+$/] }
285
287
 
286
288
  matching_ids.count > 1
@@ -293,11 +295,11 @@ module CukeCataloger
293
295
  explicit_index ? explicit_index : 1
294
296
  end
295
297
 
296
- def determine_used_sub_ids(test)
298
+ def determine_used_sub_ids(test, id_column_name)
297
299
  ids = test.examples.collect do |example|
298
- if has_id_parameter?(example)
300
+ if has_id_parameter?(example, id_column_name)
299
301
  example_rows_for(example).collect do |row|
300
- row_id_for(row)
302
+ row_id_for(row, id_column_name)
301
303
  end
302
304
  else
303
305
  []
@@ -312,8 +314,8 @@ module CukeCataloger
312
314
  ids
313
315
  end
314
316
 
315
- def determine_row_id_cell_index(row)
316
- row.get_ancestor(:example).parameters.index { |param| param =~ /test_case_id/ }
317
+ def determine_row_id_cell_index(row, id_column_name)
318
+ row.get_ancestor(:example).parameters.index { |param| param =~ /#{id_column_name}/ }
317
319
  end
318
320
 
319
321
  def tag_test(test, tag, padding_string = ' ')
@@ -338,26 +340,26 @@ module CukeCataloger
338
340
  end
339
341
  end
340
342
 
341
- def update_parameters_if_needed(test)
343
+ def update_parameters_if_needed(test, id_column_name)
342
344
  feature_file = test.get_ancestor(:feature_file)
343
345
  file_path = feature_file.path
344
346
  index_adjustment = @file_line_increases[file_path]
345
347
  method_for_rows = Gem.loaded_specs['cuke_modeler'].version.version[/^0/] ? :row_elements : :rows
346
348
 
347
349
  test.examples.each do |example|
348
- unless has_id_parameter?(example)
350
+ unless has_id_parameter?(example, id_column_name)
349
351
  parameter_line_index = (example.send(method_for_rows).first.source_line - 1) + index_adjustment
350
352
 
351
353
  file_lines = File.readlines(file_path)
352
354
 
353
- new_parameter = 'test_case_id'.ljust(parameter_spacing(example))
355
+ new_parameter = id_column_name.ljust(parameter_spacing(example, id_column_name))
354
356
  update_parameter_row(file_lines, parameter_line_index, new_parameter)
355
357
  File.open(file_path, 'w') { |file| file.print file_lines.join }
356
358
  end
357
359
  end
358
360
  end
359
361
 
360
- def update_rows_if_needed(test, sub_id)
362
+ def update_rows_if_needed(test, sub_id, id_column_name)
361
363
  feature_file = test.get_ancestor(:feature_file)
362
364
  file_path = feature_file.path
363
365
  index_adjustment = @file_line_increases[file_path]
@@ -369,12 +371,12 @@ module CukeCataloger
369
371
 
370
372
  test.examples.each do |example|
371
373
  example.send(method_for_rows)[1..(example.send(method_for_rows).count - 1)].each do |row|
372
- unless has_row_id?(row)
373
- row_id = "#{tag_index}-#{sub_id}".ljust(parameter_spacing(example))
374
+ unless has_row_id?(row, id_column_name)
375
+ row_id = "#{tag_index}-#{sub_id}".ljust(parameter_spacing(example, id_column_name))
374
376
 
375
377
  row_line_index = (row.source_line - 1) + index_adjustment
376
378
 
377
- update_value_row(file_lines, row_line_index, row, row_id)
379
+ update_value_row(file_lines, row_line_index, row, row_id, id_column_name)
378
380
  sub_id += 1
379
381
  end
380
382
  end
@@ -429,32 +431,31 @@ module CukeCataloger
429
431
  fast_id_tag_for(test).match(/#{@tag_prefix}(.*)/)[1]
430
432
  end
431
433
 
432
- def has_id_parameter?(example)
433
- #todo - make the id column name configurable
434
- example.parameters.any? { |parameter| parameter == 'test_case_id' }
434
+ def has_id_parameter?(example, id_column_name)
435
+ example.parameters.any? { |parameter| parameter == id_column_name }
435
436
  end
436
437
 
437
438
  def update_parameter_row(file_lines, line_index, parameter)
438
439
  append_row!(file_lines, line_index, " #{parameter} |")
439
440
  end
440
441
 
441
- def update_value_row(file_lines, line_index, row, row_id)
442
+ def update_value_row(file_lines, line_index, row, row_id, id_column_name)
442
443
  case
443
- when needs_adding?(row)
444
+ when needs_adding?(row, id_column_name)
444
445
  append_row!(file_lines, line_index, " #{row_id} |")
445
- when needs_filled_in?(row)
446
- fill_in_row(file_lines, line_index, row, row_id)
446
+ when needs_filled_in?(row, id_column_name)
447
+ fill_in_row(file_lines, line_index, row, row_id, id_column_name)
447
448
  else
448
449
  raise("Don't know how to update row")
449
450
  end
450
451
  end
451
452
 
452
- def needs_adding?(row)
453
- !has_id_parameter?(row.get_ancestor(:example))
453
+ def needs_adding?(row, id_column_name)
454
+ !has_id_parameter?(row.get_ancestor(:example), id_column_name)
454
455
  end
455
456
 
456
- def needs_filled_in?(row)
457
- has_id_parameter?(row.get_ancestor(:example))
457
+ def needs_filled_in?(row, id_column_name)
458
+ has_id_parameter?(row.get_ancestor(:example), id_column_name)
458
459
  end
459
460
 
460
461
  def replace_row!(file_lines, line_index, new_line)
@@ -514,13 +515,13 @@ module CukeCataloger
514
515
  }
515
516
  end
516
517
 
517
- def parameter_spacing(example)
518
+ def parameter_spacing(example, id_column_name)
518
519
  test = example.get_ancestor(:test)
519
520
  test_id = fast_id_tag_for(test)[/\d+$/]
520
521
  row_count = test.examples.reduce(0) { |sum, example| sum += example.rows.count }
521
522
 
522
523
  max_id_length = test_id.length + 1 + row_count.to_s.length
523
- param_length = 'test_case_id'.length
524
+ param_length = id_column_name.length
524
525
 
525
526
  [param_length, max_id_length].max
526
527
  end
@@ -539,11 +540,11 @@ module CukeCataloger
539
540
  indentation
540
541
  end
541
542
 
542
- def fill_in_row(file_lines, line_index, row, row_id)
543
+ def fill_in_row(file_lines, line_index, row, row_id, id_column_name)
543
544
  old_row = file_lines[line_index]
544
545
  sections = file_lines[line_index].split('|', -1)
545
546
 
546
- replacement_index = determine_row_id_cell_index(row)
547
+ replacement_index = determine_row_id_cell_index(row, id_column_name)
547
548
  sections[replacement_index + 1] = " #{row_id} "
548
549
 
549
550
  new_row = sections.join('|')
@@ -1,3 +1,3 @@
1
1
  module CukeCataloger
2
- VERSION = '1.3.1'
2
+ VERSION = '1.4.0'
3
3
  end
@@ -5,7 +5,7 @@ Feature: Cataloging executable
5
5
 
6
6
  Scenario: Cataloging test cases
7
7
 
8
- Note: By default, cataloging will be done in the current directory using the '@test_case_' prefix
8
+ Note: By default, cataloging will be done in the current directory using the '@test_case_' prefix and outline rows will also be cataloged.
9
9
 
10
10
  Given the cuke_cataloger executable is available
11
11
  And there are test cases in the "." directory that have not been cataloged with "@test_case_"
@@ -20,9 +20,10 @@ Feature: Cataloging executable
20
20
  And there are test cases in the "tests" directory that have not been cataloged with "@foo"
21
21
  When the following command is executed:
22
22
  """
23
- cuke_cataloger catalog_test_cases --location <path_to>/tests --prefix @foo
23
+ cuke_cataloger catalog_test_cases --location <path_to>/tests --prefix @foo --no-row-id
24
24
  """
25
- Then all of the test cases in the "tests" directory will be cataloged with "@foo"
25
+ Then all of the scenarios and outlines in the "tests" directory will be cataloged with "@foo"
26
+ But outline rows in the "tests" directory are not cataloged
26
27
 
27
28
  Scenario: Validating test cases
28
29
 
@@ -171,6 +171,25 @@ Then(/^all of the test cases in the "([^"]*)" directory will be cataloged with "
171
171
  verify_no_results
172
172
  end
173
173
 
174
+ Then(/^all of the scenarios and outlines in the "([^"]*)" directory will be cataloged with "([^"]*)"$/) do |target_directory, prefix|
175
+ target_directory = "#{FIXTURE_DIRECTORY}/#{target_directory}"
176
+ @expected_prefix = prefix
177
+ tag_rows = false
178
+
179
+ @test_results = CukeCataloger::UniqueTestCaseTagger.new.validate_test_ids(target_directory, @expected_prefix, tag_rows)
180
+
181
+ verify_no_results
182
+ end
183
+
184
+ But(/^outline rows in the "([^"]*)" directory are not cataloged$/) do |target_directory|
185
+ target_directory = "#{FIXTURE_DIRECTORY}/#{target_directory}"
186
+ tag_rows = true
187
+
188
+ @test_results = CukeCataloger::UniqueTestCaseTagger.new.validate_test_ids(target_directory, @expected_prefix, tag_rows)
189
+
190
+ expect(@test_results.collect { |result| result[:problem] }).to include(:missing_id_column)
191
+ end
192
+
174
193
  Then(/^a validation report for the "([^"]*)" directory with prefix "([^"]*)" is output to the console$/) do |target_directory, prefix|
175
194
  expect(@output).to include("Validating tests in '#{target_directory}' with tag '#{prefix}'")
176
195
  expect(@output).to include("Validation Results")
@@ -2,3 +2,10 @@ Feature: Foo
2
2
 
3
3
  Scenario: Test 1
4
4
  * a step
5
+
6
+ Scenario Outline: Test 2
7
+ * a step
8
+ Examples:
9
+ | param | value |
10
+ | a | b |
11
+ | c | d |
@@ -0,0 +1,21 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec :path => "../../"
4
+
5
+
6
+ # cuke_cataloger can play with pretty much any version of these but they all play differently with Ruby
7
+ if RUBY_VERSION =~ /^1\.8/
8
+ gem 'cucumber', '< 1.3.0'
9
+ gem 'gherkin', '< 2.12.0'
10
+ elsif RUBY_VERSION =~ /^1\./
11
+ gem 'cucumber', '< 2.0.0'
12
+ end
13
+
14
+ if RUBY_VERSION =~ /^1\./
15
+ gem 'tins', '< 1.7' # The 'tins' gem requires Ruby 2.x on/after this version
16
+ gem 'json', '< 2.0' # The 'json' gem drops pre-Ruby 2.x support on/after this version
17
+ gem 'term-ansicolor', '< 1.4' # The 'term-ansicolor' gem requires Ruby 2.x on/after this version
18
+ end
19
+
20
+ gem 'cuke_modeler', '< 2.0'
21
+ gem 'rake', '~> 10.0'
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec :path => "../../"
4
+
5
+
6
+ # Rake 11.x does not work with Ruby 1.8.x
7
+ gem 'rake', '~> 11.0'
8
+
9
+ if RUBY_VERSION =~ /^1\./
10
+ gem 'cucumber', '< 2.0.0'
11
+ gem 'tins', '< 1.7' # The 'tins' gem requires Ruby 2.x on/after this version
12
+ gem 'json', '< 2.0' # The 'json' gem drops pre-Ruby 2.x support on/after this version
13
+ gem 'term-ansicolor', '< 1.4' # The 'term-ansicolor' gem requires Ruby 2.x on/after this version
14
+ end
15
+
16
+ gem 'cuke_modeler', '< 2.0'
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec :path => "../../"
4
+
5
+
6
+ # Rake 12.x does not work with Ruby 1.8.x
7
+ gem 'rake', '~> 12.0'
8
+
9
+ if RUBY_VERSION =~ /^1\./
10
+ gem 'cucumber', '< 2.0.0'
11
+ gem 'tins', '< 1.7' # The 'tins' gem requires Ruby 2.x on/after this version
12
+ gem 'json', '< 2.0' # The 'json' gem drops pre-Ruby 2.x support on/after this version
13
+ gem 'term-ansicolor', '< 1.4' # The 'term-ansicolor' gem requires Ruby 2.x on/after this version
14
+ end
15
+
16
+ gem 'cuke_modeler', '< 2.0'
@@ -1,3 +1,7 @@
1
+ require "#{File.dirname(__FILE__)}/spec_helper"
2
+ require 'rubygems/mock_gem_ui'
3
+
4
+
1
5
  describe 'the gem' do
2
6
 
3
7
  here = File.dirname(__FILE__)
@@ -8,4 +12,11 @@ describe 'the gem' do
8
12
  expect(gemspec.executables).to include('cuke_cataloger')
9
13
  end
10
14
 
15
+ it 'validates cleanly' do
16
+ mock_ui = Gem::MockGemUi.new
17
+ Gem::DefaultUserInteraction.use_ui(mock_ui) { gemspec.validate }
18
+
19
+ expect(mock_ui.error).to_not match(/warn/i)
20
+ end
21
+
11
22
  end
@@ -3,15 +3,18 @@ unless RUBY_VERSION.to_s < '1.9.0'
3
3
  SimpleCov.command_name('cuke_cataloger-cucumber')
4
4
  end
5
5
 
6
+ here = File.dirname(__FILE__)
7
+
6
8
 
7
9
  require 'cuke_cataloger'
8
10
 
11
+ require 'tempfile'
9
12
 
10
13
  RSpec.configure do |config|
11
14
  config.before(:all) do
12
- here = File.dirname(__FILE__)
13
15
  @default_file_directory = "#{here}/temp_files"
14
16
  @default_test_file_directory = "#{here}/test_files"
17
+ @lib_directory = "#{here}/../../../lib"
15
18
  end
16
19
 
17
20
  config.before(:each) do
@@ -81,6 +81,42 @@ describe 'UniqueTestCaseTagger, Integration' do
81
81
  expect(@tagger.instance_variable_get(:@known_id_tags)).to_not include(0)
82
82
  expect(@tagger.instance_variable_get(:@known_id_tags)).to_not include(1)
83
83
  end
84
+
85
+ it 'does not count id like values that are not in the specified id column' do
86
+ input_file = Tempfile.new(['foo', '.feature'])
87
+
88
+ text = "Feature:
89
+
90
+ @test_case_1
91
+ Scenario:
92
+ * a step
93
+
94
+ @test_case_2
95
+ Scenario Outline:
96
+ * a step with a <param>
97
+ Examples: with rows
98
+ | param | test_case_id | foobar |
99
+ | value 1 | 2-1 | 2-4 |
100
+ Examples: without rows
101
+ | param | test_case_id | foobar |
102
+ | value 1 | 2-2 | 2-5 |
103
+ | value 2 | 2-3 | 2-6 |
104
+
105
+ @test_case_3
106
+ Scenario:
107
+ * a step"
108
+
109
+ input_file.write(text)
110
+ input_file.close
111
+ temp_directory = input_file.path.match(/(.*)\/foo.*\.feature/)[1]
112
+
113
+
114
+ result = @tagger.determine_known_ids(temp_directory, '@test_case_', 'foobar')
115
+
116
+
117
+ expect(result).to_not include('2-1', '2-2', '2-3')
118
+ end
119
+
84
120
  end
85
121
 
86
122
  end
@@ -24,8 +24,8 @@ describe 'UniqueTestCaseTagger, Unit' do
24
24
  expect(@tagger).to respond_to(:validate_test_ids)
25
25
  end
26
26
 
27
- it 'requires a directory and tag prefix when validating' do
28
- expect(@tagger.method(:validate_test_ids).arity).to eq(2)
27
+ it 'validates based on a directory, tag prefix, and optional row tagging flag' do
28
+ expect(@tagger.method(:validate_test_ids).arity).to eq(-3)
29
29
  end
30
30
 
31
31
  it 'returns validation results' do
@@ -38,8 +38,8 @@ describe 'UniqueTestCaseTagger, Unit' do
38
38
  expect(@tagger).to respond_to(:scan_for_tagged_tests)
39
39
  end
40
40
 
41
- it 'requires a directory and tag prefix when validating' do
42
- expect(@tagger.method(:scan_for_tagged_tests).arity).to eq(2)
41
+ it 'validates based on a directory, tag prefix, and optional column name' do
42
+ expect(@tagger.method(:scan_for_tagged_tests).arity).to eq(-3)
43
43
  end
44
44
 
45
45
  it 'returns scanning results' do
@@ -52,8 +52,8 @@ describe 'UniqueTestCaseTagger, Unit' do
52
52
  expect(@tagger).to respond_to(:determine_known_ids)
53
53
  end
54
54
 
55
- it 'requires a directory and tag prefix when determining used indexes' do
56
- expect(@tagger.method(:determine_known_ids).arity).to eq(2)
55
+ it 'determines used indexes based on a directory, tag prefix, and optional column name' do
56
+ expect(@tagger.method(:determine_known_ids).arity).to eq(-3)
57
57
  end
58
58
  end
59
59
 
@@ -0,0 +1,4 @@
1
+ # todo - point build/code quality/coverage tags at the dev branch
2
+ # todo - Add better test coverage (rake tasks, cli, etc.)
3
+ # todo - Use features as documentation
4
+ # todo - Use the cuketagger gem for tagging
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cuke_cataloger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Kessler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-11 00:00:00.000000000 Z
11
+ date: 2017-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cuke_modeler
@@ -56,14 +56,14 @@ dependencies:
56
56
  requirements:
57
57
  - - "<"
58
58
  - !ruby/object:Gem::Version
59
- version: '12.0'
59
+ version: '13.0'
60
60
  type: :runtime
61
61
  prerelease: false
62
62
  version_requirements: !ruby/object:Gem::Requirement
63
63
  requirements:
64
64
  - - "<"
65
65
  - !ruby/object:Gem::Version
66
- version: '12.0'
66
+ version: '13.0'
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: thor
69
69
  requirement: !ruby/object:Gem::Requirement
@@ -179,6 +179,7 @@ files:
179
179
  - LICENSE.txt
180
180
  - README.md
181
181
  - Rakefile
182
+ - appveyor.yml
182
183
  - bin/cuke_cataloger
183
184
  - cuke_cataloger.gemspec
184
185
  - lib/cuke_cataloger.rb
@@ -199,10 +200,14 @@ files:
199
200
  - testing/fixtures/tests/foo.feature
200
201
  - testing/gemfiles/cuke_modeler0.gemfile
201
202
  - testing/gemfiles/cuke_modeler1.gemfile
203
+ - testing/gemfiles/rake10.gemfile
204
+ - testing/gemfiles/rake11.gemfile
205
+ - testing/gemfiles/rake12.gemfile
202
206
  - testing/rspec/spec/cuke_cataloger_spec.rb
203
207
  - testing/rspec/spec/spec_helper.rb
204
208
  - testing/rspec/spec/unique_test_case_tagger_integration_spec.rb
205
209
  - testing/rspec/spec/unique_test_case_tagger_unit_spec.rb
210
+ - todo.txt
206
211
  homepage: https://github.com/enkessler/cuke_cataloger
207
212
  licenses:
208
213
  - MIT
@@ -223,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
228
  version: '0'
224
229
  requirements: []
225
230
  rubyforge_project:
226
- rubygems_version: 2.6.7
231
+ rubygems_version: 2.5.2
227
232
  signing_key:
228
233
  specification_version: 4
229
234
  summary: A tool to give every Cucumber test a unique id