cuke_cataloger 1.2.0 → 1.3.0

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: 574e7e5f5cb470529c0e545dee407f89e341ba2e
4
- data.tar.gz: b2c082b82da4209fb75fd45baed7ce98b7c4bbe8
3
+ metadata.gz: 7ca57a9cc7f55a7db0a69cac22642da17b709b24
4
+ data.tar.gz: 8ee177287198378826095b0356578e1d66d18180
5
5
  SHA512:
6
- metadata.gz: 663b06f1515ac03d009001a2489d0bfbc8fbaae5b2567a8db1b10abbaf8db5b24e3d3a37d9d5b38b5de5490def11094ddc644efedbc35d4acd9bc419d654867f
7
- data.tar.gz: a341cfdd22f16abb4cb7775fb994f23cd4becca8ce7163d74637ee4a868206e7bfa337befec5b4bfbd32268cc35dda87e510e5d8bedde4c5cfd0336b6c91096c
6
+ metadata.gz: 4d3ebc2a6c56845d242414f29ef9e865b0e815ebcbfe2a75479940d0c7cd4e8a8e31549412c973a121c64cb484995be152546048335b9f0c7ae74e8653bc6f77
7
+ data.tar.gz: 68845af1ed68b6868cef1efd224008afcf6f4b2b12e2f3d5113d7fdfb3e91379220c1c5d8bae9770b01156e43b1ce77216a59c11a151071505a613f50794f12f
data/History.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Release history
2
2
 
3
+ ### Version 1.3.0 / 2017-01-09
4
+
5
+ - Bug fix: Replaced non-Ruby 1.8.x compatible code so that the gem now correctly works with older versions of Ruby.
6
+
7
+ - Added an executable file for the gem so that it can be used without having to use Rake tasks.
8
+
9
+ - A basic cataloging location and prefix is used by default so that specifying these values will not be necessary in many cases.
10
+
11
+
3
12
  ### Version 1.2.0 / 2016-10-02
4
13
 
5
14
  - The gem now declares version limits on all of its dependencies.
