cuke_cataloger 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.simplecov +1 -2
- data/.travis.yml +2 -1
- data/Gemfile +1 -1
- data/History.md +5 -0
- data/LICENSE.txt +1 -1
- data/README.md +56 -5
- data/appveyor.yml +20 -31
- data/bin/cuke_cataloger +1 -20
- data/lib/cuke_cataloger.rb +7 -64
- data/lib/cuke_cataloger/formatters/text_report_formatter.rb +33 -0
- data/lib/cuke_cataloger/rake_tasks.rb +46 -0
- data/lib/cuke_cataloger/unique_test_case_tagger.rb +22 -3
- data/lib/cuke_cataloger/version.rb +2 -1
- data/testing/cucumber/features/cataloging_tasks.feature +48 -0
- data/testing/cucumber/step_definitions/action_steps.rb +17 -1
- data/testing/cucumber/step_definitions/setup_steps.rb +17 -10
- data/testing/cucumber/step_definitions/verification_steps.rb +8 -4
- data/testing/cucumber/support/env.rb +10 -7
- data/testing/file_helper.rb +39 -0
- data/testing/fixtures/Rakefile +19 -0
- data/testing/rspec/spec/spec_helper.rb +5 -9
- data/testing/rspec/spec/unique_test_case_tagger_integration_spec.rb +7 -9
- data/testing/rspec/spec/unique_test_case_tagger_unit_spec.rb +6 -2
- data/todo.txt +1 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7105dd4739cfcf77b2b055b427aa21584899e4e9
|
4
|
+
data.tar.gz: f05a36d1ab015534957dfcd679fd2385bdbe4793
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6269a07d0f33bbb791d1b6ea77e26b0aa8366370b84cf26ba0b97e32a2979018680697cf1ff3ad60c4445bb1281f8ba1bab647769be3897b0643045ffe7252e2
|
7
|
+
data.tar.gz: 05f2f4163333b9ae0e548324edeb6e648a145979289c8135dfce8334afba7ed2bb407d1ba43e830de1481741c6d29f55111b235cbb6b5776ee488949baf847b2
|
data/.simplecov
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/History.md
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,16 +1,67 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
[![Gem Version](https://badge.fury.io/rb/cuke_cataloger.svg)](http://badge.fury.io/rb/cuke_cataloger)
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/cuke_cataloger.svg)](https://rubygems.org/gems/cuke_cataloger)
|
2
|
+
[![Dependency Status](https://gemnasium.com/enkessler/cuke_cataloger.svg)](https://gemnasium.com/enkessler/cuke_cataloger)
|
5
3
|
[![Build Status](https://travis-ci.org/enkessler/cuke_cataloger.svg?branch=dev)](https://travis-ci.org/enkessler/cuke_cataloger)
|
6
4
|
[![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
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/github/enkessler/cuke_cataloger/badge.svg?branch=dev)](https://coveralls.io/github/enkessler/cuke_cataloger?branch=dev)
|
8
6
|
[![Code Climate](https://codeclimate.com/github/enkessler/cuke_cataloger/badges/gpa.svg)](https://codeclimate.com/github/enkessler/cuke_cataloger)
|
7
|
+
[![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/gems/cuke_cataloger)
|
8
|
+
[![Inline docs](http://inch-ci.org/github/enkessler/cuke_cataloger.svg?branch=dev)](https://inch-ci.org/github/enkessler/cuke_cataloger?branch=dev)
|
9
9
|
[![Project License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/enkessler/cuke_cataloger/blob/master/LICENSE.txt)
|
10
10
|
|
11
11
|
|
12
|
+
# CukeCataloger
|
13
|
+
|
14
|
+
|
12
15
|
The cuke_cataloger gem is a convenient way to provide a unique id to every test case in your Cucumber test suite.
|
13
16
|
|
17
|
+
Turn your features from this
|
18
|
+
|
19
|
+
````
|
20
|
+
Feature:
|
21
|
+
|
22
|
+
Scenario:
|
23
|
+
* a step
|
24
|
+
|
25
|
+
Scenario Outline:
|
26
|
+
* a step
|
27
|
+
Examples:
|
28
|
+
| param 1 |
|
29
|
+
| value 1 |
|
30
|
+
Examples:
|
31
|
+
| param 1 |
|
32
|
+
| value 1 |
|
33
|
+
| value 2 |
|
34
|
+
|
35
|
+
Scenario:
|
36
|
+
* a step
|
37
|
+
````
|
38
|
+
|
39
|
+
into this!
|
40
|
+
|
41
|
+
````
|
42
|
+
Feature:
|
43
|
+
|
44
|
+
@test_case_1
|
45
|
+
Scenario:
|
46
|
+
* a step
|
47
|
+
|
48
|
+
@test_case_2
|
49
|
+
Scenario Outline:
|
50
|
+
* a step
|
51
|
+
Examples:
|
52
|
+
| param 1 | test_case_id |
|
53
|
+
| value 1 | 2-1 |
|
54
|
+
Examples:
|
55
|
+
| param 1 | test_case_id |
|
56
|
+
| value 1 | 2-2 |
|
57
|
+
| value 2 | 2-3 |
|
58
|
+
|
59
|
+
@test_case_3
|
60
|
+
Scenario:
|
61
|
+
* a step
|
62
|
+
````
|
63
|
+
|
64
|
+
|
14
65
|
## Installation
|
15
66
|
|
16
67
|
Add this line to your application's Gemfile:
|
data/appveyor.yml
CHANGED
@@ -2,55 +2,44 @@ version: '1.0.{build}'
|
|
2
2
|
|
3
3
|
environment:
|
4
4
|
matrix:
|
5
|
-
- RUBY_VERSION:
|
5
|
+
- RUBY_VERSION: 193
|
6
6
|
BUNDLE_GEMFILE: testing/gemfiles/cuke_modeler0.gemfile
|
7
|
-
|
7
|
+
# AppVeyor does not have a 64-bit Ruby 1.9.3
|
8
|
+
- RUBY_VERSION: 23
|
8
9
|
BUNDLE_GEMFILE: testing/gemfiles/cuke_modeler0.gemfile
|
9
|
-
- RUBY_VERSION:
|
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
|
10
|
+
- RUBY_VERSION: 23-x64
|
14
11
|
BUNDLE_GEMFILE: testing/gemfiles/cuke_modeler0.gemfile
|
15
12
|
|
16
|
-
- RUBY_VERSION:
|
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
|
13
|
+
- RUBY_VERSION: 193
|
21
14
|
BUNDLE_GEMFILE: testing/gemfiles/cuke_modeler1.gemfile
|
22
|
-
|
15
|
+
# AppVeyor does not have a 64-bit Ruby 1.9.3
|
16
|
+
- RUBY_VERSION: 23
|
23
17
|
BUNDLE_GEMFILE: testing/gemfiles/cuke_modeler1.gemfile
|
24
|
-
- RUBY_VERSION:
|
18
|
+
- RUBY_VERSION: 23-x64
|
25
19
|
BUNDLE_GEMFILE: testing/gemfiles/cuke_modeler1.gemfile
|
26
20
|
|
27
|
-
- RUBY_VERSION:
|
21
|
+
- RUBY_VERSION: 193
|
28
22
|
BUNDLE_GEMFILE: testing/gemfiles/rake10.gemfile
|
29
|
-
|
23
|
+
# AppVeyor does not have a 64-bit Ruby 1.9.3
|
24
|
+
- RUBY_VERSION: 23
|
30
25
|
BUNDLE_GEMFILE: testing/gemfiles/rake10.gemfile
|
31
|
-
- RUBY_VERSION:
|
32
|
-
BUNDLE_GEMFILE: testing/gemfiles/rake10.gemfile
|
33
|
-
- RUBY_VERSION: 21-x64
|
34
|
-
BUNDLE_GEMFILE: testing/gemfiles/rake10.gemfile
|
35
|
-
- RUBY_VERSION: 22-x64
|
26
|
+
- RUBY_VERSION: 23-x64
|
36
27
|
BUNDLE_GEMFILE: testing/gemfiles/rake10.gemfile
|
37
28
|
|
38
|
-
- RUBY_VERSION: 193
|
29
|
+
- RUBY_VERSION: 193
|
39
30
|
BUNDLE_GEMFILE: testing/gemfiles/rake11.gemfile
|
40
|
-
|
31
|
+
# AppVeyor does not have a 64-bit Ruby 1.9.3
|
32
|
+
- RUBY_VERSION: 23
|
41
33
|
BUNDLE_GEMFILE: testing/gemfiles/rake11.gemfile
|
42
|
-
- RUBY_VERSION:
|
43
|
-
BUNDLE_GEMFILE: testing/gemfiles/rake11.gemfile
|
44
|
-
- RUBY_VERSION: 22-x64
|
34
|
+
- RUBY_VERSION: 23-x64
|
45
35
|
BUNDLE_GEMFILE: testing/gemfiles/rake11.gemfile
|
46
36
|
|
47
|
-
- RUBY_VERSION: 193
|
48
|
-
BUNDLE_GEMFILE: testing/gemfiles/rake12.gemfile
|
49
|
-
- RUBY_VERSION: 200-x64
|
37
|
+
- RUBY_VERSION: 193
|
50
38
|
BUNDLE_GEMFILE: testing/gemfiles/rake12.gemfile
|
51
|
-
|
39
|
+
# AppVeyor does not have a 64-bit Ruby 1.9.3
|
40
|
+
- RUBY_VERSION: 23
|
52
41
|
BUNDLE_GEMFILE: testing/gemfiles/rake12.gemfile
|
53
|
-
- RUBY_VERSION:
|
42
|
+
- RUBY_VERSION: 23-x64
|
54
43
|
BUNDLE_GEMFILE: testing/gemfiles/rake12.gemfile
|
55
44
|
|
56
45
|
|
data/bin/cuke_cataloger
CHANGED
@@ -33,26 +33,7 @@ class CLI < Thor
|
|
33
33
|
puts "Including outline rows\n" if options[:row_id]
|
34
34
|
|
35
35
|
results = CukeCataloger::UniqueTestCaseTagger.new.validate_test_ids(options[:location], options[:prefix], options[:row_id], options[:id_column_name])
|
36
|
-
report_text =
|
37
|
-
|
38
|
-
|
39
|
-
results_by_category = Hash.new { |hash, key| hash[key] = [] }
|
40
|
-
|
41
|
-
results.each do |result|
|
42
|
-
results_by_category[result[:problem]] << result
|
43
|
-
end
|
44
|
-
|
45
|
-
results_by_category.keys.each do |problem_category|
|
46
|
-
report_text << "#{problem_category} problems: #{results_by_category[problem_category].count}\n"
|
47
|
-
end
|
48
|
-
|
49
|
-
results_by_category.keys.each do |problem_category|
|
50
|
-
report_text << "\n\n#{problem_category} problems (#{results_by_category[problem_category].count}):\n"
|
51
|
-
|
52
|
-
results_by_category[problem_category].each do |result|
|
53
|
-
report_text << "#{result[:test]}\n"
|
54
|
-
end
|
55
|
-
end
|
36
|
+
report_text = CukeCataloger::TextReportFormatter.new.format_data(results)
|
56
37
|
|
57
38
|
if options[:file]
|
58
39
|
puts "Problems found: #{results.count}"
|
data/lib/cuke_cataloger.rb
CHANGED
@@ -2,71 +2,14 @@ require 'rake'
|
|
2
2
|
require 'cuke_modeler'
|
3
3
|
require 'cql'
|
4
4
|
|
5
|
-
require 'cuke_cataloger/version'
|
6
|
-
require 'cuke_cataloger/unique_test_case_tagger'
|
7
|
-
|
8
|
-
module CukeCataloger
|
9
|
-
|
10
|
-
extend Rake::DSL
|
11
|
-
|
12
|
-
# todo - test these better
|
13
|
-
|
14
|
-
def self.create_tasks
|
15
|
-
|
16
|
-
desc 'Add unique id tags to tests in the given directory'
|
17
|
-
task 'tag_tests', [:directory, :prefix, :row_id, :id_column_name] do |t, args|
|
18
|
-
location = args[:directory] || '.'
|
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'
|
22
|
-
|
23
|
-
puts "Tagging tests in '#{location}' with tag '#{prefix}'\n"
|
24
|
-
puts "Including outline rows\n" if tag_rows
|
25
|
-
|
26
|
-
tagger = CukeCataloger::UniqueTestCaseTagger.new
|
27
|
-
tagger.tag_tests(location, prefix, {}, tag_rows, id_column_name)
|
28
|
-
end
|
29
|
-
|
30
|
-
desc 'Scan tests in the given directory for id problems'
|
31
|
-
task 'validate_tests', [:directory, :prefix, :out_file, :row_id, :id_column_name] do |t, args|
|
32
|
-
location = args[:directory] || '.'
|
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'
|
36
|
-
|
37
|
-
puts "Validating tests in '#{location}' with tag '#{prefix}'\n"
|
38
|
-
puts "Including outline rows\n" if tag_rows
|
39
5
|
|
40
|
-
|
41
|
-
report_text = "Validation Results\nProblems found: #{results.count}\n\n"
|
6
|
+
# The top level namespace used by this gem
|
42
7
|
|
8
|
+
module CukeCataloger
|
9
|
+
end
|
43
10
|
|
44
|
-
results_by_category = Hash.new { |hash, key| hash[key] = [] }
|
45
|
-
|
46
|
-
results.each do |result|
|
47
|
-
results_by_category[result[:problem]] << result
|
48
|
-
end
|
49
|
-
|
50
|
-
results_by_category.keys.each do |problem_category|
|
51
|
-
report_text << "#{problem_category} problems: #{results_by_category[problem_category].count}\n"
|
52
|
-
end
|
53
|
-
|
54
|
-
results_by_category.keys.each do |problem_category|
|
55
|
-
report_text << "\n\n#{problem_category} problems (#{results_by_category[problem_category].count}):\n"
|
56
|
-
|
57
|
-
results_by_category[problem_category].each do |result|
|
58
|
-
report_text << "#{result[:test]}\n"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
if args[:out_file]
|
63
|
-
puts "Problems found: #{results.count}"
|
64
|
-
File.open(args[:out_file], 'w') { |file| file.write(report_text) }
|
65
|
-
else
|
66
|
-
puts report_text
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
11
|
|
72
|
-
|
12
|
+
require 'cuke_cataloger/version'
|
13
|
+
require 'cuke_cataloger/unique_test_case_tagger'
|
14
|
+
require 'cuke_cataloger/rake_tasks'
|
15
|
+
require 'cuke_cataloger/formatters/text_report_formatter'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module CukeCataloger
|
2
|
+
|
3
|
+
# Not a part of the public API. Subject to change at any time.
|
4
|
+
class TextReportFormatter
|
5
|
+
|
6
|
+
# Formats validation results into a readable text report
|
7
|
+
def format_data(data)
|
8
|
+
report_text = "Validation Results\nProblems found: #{data.count}\n\n"
|
9
|
+
|
10
|
+
|
11
|
+
results_by_category = Hash.new { |hash, key| hash[key] = [] }
|
12
|
+
|
13
|
+
data.each do |result|
|
14
|
+
results_by_category[result[:problem]] << result
|
15
|
+
end
|
16
|
+
|
17
|
+
results_by_category.keys.each do |problem_category|
|
18
|
+
report_text << "#{problem_category} problems: #{results_by_category[problem_category].count}\n"
|
19
|
+
end
|
20
|
+
|
21
|
+
results_by_category.keys.each do |problem_category|
|
22
|
+
report_text << "\n\n#{problem_category} problems (#{results_by_category[problem_category].count}):\n"
|
23
|
+
|
24
|
+
results_by_category[problem_category].each do |result|
|
25
|
+
report_text << "#{result[:test]}\n"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
report_text
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module CukeCataloger
|
2
|
+
|
3
|
+
extend Rake::DSL
|
4
|
+
|
5
|
+
|
6
|
+
# Adds the gem's provided Rake tasks to the namespace from which the method is called
|
7
|
+
def self.create_tasks
|
8
|
+
|
9
|
+
desc 'Add unique id tags to tests in the given directory'
|
10
|
+
task 'tag_tests', [:directory, :prefix, :row_id, :id_column_name] do |t, args|
|
11
|
+
location = args[:directory] || '.'
|
12
|
+
prefix = args[:prefix] || '@test_case_'
|
13
|
+
tag_rows = args[:row_id].nil? ? true : args[:row_id]
|
14
|
+
id_column_name = args[:id_column_name] || 'test_case_id'
|
15
|
+
|
16
|
+
puts "Tagging tests in '#{location}' with tag '#{prefix}'\n"
|
17
|
+
puts "Including outline rows\n" if tag_rows
|
18
|
+
|
19
|
+
tagger = CukeCataloger::UniqueTestCaseTagger.new
|
20
|
+
tagger.tag_tests(location, prefix, {}, tag_rows, id_column_name)
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'Scan tests in the given directory for id problems'
|
24
|
+
task 'validate_tests', [:directory, :prefix, :out_file, :row_id, :id_column_name] do |t, args|
|
25
|
+
location = args[:directory] || '.'
|
26
|
+
prefix = args[:prefix] || '@test_case_'
|
27
|
+
tag_rows = args[:row_id].nil? ? true : args[:row_id]
|
28
|
+
id_column_name = args[:id_column_name] || 'test_case_id'
|
29
|
+
|
30
|
+
puts "Validating tests in '#{location}' with tag '#{prefix}'\n"
|
31
|
+
puts "Including outline rows\n" if tag_rows
|
32
|
+
|
33
|
+
results = CukeCataloger::UniqueTestCaseTagger.new.validate_test_ids(location, prefix, tag_rows, id_column_name)
|
34
|
+
report_text = CukeCataloger::TextReportFormatter.new.format_data(results)
|
35
|
+
|
36
|
+
if args[:out_file]
|
37
|
+
puts "Problems found: #{results.count}"
|
38
|
+
File.open(args[:out_file], 'w') { |file| file.write(report_text) }
|
39
|
+
else
|
40
|
+
puts report_text
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -1,10 +1,17 @@
|
|
1
1
|
module CukeCataloger
|
2
|
+
|
3
|
+
# A tagger that handles test case cataloging.
|
4
|
+
|
2
5
|
class UniqueTestCaseTagger
|
3
6
|
|
4
|
-
|
5
|
-
|
7
|
+
# The pattern of a sub id
|
8
|
+
SUB_ID_PATTERN = /^\d+\-\d+$/ # Not a part of the public API. Subject to change at any time.
|
6
9
|
|
10
|
+
# The pattern of a sub id, with id capture
|
11
|
+
SUB_ID_MATCH_PATTERN = /^\d+\-(\d+)$/ # Not a part of the public API. Subject to change at any time.
|
7
12
|
|
13
|
+
|
14
|
+
# Where the id tag should be placed, relative to the other tags on the test
|
8
15
|
attr_accessor :tag_location
|
9
16
|
|
10
17
|
|
@@ -13,6 +20,7 @@ module CukeCataloger
|
|
13
20
|
@tag_location = :adjacent
|
14
21
|
end
|
15
22
|
|
23
|
+
# Adds id tags based on *tag_prefix* to the tests found in *feature_directory*
|
16
24
|
def tag_tests(feature_directory, tag_prefix, explicit_indexes = {}, tag_rows = true, id_column_name = 'test_case_id')
|
17
25
|
warn("This script will potentially rewrite all of your feature files. Please be patient and remember to tip your source control system.")
|
18
26
|
|
@@ -37,6 +45,7 @@ module CukeCataloger
|
|
37
45
|
end
|
38
46
|
end
|
39
47
|
|
48
|
+
# Finds existing id tags and their associated tests in *feature_directory* based on *tag_prefix*
|
40
49
|
def scan_for_tagged_tests(feature_directory, tag_prefix, id_column_name = 'test_case_id')
|
41
50
|
@results = []
|
42
51
|
@known_id_tags = {}
|
@@ -61,6 +70,7 @@ module CukeCataloger
|
|
61
70
|
@results
|
62
71
|
end
|
63
72
|
|
73
|
+
# Checks for cataloging problems in *feature_directory* based on *tag_prefix*
|
64
74
|
def validate_test_ids(feature_directory, tag_prefix, tag_rows = true, id_column_name = 'test_case_id')
|
65
75
|
@results = []
|
66
76
|
@known_id_tags = {}
|
@@ -74,6 +84,7 @@ module CukeCataloger
|
|
74
84
|
@results
|
75
85
|
end
|
76
86
|
|
87
|
+
# Finds existing id tags in *feature_directory* based on *tag_prefix*
|
77
88
|
def determine_known_ids(feature_directory, tag_prefix, id_column_name = 'test_case_id')
|
78
89
|
known_ids = []
|
79
90
|
|
@@ -198,6 +209,7 @@ module CukeCataloger
|
|
198
209
|
end
|
199
210
|
end
|
200
211
|
|
212
|
+
# Checks the rows of the given test for the given problem
|
201
213
|
def validate_rows(test, rule, desired, row_check, id_column_name)
|
202
214
|
test.examples.each do |example|
|
203
215
|
if has_id_column?(example, id_column_name)
|
@@ -435,10 +447,12 @@ module CukeCataloger
|
|
435
447
|
example.parameters.any? { |parameter| parameter == id_column_name }
|
436
448
|
end
|
437
449
|
|
450
|
+
# Adds an id column to the given parameter row
|
438
451
|
def update_parameter_row(file_lines, line_index, parameter)
|
439
452
|
append_row!(file_lines, line_index, " #{parameter} |")
|
440
453
|
end
|
441
454
|
|
455
|
+
# Adds an id to the given value row
|
442
456
|
def update_value_row(file_lines, line_index, row, row_id, id_column_name)
|
443
457
|
case
|
444
458
|
when needs_adding?(row, id_column_name)
|
@@ -458,16 +472,19 @@ module CukeCataloger
|
|
458
472
|
has_id_parameter?(row.get_ancestor(:example), id_column_name)
|
459
473
|
end
|
460
474
|
|
475
|
+
# Replaces the indicated line of text with the provided line of tet
|
461
476
|
def replace_row!(file_lines, line_index, new_line)
|
462
477
|
file_lines[line_index] = new_line
|
463
478
|
end
|
464
479
|
|
480
|
+
# Adds text to the beginning of the given line (with whitespace loss)
|
465
481
|
def prepend_row!(file_lines, line_index, string)
|
466
482
|
old_row = file_lines[line_index]
|
467
483
|
new_row = string + old_row.lstrip
|
468
484
|
file_lines[line_index] = new_row
|
469
485
|
end
|
470
486
|
|
487
|
+
# Adds text to the end of the given line (with whitespace loss)
|
471
488
|
def append_row!(file_lines, line_index, string)
|
472
489
|
old_row = file_lines[line_index]
|
473
490
|
trailing_bits = old_row[/\s*$/]
|
@@ -509,6 +526,7 @@ module CukeCataloger
|
|
509
526
|
default_indexes
|
510
527
|
end
|
511
528
|
|
529
|
+
# Merges the given index sets (of the shape {:primary => Integer, :sub => Hash}) into a new one
|
512
530
|
def merge_indexes(set1, set2)
|
513
531
|
set1.merge(set2) { |key, set1_value, set2_value|
|
514
532
|
key == :sub ? set1_value.merge(set2_value) : set2_value
|
@@ -540,8 +558,9 @@ module CukeCataloger
|
|
540
558
|
indentation
|
541
559
|
end
|
542
560
|
|
561
|
+
# Adds an id to the given value row (which has a column for an id but no value for it)
|
543
562
|
def fill_in_row(file_lines, line_index, row, row_id, id_column_name)
|
544
|
-
old_row = file_lines[line_index]
|
563
|
+
old_row = file_lines[line_index] # todo - Dead line of code?
|
545
564
|
sections = file_lines[line_index].split('|', -1)
|
546
565
|
|
547
566
|
replacement_index = determine_row_id_cell_index(row, id_column_name)
|
@@ -0,0 +1,48 @@
|
|
1
|
+
Feature: Cataloging tasks
|
2
|
+
|
3
|
+
Cataloging functionality can be invoked using Rake tasks that are provided by this gem.
|
4
|
+
|
5
|
+
|
6
|
+
Background: Rake task availability
|
7
|
+
* the Rake tasks provided by the gem have been loaded
|
8
|
+
|
9
|
+
|
10
|
+
Scenario: Cataloging test cases
|
11
|
+
|
12
|
+
Note: By default, cataloging will be done in the current directory using the '@test_case_' prefix and outline rows will also be cataloged.
|
13
|
+
|
14
|
+
Given there are test cases in the "." directory that have not been cataloged with "@test_case_"
|
15
|
+
When the following task is invoked:
|
16
|
+
"""
|
17
|
+
tag_tests
|
18
|
+
"""
|
19
|
+
Then all of the test cases in the "." directory will be cataloged with "@test_case_"
|
20
|
+
|
21
|
+
Scenario: Specifying cataloging options
|
22
|
+
|
23
|
+
Note: Due to the implementation of teh Rake tasks, not all options can be used from the command line. Some options only work when invoking the task within other code.
|
24
|
+
|
25
|
+
Given there are test cases in the "tests" directory that have not been cataloged with "@foo"
|
26
|
+
When the following code is run:
|
27
|
+
"""
|
28
|
+
Rake::Task['tag_tests'].invoke('<path_to>/tests','@foo', false)
|
29
|
+
"""
|
30
|
+
Then all of the scenarios and outlines in the "tests" directory will be cataloged with "@foo"
|
31
|
+
But outline rows in the "tests" directory are not cataloged
|
32
|
+
|
33
|
+
Scenario: Validating test cases
|
34
|
+
|
35
|
+
Note: By default, validation will be done in the current directory using the '@test_case_' prefix
|
36
|
+
|
37
|
+
When the following task is invoked:
|
38
|
+
"""
|
39
|
+
validate_tests
|
40
|
+
"""
|
41
|
+
Then a validation report for the "." directory with prefix "@test_case_" is output to the console
|
42
|
+
|
43
|
+
Scenario: Specifying validation options
|
44
|
+
When the following task is invoked:
|
45
|
+
"""
|
46
|
+
validate_tests['<path_to>/tests','@foo','<path_to>/foo.txt']
|
47
|
+
"""
|
48
|
+
Then a validation report for the "tests" directory with prefix "@foo" is output to "foo.txt"
|
@@ -30,7 +30,7 @@ end
|
|
30
30
|
When(/^the following command is executed:$/) do |command|
|
31
31
|
if command =~ /--file /
|
32
32
|
output_file_name = command.match(/--file <path_to>\/(.*)\.txt/)[1]
|
33
|
-
command.sub!(/--file <path_to>\/(.*)\.txt/, "--file #{
|
33
|
+
command.sub!(/--file <path_to>\/(.*)\.txt/, "--file #{@root_test_directory}/#{output_file_name}.txt")
|
34
34
|
end
|
35
35
|
|
36
36
|
command.sub!('<path_to>', FIXTURE_DIRECTORY)
|
@@ -40,3 +40,19 @@ When(/^the following command is executed:$/) do |command|
|
|
40
40
|
@output = `#{command}`
|
41
41
|
end
|
42
42
|
end
|
43
|
+
|
44
|
+
When(/^the following task is invoked:$/) do |command|
|
45
|
+
command.sub!('<path_to>/tests', "#{FIXTURE_DIRECTORY}/tests")
|
46
|
+
command.sub!('<path_to>/foo', "#{@root_test_directory}/foo")
|
47
|
+
command = "bundle exec rake #{command}"
|
48
|
+
|
49
|
+
Dir.chdir(FIXTURE_DIRECTORY) do
|
50
|
+
@output = `#{command}`
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
When(/^the following code is run:$/) do |code_text|
|
55
|
+
code_text.sub!('<path_to>', FIXTURE_DIRECTORY)
|
56
|
+
|
57
|
+
eval(code_text)
|
58
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
Given /^the following feature file(?: "([^"]*)")?:$/ do |file_name, file_text|
|
2
|
-
@test_directory = @
|
2
|
+
@test_directory = @root_test_directory
|
3
3
|
@files_created ||= 0
|
4
4
|
@feature_files ||= []
|
5
5
|
|
6
|
-
file_name ||= "#{@
|
7
|
-
|
8
|
-
@feature_files << file_path
|
6
|
+
file_name ||= "test_feature_#{@files_created + 1}"
|
7
|
+
file_name = File.basename(file_name, '.feature')
|
9
8
|
|
10
|
-
|
9
|
+
file_path = CukeCataloger::FileHelper.create_feature_file(:directory => @test_directory, :name => file_name, :text => file_text)
|
10
|
+
@feature_files << file_path
|
11
11
|
|
12
12
|
@files_created += 1
|
13
13
|
end
|
@@ -27,15 +27,17 @@ And(/^a start index of "([^"]*)" for testcase "([^"]*)"$/) do |sub_index, parent
|
|
27
27
|
end
|
28
28
|
|
29
29
|
Given(/^a feature file$/) do
|
30
|
-
@test_directory = @
|
30
|
+
@test_directory = @root_test_directory
|
31
31
|
@files_created ||= 0
|
32
32
|
@feature_files ||= []
|
33
33
|
|
34
|
-
file_name
|
35
|
-
|
36
|
-
@feature_files << file_path
|
34
|
+
file_name = "test_feature_#{@files_created + 1}.feature"
|
35
|
+
file_name = File.basename(file_name, '.feature')
|
37
36
|
|
38
|
-
|
37
|
+
file_text = "Feature:\nScenario Outline:\n* a step\nExamples:\n| param 1 |\n| value 1 |"
|
38
|
+
|
39
|
+
file_path = CukeCataloger::FileHelper.create_feature_file(:directory => @test_directory, :name => file_name, :text => file_text)
|
40
|
+
@feature_files << file_path
|
39
41
|
|
40
42
|
@files_created += 1
|
41
43
|
end
|
@@ -67,3 +69,8 @@ And(/^there are test cases in the "([^"]*)" directory that have not been catalog
|
|
67
69
|
# Making sure that there is work to be done, thus avoiding false positives
|
68
70
|
expect(@test_results.select { |test_result| test_result[:problem] == :missing_tag }).to_not be_empty
|
69
71
|
end
|
72
|
+
|
73
|
+
Given(/^the Rake tasks provided by the gem have been loaded$/) do
|
74
|
+
File.open("#{FIXTURE_DIRECTORY}/Rakefile", 'a') { |file| file.puts 'CukeCataloger.create_tasks' }
|
75
|
+
CukeCataloger.create_tasks
|
76
|
+
end
|
@@ -116,14 +116,18 @@ def verify_category_results(category, results)
|
|
116
116
|
end
|
117
117
|
|
118
118
|
def verify_results(results)
|
119
|
-
|
119
|
+
actual = @test_results.collect { |test_result| test_result[:test] }
|
120
|
+
expected = process_expected_results(results)
|
121
|
+
|
122
|
+
expect(actual).to match_array(expected)
|
120
123
|
end
|
121
124
|
|
122
|
-
def
|
125
|
+
def process_expected_results(results)
|
123
126
|
results = results.raw.flatten
|
124
|
-
results.collect { |test_path| test_path.sub('path/to', @
|
127
|
+
results.collect { |test_path| test_path.sub('path/to', @root_test_directory) }
|
125
128
|
end
|
126
129
|
|
130
|
+
|
127
131
|
Then(/^the resulting first file is:$/) do |expected_text|
|
128
132
|
file_name = @feature_files[0]
|
129
133
|
|
@@ -197,7 +201,7 @@ end
|
|
197
201
|
|
198
202
|
Then(/^a validation report for the "([^"]*)" directory with prefix "([^"]*)" is output to "([^"]*)"$/) do |target_directory, prefix, filename|
|
199
203
|
target_directory = "#{FIXTURE_DIRECTORY}/#{target_directory}"
|
200
|
-
filename = "#{
|
204
|
+
filename = "#{@root_test_directory}/#{filename}"
|
201
205
|
|
202
206
|
expect(@output).to include("Validating tests in '#{target_directory}' with tag '#{prefix}'")
|
203
207
|
expect(@output).to include("Problems found:")
|
@@ -3,21 +3,18 @@ unless RUBY_VERSION.to_s < '1.9.0'
|
|
3
3
|
SimpleCov.command_name('cuke_cataloger-cucumber')
|
4
4
|
end
|
5
5
|
|
6
|
+
|
6
7
|
require 'cuke_cataloger'
|
7
8
|
|
8
9
|
here = File.dirname(__FILE__)
|
10
|
+
require "#{here}/../../file_helper"
|
9
11
|
|
10
|
-
DEFAULT_FEATURE_FILE_NAME = 'test_feature'
|
11
|
-
DEFAULT_FILE_DIRECTORY = "#{here}/../temp_files"
|
12
12
|
PROJECT_ROOT = "#{here}/../../.."
|
13
13
|
FIXTURE_DIRECTORY = "#{here}/../../fixtures"
|
14
14
|
|
15
15
|
Before do
|
16
16
|
begin
|
17
|
-
@
|
18
|
-
@default_file_directory = DEFAULT_FILE_DIRECTORY
|
19
|
-
|
20
|
-
FileUtils.mkdir(@default_file_directory)
|
17
|
+
@root_test_directory = CukeCataloger::FileHelper.create_directory
|
21
18
|
rescue => e
|
22
19
|
puts "Error caught in before hook!"
|
23
20
|
puts "Type: #{e.class}"
|
@@ -28,10 +25,16 @@ end
|
|
28
25
|
After do
|
29
26
|
begin
|
30
27
|
`git checkout HEAD -- #{FIXTURE_DIRECTORY}`
|
31
|
-
FileUtils.remove_dir(@default_file_directory, true)
|
32
28
|
rescue => e
|
33
29
|
puts "Error caught in before hook!"
|
34
30
|
puts "Type: #{e.class}"
|
35
31
|
puts "Message: #{e.message}"
|
36
32
|
end
|
37
33
|
end
|
34
|
+
|
35
|
+
|
36
|
+
at_exit {
|
37
|
+
CukeCataloger::FileHelper.created_directories.each do |dir_path|
|
38
|
+
FileUtils.remove_entry(dir_path, true)
|
39
|
+
end
|
40
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module CukeCataloger
|
2
|
+
module FileHelper
|
3
|
+
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def create_feature_file(options = {})
|
7
|
+
options[:text] ||= 'Feature:'
|
8
|
+
options[:name] ||= 'test_file'
|
9
|
+
|
10
|
+
create_file(:text => options[:text], :name => options[:name], :extension => '.feature', :directory => options[:directory])
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_file(options = {})
|
14
|
+
options[:text] ||= ''
|
15
|
+
options[:name] ||= 'test_file'
|
16
|
+
options[:extension] ||= '.txt'
|
17
|
+
options[:directory] ||= create_directory
|
18
|
+
|
19
|
+
file_path = "#{options[:directory]}/#{options[:name]}#{options[:extension]}"
|
20
|
+
File.open(file_path, 'w') { |file| file.write(options[:text]) }
|
21
|
+
|
22
|
+
file_path
|
23
|
+
end
|
24
|
+
|
25
|
+
def created_directories
|
26
|
+
@created_directories ||= []
|
27
|
+
end
|
28
|
+
|
29
|
+
def create_directory
|
30
|
+
new_dir = Dir::mktmpdir
|
31
|
+
created_directories << new_dir
|
32
|
+
|
33
|
+
new_dir
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
unless RUBY_VERSION.to_s < '1.9.0'
|
2
|
+
require 'simplecov'
|
3
|
+
require 'securerandom'
|
4
|
+
|
5
|
+
SimpleCov.start do
|
6
|
+
root File.dirname(__FILE__) + '/../..'
|
7
|
+
|
8
|
+
# Every test process will need its own unique name or else they will override each others' coverage data
|
9
|
+
command_name("cuke_cataloger-fixtures-#{SecureRandom.uuid}")
|
10
|
+
|
11
|
+
add_filter '/testing/'
|
12
|
+
|
13
|
+
merge_timeout 300
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
require 'cuke_cataloger'
|
@@ -4,24 +4,20 @@ unless RUBY_VERSION.to_s < '1.9.0'
|
|
4
4
|
end
|
5
5
|
|
6
6
|
here = File.dirname(__FILE__)
|
7
|
-
|
7
|
+
require "#{here}/../../file_helper"
|
8
8
|
|
9
9
|
require 'cuke_cataloger'
|
10
10
|
|
11
|
-
require 'tempfile'
|
12
11
|
|
13
12
|
RSpec.configure do |config|
|
14
13
|
config.before(:all) do
|
15
|
-
@default_file_directory = "#{here}/temp_files"
|
16
|
-
@default_test_file_directory = "#{here}/test_files"
|
17
14
|
@lib_directory = "#{here}/../../../lib"
|
18
15
|
end
|
19
16
|
|
20
|
-
config.
|
21
|
-
|
17
|
+
config.after(:all) do
|
18
|
+
CukeCataloger::FileHelper.created_directories.each do |dir_path|
|
19
|
+
FileUtils.remove_entry(dir_path, true)
|
20
|
+
end
|
22
21
|
end
|
23
22
|
|
24
|
-
config.after(:each) do
|
25
|
-
FileUtils.remove_dir(@default_file_directory, true)
|
26
|
-
end
|
27
23
|
end
|
@@ -20,7 +20,7 @@ describe 'UniqueTestCaseTagger, Integration' do
|
|
20
20
|
# Using ids that are not used for memory allocation by Ruby since they are used for predefined constants.
|
21
21
|
@tagger.instance_variable_set(:@known_id_tags, {0 => '123', 2 => '456'})
|
22
22
|
|
23
|
-
@tagger.tag_tests(
|
23
|
+
Dir.mktmpdir { |path| @tagger.tag_tests(path, '') }
|
24
24
|
|
25
25
|
expect(@tagger.instance_variable_get(:@known_id_tags)).to_not include(0)
|
26
26
|
expect(@tagger.instance_variable_get(:@known_id_tags)).to_not include(1)
|
@@ -39,7 +39,7 @@ describe 'UniqueTestCaseTagger, Integration' do
|
|
39
39
|
# Using ids that are not used for memory allocation by Ruby since they are used for predefined constants.
|
40
40
|
@tagger.instance_variable_set(:@known_id_tags, {0 => '123', 2 => '456'})
|
41
41
|
|
42
|
-
@tagger.validate_test_ids(
|
42
|
+
Dir.mktmpdir { |path| @tagger.validate_test_ids(path, '') }
|
43
43
|
|
44
44
|
expect(@tagger.instance_variable_get(:@known_id_tags)).to_not include(0)
|
45
45
|
expect(@tagger.instance_variable_get(:@known_id_tags)).to_not include(1)
|
@@ -58,7 +58,7 @@ describe 'UniqueTestCaseTagger, Integration' do
|
|
58
58
|
# Using ids that are not used for memory allocation by Ruby since they are used for predefined constants.
|
59
59
|
@tagger.instance_variable_set(:@known_id_tags, {0 => '123', 2 => '456'})
|
60
60
|
|
61
|
-
@tagger.scan_for_tagged_tests(
|
61
|
+
Dir.mktmpdir { |path| @tagger.scan_for_tagged_tests(path, '') }
|
62
62
|
|
63
63
|
expect(@tagger.instance_variable_get(:@known_id_tags)).to_not include(0)
|
64
64
|
expect(@tagger.instance_variable_get(:@known_id_tags)).to_not include(1)
|
@@ -76,14 +76,14 @@ describe 'UniqueTestCaseTagger, Integration' do
|
|
76
76
|
# Using ids that are not used for memory allocation by Ruby since they are used for predefined constants.
|
77
77
|
@tagger.instance_variable_set(:@known_id_tags, {0 => '123', 2 => '456'})
|
78
78
|
|
79
|
-
@tagger.determine_known_ids(
|
79
|
+
Dir.mktmpdir { |path| @tagger.determine_known_ids(path, '') }
|
80
80
|
|
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
84
|
|
85
85
|
it 'does not count id like values that are not in the specified id column' do
|
86
|
-
|
86
|
+
test_directory = CukeCataloger::FileHelper.create_directory
|
87
87
|
|
88
88
|
text = "Feature:
|
89
89
|
|
@@ -106,12 +106,10 @@ describe 'UniqueTestCaseTagger, Integration' do
|
|
106
106
|
Scenario:
|
107
107
|
* a step"
|
108
108
|
|
109
|
-
|
110
|
-
input_file.close
|
111
|
-
temp_directory = input_file.path.match(/(.*)\/foo.*\.feature/)[1]
|
109
|
+
CukeCataloger::FileHelper.create_feature_file(:directory => test_directory, :text => text)
|
112
110
|
|
113
111
|
|
114
|
-
result = @tagger.determine_known_ids(
|
112
|
+
result = @tagger.determine_known_ids(test_directory, '@test_case_', 'foobar')
|
115
113
|
|
116
114
|
|
117
115
|
expect(result).to_not include('2-1', '2-2', '2-3')
|
@@ -29,7 +29,9 @@ describe 'UniqueTestCaseTagger, Unit' do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'returns validation results' do
|
32
|
-
|
32
|
+
results = Dir.mktmpdir { |path| @tagger.validate_test_ids(path, '') }
|
33
|
+
|
34
|
+
expect(results).to be_a_kind_of(Array)
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
@@ -43,7 +45,9 @@ describe 'UniqueTestCaseTagger, Unit' do
|
|
43
45
|
end
|
44
46
|
|
45
47
|
it 'returns scanning results' do
|
46
|
-
|
48
|
+
results = Dir.mktmpdir { |path| @tagger.scan_for_tagged_tests(path, '') }
|
49
|
+
|
50
|
+
expect(results).to be_a_kind_of(Array)
|
47
51
|
end
|
48
52
|
end
|
49
53
|
|
data/todo.txt
CHANGED
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.4.
|
4
|
+
version: 1.4.1
|
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-
|
11
|
+
date: 2017-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cuke_modeler
|
@@ -183,8 +183,11 @@ files:
|
|
183
183
|
- bin/cuke_cataloger
|
184
184
|
- cuke_cataloger.gemspec
|
185
185
|
- lib/cuke_cataloger.rb
|
186
|
+
- lib/cuke_cataloger/formatters/text_report_formatter.rb
|
187
|
+
- lib/cuke_cataloger/rake_tasks.rb
|
186
188
|
- lib/cuke_cataloger/unique_test_case_tagger.rb
|
187
189
|
- lib/cuke_cataloger/version.rb
|
190
|
+
- testing/cucumber/features/cataloging_tasks.feature
|
188
191
|
- testing/cucumber/features/executable.feature
|
189
192
|
- testing/cucumber/features/formatting.feature
|
190
193
|
- testing/cucumber/features/tag_indexing.feature
|
@@ -197,6 +200,8 @@ files:
|
|
197
200
|
- testing/cucumber/step_definitions/verification_steps.rb
|
198
201
|
- testing/cucumber/support/env.rb
|
199
202
|
- testing/cucumber/support/transforms.rb
|
203
|
+
- testing/file_helper.rb
|
204
|
+
- testing/fixtures/Rakefile
|
200
205
|
- testing/fixtures/tests/foo.feature
|
201
206
|
- testing/gemfiles/cuke_modeler0.gemfile
|
202
207
|
- testing/gemfiles/cuke_modeler1.gemfile
|