data/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  [![Project License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/enkessler/cuke_cataloger/blob/master/LICENSE.txt)
9
9
 
10
10
 
11
- The cuke_cataloger gem is a convenient way to provide a unique id to every test case in your Cucumber test suite.
11
+ The cuke_cataloger gem is a convenient way to provide a unique id to every test case in your Cucumber test suite.
12
12
 
13
13
  ## Installation
14
14
 
@@ -26,7 +26,19 @@ Or install it yourself as:
26
26
 
27
27
  ## Usage
28
28
 
29
- The simplest way to use this gem is to include the Rake tasks that it provides in your project. Just require the gem
29
+ In addition to using the provided classes in any regular Ruby script, the gem's functionality can be accessed through the command line or through the provided Rake tasks.
30
+
31
+ ### Command Line
32
+
33
+ cuke_cataloger catalog_test_cases [--location=LOCATION] [--prefix=PREFIX]
34
+
35
+ and
36
+
37
+ cuke_cataloger validate_test_cases [--location=LOCATION] [--prefix=PREFIX] [--file=FILE]
38
+
39
+ ### Rake Task
40
+
41
+ Require the gem
30
42
 
31
43
  require 'cuke_cataloger'
32
44
 
@@ -40,28 +52,34 @@ If you want the tasks to be created in a certain namespace, simply call the crea
40
52
  CukeCataloger.create_tasks
41
53
  end
42
54
 
43
- The classes used to tag and validate tests could also be used directly in other scripts if you want to do something more complex than the functionality provided by the two predefined Rake tasks.
55
+ This will create tasks that can then be invoked in the usual manner:
56
+
57
+ rake tag_tests['path/to/your/tests','@test_case_']
58
+
59
+ and
60
+
61
+ rake validate_tests['path/to/your/tests','@test_case_','validation_results.txt']
44
62
 
45
63
  ### Adding ids to tests
46
64
 
47
- The tag_tests task will add an id tag to every scenario (and an id column to every outline) in a test suite. To do this, it needs to be provided a directory in which the tests are located and a prefix upon which to base the tagging scheme.
65
+ The the tagging functionality will add an id tag to every scenario (and an id column to every outline) in a test suite. It can be given a directory in which the tests are located and a prefix upon which to base the tagging scheme but, if not given that information, it will use the current directory and a prefix of `@test_case_`.
48
66
 
49
- rake tag_tests['path/to/your/tests','@test_case_']
67
+ rake tag_tests['path/to/your/tests','@my_prefix_']
50
68
 
51
- The above example would result in the tags @test_case_1, @test_case_2, @test_case_3, etc. being added to every test in the given directory.
69
+ The above example would result in the tags `@my_prefix_1`, `@my_prefix_2`, `@my_prefix_3`, etc. being added to every test in the `tests` directory.
52
70
 
53
71
  ### Validating test ids
54
72
 
55
- The validate_tests task scans a given directory for any problems related to id tags and generates a report detailing its results. To do this, it needs to be provided a directory in which the tests are located and a prefix upon which to base the tagging scheme. It can optionally take a file location to which it should output its report instead of printing it to the console.
73
+ The the validating functionality scans a given directory for any problems related to id tags and generates a report detailing its results. It can be given a directory in which the tests are located and a prefix upon which to base the tagging scheme, as well as a file location to which it should output its report but, if not given that information, it will use the current directory and a prefix of `@test_case_` and it will output the report to the console.
56
74
 
57
- rake validate_tests['path/to/your/tests','@test_case_','validation_results.txt']
75
+ rake validate_tests['path/to/your/tests','@my_prefix_','validation_results.txt']
58
76
 
59
- The above example would result in a report called 'validation_results.txt' being generated for any test had problems related to their id (e.g. did not have an id tag, had the same id tag as another test, etc.).
77
+ 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_`.
60
78
 
61
79
  ## Contributing
62
80
 
63
- 1. Fork it ( http://github.com/<my-github-username>/cuke_cataloger/fork )
64
- 2. Create your feature branch (`git checkout -b my-new-feature`)
65
- 3. Commit your changes (`git commit -am 'Add some feature'`)
66
- 4. Push to the branch (`git push origin my-new-feature`)
81
+ 1. Fork it `http://github.com/<my-github-username>/cuke_cataloger/fork`
82
+ 2. Create your feature branch (off of the development branch) `git checkout -b my-new-feature`
83
+ 3. Commit your changes `git commit -am 'Add some feature'`
84
+ 4. Push to the branch `git push origin my-new-feature`
67
85
  5. Create new Pull Request
@@ -0,0 +1,59 @@
1
+ require 'thor'
2
+ require 'cuke_cataloger'
3
+
4
+
5
+ class CLI < Thor
6
+
7
+ desc 'catalog_test_cases', 'Catalog the test cases in LOCATION with an id based on PREFIX'
8
+ option :location, :default => '.'
9
+ option :prefix, :default => '@test_case_'
10
+
11
+ def catalog_test_cases
12
+ puts "Tagging tests in '#{options[:location]}' with tag '#{options[:prefix]}'\n"
13
+
14
+ tagger = CukeCataloger::UniqueTestCaseTagger.new
15
+ tagger.tag_tests(options[:location], options[:prefix])
16
+ end
17
+
18
+ desc 'validate_test_cases', 'Validate the test cases in LOCATION with an id based on PREFIX. Will output the report to FILE, if provided.'
19
+ option :location, :default => '.'
20
+ option :prefix, :default => '@test_case_'
21
+ option :file
22
+
23
+ def validate_test_cases
24
+ puts "Validating tests in '#{options[:location]}' with tag '#{options[:prefix]}'\n"
25
+
26
+ results = CukeCataloger::UniqueTestCaseTagger.new.validate_test_ids(options[:location], options[:prefix])
27
+ report_text = "Validation Results\nProblems found: #{results.count}\n\n"
28
+
29
+
30
+ results_by_category = Hash.new { |hash, key| hash[key] = [] }
31
+
32
+ results.each do |result|
33
+ results_by_category[result[:problem]] << result
34
+ end
35
+
36
+ results_by_category.keys.each do |problem_category|
37
+ report_text << "#{problem_category} problems: #{results_by_category[problem_category].count}\n"
38
+ end
39
+
40
+ results_by_category.keys.each do |problem_category|
41
+ report_text << "\n\n#{problem_category} problems (#{results_by_category[problem_category].count}):\n"
42
+
43
+ results_by_category[problem_category].each do |result|
44
+ report_text << "#{result[:test]}\n"
45
+ end
46
+ end
47
+
48
+ if options[:file]
49
+ puts "Problems found: #{results.count}"
50
+ File.open(options[:file], 'w') { |file| file.write(report_text) }
51
+ else
52
+ puts report_text
53
+ end
54
+ end
55
+
56
+ end
57
+
58
+
59
+ CLI.start(ARGV)
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
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
23
  spec.add_runtime_dependency 'rake', '< 12.0'
24
+ spec.add_runtime_dependency 'thor', '~> 0.0'
24
25
 
25
26
  spec.add_development_dependency 'bundler', '~> 1.5'
26
27
  spec.add_development_dependency 'cucumber', '< 3.0'
@@ -9,22 +9,29 @@ module CukeCataloger
9
9
 
10
10
  extend Rake::DSL
11
11
 
12
+ # todo - test these better
12
13
 
13
14
  def self.create_tasks
14
15
 
15
16
  desc 'Add unique id tags to tests in the given directory'
16
17
  task 'tag_tests', [:directory, :prefix] do |t, args|
17
- puts "Tagging tests in '#{args[:directory]}' with tag '#{args[:prefix]}'\n"
18
+ location = args[:directory] || '.'
19
+ prefix = args[:prefix] || '@test_case_'
20
+
21
+ puts "Tagging tests in '#{location}' with tag '#{prefix}'\n"
18
22
 
19
23
  tagger = CukeCataloger::UniqueTestCaseTagger.new
20
- tagger.tag_tests(args[:directory], args[:prefix])
24
+ tagger.tag_tests(location, prefix)
21
25
  end
22
26
 
23
27
  desc 'Scan tests in the given directory for id problems'
24
28
  task 'validate_tests', [:directory, :prefix, :out_file] do |t, args|
25
- puts "Validating tests in '#{args[:directory]}' with tag '#{args[:prefix]}'\n"
29
+ location = args[:directory] || '.'
30
+ prefix = args[:prefix] || '@test_case_'
31
+
32
+ puts "Validating tests in '#{location}' with tag '#{prefix}'\n"
26
33
 
27
- results = CukeCataloger::UniqueTestCaseTagger.new.validate_test_ids(args[:directory], args[:prefix])
34
+ results = CukeCataloger::UniqueTestCaseTagger.new.validate_test_ids(location, prefix)
28
35
  report_text = "Validation Results\nProblems found: #{results.count}\n\n"
29
36
 
30
37
 
@@ -48,7 +55,7 @@ module CukeCataloger
48
55
 
49
56
  if args[:out_file]
50
57
  puts "Problems found: #{results.count}"
51
- File.write(args[:out_file], report_text)
58
+ File.open(args[:out_file], 'w') { |file| file.write(report_text) }
52
59
  else
53
60
  puts report_text
54
61
  end
@@ -1,3 +1,3 @@
1
1
  module CukeCataloger
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
@@ -0,0 +1,44 @@
1
+ Feature: Cataloging executable
2
+
3
+ Cataloging functionality can be used directly from the command line.
4
+
5
+
6
+ Scenario: Cataloging test cases
7
+
8
+ Note: By default, cataloging will be done in the current directory using the '@test_case_' prefix
9
+
10
+ Given the cuke_cataloger executable is available
11
+ And there are test cases in the "." directory that have not been cataloged with "@test_case_"
12
+ When the following command is executed:
13
+ """
14
+ cuke_cataloger catalog_test_cases
15
+ """
16
+ Then all of the test cases in the "." directory will be cataloged with "@test_case_"
17
+
18
+ Scenario: Specifying cataloging options
19
+ Given the cuke_cataloger executable is available
20
+ And there are test cases in the "tests" directory that have not been cataloged with "@foo"
21
+ When the following command is executed:
22
+ """
23
+ cuke_cataloger catalog_test_cases --location <path_to>/tests --prefix @foo
24
+ """
25
+ Then all of the test cases in the "tests" directory will be cataloged with "@foo"
26
+
27
+ Scenario: Validating test cases
28
+
29
+ Note: By default, validation will be done in the current directory using the '@test_case_' prefix
30
+
31
+ Given the cuke_cataloger executable is available
32
+ When the following command is executed:
33
+ """
34
+ cuke_cataloger validate_test_cases
35
+ """
36
+ Then a validation report for the "." directory with prefix "@test_case_" is output to the console
37
+
38
+ Scenario: Specifying validation options
39
+ Given the cuke_cataloger executable is available
40
+ When the following command is executed:
41
+ """
42
+ cuke_cataloger validate_test_cases --location <path_to>/tests --prefix @foo --file <path_to>/foo.txt
43
+ """
44
+ Then a validation report for the "tests" directory with prefix "@foo" is output to "foo.txt"
@@ -26,3 +26,17 @@ When(/^the existing ids are determined$/) do
26
26
 
27
27
  @ids_found = CukeCataloger::UniqueTestCaseTagger.new.determine_known_ids(@directory.path, @tag_prefix)
28
28
  end
29
+
30
+ When(/^the following command is executed:$/) do |command|
31
+ if command =~ /--file /
32
+ output_file_name = command.match(/--file <path_to>\/(.*)\.txt/)[1]
33
+ command.sub!(/--file <path_to>\/(.*)\.txt/, "--file #{DEFAULT_FILE_DIRECTORY}/#{output_file_name}.txt")
34
+ end
35
+
36
+ command.sub!('<path_to>', FIXTURE_DIRECTORY)
37
+ command = "bundle exec ruby #{@executable_directory}/#{command}"
38
+
39
+ Dir.chdir(FIXTURE_DIRECTORY) do
40
+ @output = `#{command}`
41
+ end
42
+ end
@@ -54,3 +54,16 @@ end
54
54
  And(/^the tag location is unspecified$/) do
55
55
  @above_or_below = nil
56
56
  end
57
+
58
+ Given(/^the cuke_cataloger executable is available$/) do
59
+ @executable_directory = "#{PROJECT_ROOT}/bin"
60
+ end
61
+
62
+ And(/^there are test cases in the "([^"]*)" directory that have not been cataloged with "([^"]*)"$/) do |target_directory, prefix|
63
+ target_directory = "#{FIXTURE_DIRECTORY}/#{target_directory}"
64
+
65
+ @test_results = CukeCataloger::UniqueTestCaseTagger.new.validate_test_ids(target_directory, prefix)
66
+
67
+ # Making sure that there is work to be done, thus avoiding false positives
68
+ expect(@test_results.select { |test_result| test_result[:problem] == :missing_tag }).to_not be_empty
69
+ end
@@ -162,3 +162,27 @@ And(/^the resulting second file is:$/) do |expected_text|
162
162
 
163
163
  expect(actual_text).to eq(expected_text)
164
164
  end
165
+
166
+ Then(/^all of the test cases in the "([^"]*)" directory will be cataloged with "([^"]*)"$/) do |target_directory, prefix|
167
+ target_directory = "#{FIXTURE_DIRECTORY}/#{target_directory}"
168
+
169
+ @test_results = CukeCataloger::UniqueTestCaseTagger.new.validate_test_ids(target_directory, prefix)
170
+
171
+ verify_no_results
172
+ end
173
+
174
+ Then(/^a validation report for the "([^"]*)" directory with prefix "([^"]*)" is output to the console$/) do |target_directory, prefix|
175
+ expect(@output).to include("Validating tests in '#{target_directory}' with tag '#{prefix}'")
176
+ expect(@output).to include("Validation Results")
177
+ end
178
+
179
+ Then(/^a validation report for the "([^"]*)" directory with prefix "([^"]*)" is output to "([^"]*)"$/) do |target_directory, prefix, filename|
180
+ target_directory = "#{FIXTURE_DIRECTORY}/#{target_directory}"
181
+ filename = "#{DEFAULT_FILE_DIRECTORY}/#{filename}"
182
+
183
+ expect(@output).to include("Validating tests in '#{target_directory}' with tag '#{prefix}'")
184
+ expect(@output).to include("Problems found:")
185
+
186
+ expect(File.exists?(filename)).to be true
187
+ expect(File.read(filename)).to include('Validation Results')
188
+ end
@@ -5,18 +5,33 @@ end
5
5
 
6
6
  require 'cuke_cataloger'
7
7
 
8
+ here = File.dirname(__FILE__)
8
9
 
9
10
  DEFAULT_FEATURE_FILE_NAME = 'test_feature'
10
- DEFAULT_FILE_DIRECTORY = "#{File.dirname(__FILE__)}/../temp_files"
11
-
11
+ DEFAULT_FILE_DIRECTORY = "#{here}/../temp_files"
12
+ PROJECT_ROOT = "#{here}/../../.."
13
+ FIXTURE_DIRECTORY = "#{here}/../../fixtures"
12
14
 
13
15
  Before do
14
- @default_feature_file_name = DEFAULT_FEATURE_FILE_NAME
15
- @default_file_directory = DEFAULT_FILE_DIRECTORY
16
+ begin
17
+ @default_feature_file_name = DEFAULT_FEATURE_FILE_NAME
18
+ @default_file_directory = DEFAULT_FILE_DIRECTORY
16
19
 
17
- FileUtils.mkdir(@default_file_directory)
20
+ FileUtils.mkdir(@default_file_directory)
21
+ rescue => e
22
+ puts "Error caught in before hook!"
23
+ puts "Type: #{e.class}"
24
+ puts "Message: #{e.message}"
25
+ end
18
26
  end
19
27
 
20
28
  After do
21
- FileUtils.remove_dir(@default_file_directory, true)
29
+ begin
30
+ `git checkout HEAD -- #{FIXTURE_DIRECTORY}`
31
+ FileUtils.remove_dir(@default_file_directory, true)
32
+ rescue => e
33
+ puts "Error caught in before hook!"
34
+ puts "Type: #{e.class}"
35
+ puts "Message: #{e.message}"
36
+ end
22
37
  end
@@ -0,0 +1,4 @@
1
+ Feature: Foo
2
+
3
+ Scenario: Test 1
4
+ * a step
@@ -0,0 +1,11 @@
1
+ describe 'the gem' do
2
+
3
+ here = File.dirname(__FILE__)
4
+
5
+ let(:gemspec) { eval(File.read "#{here}/../../../cuke_cataloger.gemspec") }
6
+
7
+ it 'has an executable' do
8
+ expect(gemspec.executables).to include('cuke_cataloger')
9
+ end
10
+
11
+ end
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.2.0
4
+ version: 1.3.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: 2016-10-02 00:00:00.000000000 Z
11
+ date: 2017-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cuke_modeler
@@ -64,6 +64,20 @@ dependencies:
64
64
  - - "<"
65
65
  - !ruby/object:Gem::Version
66
66
  version: '12.0'
67
+ - !ruby/object:Gem::Dependency
68
+ name: thor
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '0.0'
74
+ type: :runtime
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '0.0'
67
81
  - !ruby/object:Gem::Dependency
68
82
  name: bundler
69
83
  requirement: !ruby/object:Gem::Requirement
@@ -152,7 +166,8 @@ description: Scans existing Cucumber tests and updates them to include an id tag
152
166
  is unique for the test suite.
153
167
  email:
154
168
  - morrow748@gmail.com
155
- executables: []
169
+ executables:
170
+ - cuke_cataloger
156
171
  extensions: []
157
172
  extra_rdoc_files: []
158
173
  files:
@@ -164,10 +179,12 @@ files:
164
179
  - LICENSE.txt
165
180
  - README.md
166
181
  - Rakefile
182
+ - bin/cuke_cataloger
167
183
  - cuke_cataloger.gemspec
168
184
  - lib/cuke_cataloger.rb
169
185
  - lib/cuke_cataloger/unique_test_case_tagger.rb
170
186
  - lib/cuke_cataloger/version.rb
187
+ - testing/cucumber/features/executable.feature
171
188
  - testing/cucumber/features/formatting.feature
172
189
  - testing/cucumber/features/tag_indexing.feature
173
190
  - testing/cucumber/features/test_case_scanning.feature
@@ -179,8 +196,10 @@ files:
179
196
  - testing/cucumber/step_definitions/verification_steps.rb
180
197
  - testing/cucumber/support/env.rb
181
198
  - testing/cucumber/support/transforms.rb
199
+ - testing/fixtures/tests/foo.feature
182
200
  - testing/gemfiles/cuke_modeler0.gemfile
183
201
  - testing/gemfiles/cuke_modeler1.gemfile
202
+ - testing/rspec/spec/cuke_cataloger_spec.rb
184
203
  - testing/rspec/spec/spec_helper.rb
185
204
  - testing/rspec/spec/unique_test_case_tagger_integration_spec.rb
186
205
  - testing/rspec/spec/unique_test_case_tagger_unit_spec.rb
@@ -204,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
223
  version: '0'
205
224
  requirements: []
206
225
  rubyforge_project:
207
- rubygems_version: 2.2.5
226
+ rubygems_version: 2.6.7
208
227
  signing_key:
209
228
  specification_version: 4
210
229
  summary: A tool to give every Cucumber test a unique id