cuke_slicer 1.0.0 → 2.2.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.
@@ -77,3 +77,27 @@ end
77
77
  Given(/^a slicer$/) do
78
78
  @slicer = CukeSlicer::Slicer.new
79
79
  end
80
+
81
+ And(/^the test cases are to be extracted as objects$/) do
82
+ @output_type = :test_object
83
+ end
84
+
85
+ And(/^an invalid output option$/) do
86
+ @output_type = :invalid_option
87
+ end
88
+
89
+ Given(/^a test suite to extract from$/) do
90
+ @test_directory ||= @default_file_directory
91
+
92
+ @targets ||= []
93
+ @targets << @default_feature_file_name
94
+
95
+
96
+ test_suite = "Feature: Test feature
97
+
98
+ @tag
99
+ Scenario: Test scenario
100
+ * some step"
101
+
102
+ File.write("#{@test_directory}/#{@default_feature_file_name}", test_suite)
103
+ end
@@ -45,3 +45,14 @@ Then(/^an error indicating that the filter is invalid will be triggered$/) do
45
45
  expect(@error_raised).to_not be_nil
46
46
  expect(@error_raised.message).to match(/invalid filter/i)
47
47
  end
48
+
49
+ Then(/^the test cases are provided as objects$/) do
50
+ @output.values.flatten.each do |output|
51
+ expect(output).to be_a(CukeModeler::Scenario).or be_a(CukeModeler::Row)
52
+ end
53
+ end
54
+
55
+ Then(/^an error indicating that the output type is invalid will be triggered$/) do
56
+ expect(@error_raised).to_not be_nil
57
+ expect(@error_raised.message).to match(/Invalid Output Format/i)
58
+ end
@@ -1,6 +1,6 @@
1
1
  Feature: Test case extraction
2
2
 
3
- Test cases can be extracted from a source file or directory as a collection of 'file:line' items that
3
+ Test cases can be extracted from a source file or directory as a collection of 'file:line' items or objects that
4
4
  can then be conveniently arranged for consumption by some other tool (e.g. Cucumber).
5
5
 
6
6
 
@@ -76,3 +76,9 @@ Feature: Test case extraction
76
76
  And the directory "test_directory/empty_directory"
77
77
  When test cases are extracted from "test_directory"
78
78
  Then no test cases are found
79
+
80
+ Scenario: Extracting objects
81
+ Given a test suite to extract from
82
+ And the test cases are to be extracted as objects
83
+ When test cases are extracted from it
84
+ Then the test cases are provided as objects
@@ -54,3 +54,9 @@ Feature: Validation
54
54
  When test cases are extracted from "test_directory"
55
55
  Then the following test cases are found
56
56
  | path/to/test_directory/a_test.feature:3 |
57
+
58
+ Scenario: Invalid output type are not allowed
59
+ Given a test suite to extract from
60
+ And an invalid output option
61
+ When test cases are extracted from it
62
+ Then an error indicating that the output type is invalid will be triggered
@@ -0,0 +1,28 @@
1
+ # Older Rubies on Windows cannot securely connect to RubyGems anymore (https://github.com/rubygems/rubygems/issues/2330)
2
+ if (RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw32/) && (RUBY_VERSION =~ /^1\./)
3
+ source 'http://rubygems.org'
4
+ else
5
+ source 'https://rubygems.org'
6
+ end
7
+
8
+ gemspec :path => "../"
9
+
10
+ # Using the most recent release of the 0.x series in order to have all of the bug fixes.
11
+ gem 'cuke_modeler', '0.4.1'
12
+
13
+ if RUBY_VERSION =~ /^1\./
14
+ gem 'cucumber', '< 3.0.0' # Ruby 1.9.x support dropped after this version
15
+ gem 'ffi', '< 1.9.15' # The 'ffi' 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 'mime-types', '< 3.0.0' # The 'mime-types' gem requires Ruby 2.x on/after this version
18
+ gem 'rainbow', '< 3.0' # The 'rainbow' gem requires Ruby 2.x on/after this version
19
+ gem 'rake', '< 12.3.0' # The 'rake' gem requires Ruby 2.x on/after this version
20
+ gem 'rest-client', '< 2.0' # The 'rainbow' gem requires Ruby 2.x on/after this version
21
+ gem 'simplecov-html', '< 0.11.0' # The 'simplecov-html' gem requires Ruby 2.x on/after this version
22
+ gem 'thor', '< 1.0' # The 'thor' gem requires Ruby 2.x on/after this version
23
+ gem 'tins', '< 1.7' # The 'tins' gem requires Ruby 2.x on/after this version
24
+ gem 'term-ansicolor', '< 1.4' # The 'term-ansicolor' gem requires Ruby 2.x on/after this version
25
+ gem 'unf_ext', '< 0.0.7.3' # The 'unf_ext' gem requires Ruby 2.x on/after this version
26
+ else
27
+ gem 'cucumber', '< 4.0.0' # Cucumber 4.x switches to needing the `cucumber-gherkin` gem, which is incompatible with `cuke_modeler` 0.x
28
+ end
@@ -0,0 +1,29 @@
1
+ # Older Rubies on Windows cannot securely connect to RubyGems anymore (https://github.com/rubygems/rubygems/issues/2330)
2
+ if (RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw32/) && (RUBY_VERSION =~ /^1\./)
3
+ source 'http://rubygems.org'
4
+ else
5
+ source 'https://rubygems.org'
6
+ end
7
+
8
+ gemspec :path => "../"
9
+
10
+ # The version of CukeModeler being tested
11
+ gem 'cuke_modeler', '~> 1.0'
12
+
13
+
14
+ if RUBY_VERSION =~ /^1\./
15
+ gem 'cucumber', '< 3.0.0' # Ruby 1.9.x support dropped after this version
16
+ gem 'ffi', '< 1.9.15' # The 'ffi' gem requires Ruby 2.x on/after this version
17
+ gem 'json', '< 2.0' # The 'json' gem drops pre-Ruby 2.x support on/after this version
18
+ gem 'mime-types', '< 3.0.0' # The 'mime-types' gem requires Ruby 2.x on/after this version
19
+ gem 'rainbow', '< 3.0' # The 'rainbow' gem requires Ruby 2.x on/after this version
20
+ gem 'rake', '< 12.3.0' # The 'rake' gem requires Ruby 2.x on/after this version
21
+ gem 'rest-client', '< 2.0' # The 'rainbow' gem requires Ruby 2.x on/after this version
22
+ gem 'simplecov-html', '< 0.11.0' # The 'simplecov-html' gem requires Ruby 2.x on/after this version
23
+ gem 'thor', '< 1.0' # The 'thor' gem requires Ruby 2.x on/after this version
24
+ gem 'tins', '< 1.7' # The 'tins' gem requires Ruby 2.x on/after this version
25
+ gem 'term-ansicolor', '< 1.4' # The 'term-ansicolor' gem requires Ruby 2.x on/after this version
26
+ gem 'unf_ext', '< 0.0.7.3' # The 'unf_ext' gem requires Ruby 2.x on/after this version
27
+ else
28
+ gem 'cucumber', '< 4.0.0' # Cucumber 4.x switches to needing the `cucumber-gherkin` gem, which is incompatible with `cuke_modeler` 1.x
29
+ end
@@ -0,0 +1,29 @@
1
+ # Older Rubies on Windows cannot securely connect to RubyGems anymore (https://github.com/rubygems/rubygems/issues/2330)
2
+ if (RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw32/) && (RUBY_VERSION =~ /^1\./)
3
+ source 'http://rubygems.org'
4
+ else
5
+ source 'https://rubygems.org'
6
+ end
7
+
8
+ gemspec :path => "../"
9
+
10
+ # The version of CukeModeler being tested
11
+ gem 'cuke_modeler', '~> 2.0'
12
+
13
+
14
+ if RUBY_VERSION =~ /^1\./
15
+ gem 'cucumber', '< 3.0.0' # Ruby 1.9.x support dropped after this version
16
+ gem 'ffi', '< 1.9.15' # The 'ffi' gem requires Ruby 2.x on/after this version
17
+ gem 'json', '< 2.0' # The 'json' gem drops pre-Ruby 2.x support on/after this version
18
+ gem 'mime-types', '< 3.0.0' # The 'mime-types' gem requires Ruby 2.x on/after this version
19
+ gem 'rainbow', '< 3.0' # The 'rainbow' gem requires Ruby 2.x on/after this version
20
+ gem 'rake', '< 12.3.0' # The 'rake' gem requires Ruby 2.x on/after this version
21
+ gem 'rest-client', '< 2.0' # The 'rainbow' gem requires Ruby 2.x on/after this version
22
+ gem 'simplecov-html', '< 0.11.0' # The 'simplecov-html' gem requires Ruby 2.x on/after this version
23
+ gem 'thor', '< 1.0' # The 'thor' gem requires Ruby 2.x on/after this version
24
+ gem 'tins', '< 1.7' # The 'tins' gem requires Ruby 2.x on/after this version
25
+ gem 'term-ansicolor', '< 1.4' # The 'term-ansicolor' gem requires Ruby 2.x on/after this version
26
+ gem 'unf_ext', '< 0.0.7.3' # The 'unf_ext' gem requires Ruby 2.x on/after this version
27
+ else
28
+ gem 'cucumber', '< 4.0.0' # Cucumber 4.x switches to needing the `cucumber-gherkin` gem, which is incompatible with `cuke_modeler` 2.x
29
+ end
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec :path => "../"
4
+
5
+ # The version of CukeModeler being tested
6
+ gem 'cuke_modeler', '~> 3.0'
7
+
8
+ gem 'cucumber', '2.2.0' # `cucumber` 4.x does not currently work on JRuby
9
+
10
+ if RUBY_VERSION =~ /^2\.[1234]/
11
+ gem 'activesupport', '< 6.0' # `activesupport` 6.x requires at least Ruby 2.5
12
+ end
@@ -1,10 +1,10 @@
1
- require 'cuke_modeler'
2
-
3
- require "cuke_slicer/version"
4
- require "cuke_slicer/slicer"
5
-
6
-
7
- # Top level module under which the gem code lives.
8
- module CukeSlicer
9
- # Your code goes here...
10
- end
1
+ require 'cuke_modeler'
2
+
3
+ require "cuke_slicer/version"
4
+ require "cuke_slicer/slicer"
5
+
6
+
7
+ # Top level module under which the gem code lives.
8
+ module CukeSlicer
9
+ # Your code goes here...
10
+ end
@@ -0,0 +1,29 @@
1
+ require "cuke_slicer/helpers/helpers"
2
+
3
+
4
+ # Internal helper module that is not part of the public API. Subject to change at any time.
5
+ # :nodoc: all
6
+ module CukeSlicer
7
+ class NestedTagCollection
8
+
9
+ include Helpers
10
+
11
+
12
+ def initialize collection
13
+ self.nested_collection = collection
14
+ end
15
+
16
+ def validate
17
+ nested_collection.each do |element|
18
+ raise(ArgumentError, "Tag filters cannot be nested more than one level deep.") if element.is_a?(Array)
19
+ raise(ArgumentError, "Filter '#{element}' must be a String or Regexp. Got #{element.class}") unless str_regex?(element)
20
+ end
21
+ end
22
+
23
+
24
+ private
25
+
26
+ attr_accessor :nested_collection
27
+
28
+ end
29
+ end
@@ -0,0 +1,28 @@
1
+ require "cuke_slicer/helpers/helpers"
2
+
3
+
4
+ # Internal helper module that is not part of the public API. Subject to change at any time.
5
+ # :nodoc: all
6
+ module CukeSlicer
7
+ class PathCollection
8
+
9
+ include Helpers
10
+
11
+
12
+ def initialize filter_values
13
+ self.filter_values = filter_values
14
+ end
15
+
16
+ def validate
17
+ filter_values.each do |val|
18
+ raise(ArgumentError, "Filter '#{val}' must be a String or Regexp. Got #{val.class}") unless str_regex?(val)
19
+ end
20
+ end
21
+
22
+
23
+ private
24
+
25
+ attr_accessor :filter_values
26
+
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ require "cuke_slicer/helpers/helpers"
2
+ require "cuke_slicer/collections/nested_tag_collection"
3
+
4
+
5
+ # Internal helper module that is not part of the public API. Subject to change at any time.
6
+ # :nodoc: all
7
+ module CukeSlicer
8
+ class TagCollection
9
+
10
+ include Helpers
11
+
12
+
13
+ def initialize parameters
14
+ self.filter_values = parameters
15
+ end
16
+
17
+ def validate
18
+ filter_values.each do |val|
19
+ raise(ArgumentError, "Filter '#{val}' must be a String, Regexp, or Array. Got #{val.class}") unless str_regex_arr?(val)
20
+ NestedTagCollection.new(val).validate if val.is_a?(Array)
21
+ end
22
+ end
23
+
24
+
25
+ private
26
+
27
+ attr_accessor :filter_values
28
+
29
+ end
30
+ end
@@ -0,0 +1,19 @@
1
+ # Internal helper module that is not part of the public API. Subject to change at any time.
2
+ # :nodoc: all
3
+ module CukeSlicer
4
+ class DirectoryExtractor
5
+
6
+ def extract(target, filters, format, &block)
7
+ Array.new.tap do |test_cases|
8
+ target.feature_files.each do |feature_file|
9
+ test_cases.concat(FileExtractor.new.extract(feature_file, filters, format, &block))
10
+ end
11
+
12
+ target.directories.each do |directory|
13
+ test_cases.concat(extract(directory, filters, format, &block))
14
+ end
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ require "cuke_slicer/helpers/matching_helpers"
2
+ require "cuke_slicer/helpers/filter_helpers"
3
+ require "cuke_slicer/helpers/extraction_helpers"
4
+
5
+
6
+ # Internal helper module that is not part of the public API. Subject to change at any time.
7
+ # :nodoc: all
8
+ module CukeSlicer
9
+ class FileExtractor
10
+
11
+ include ExtractionHelpers
12
+
13
+
14
+ def extract(target, filters, format, &block)
15
+ Array.new.tap do |test_cases|
16
+ unless target.feature.nil?
17
+ tests = target.feature.tests
18
+
19
+ runnable_elements = extract_runnable_elements(extract_runnable_block_elements(tests, filters, &block))
20
+
21
+ runnable_elements.each do |element|
22
+ case
23
+ when format == :file_line
24
+ test_cases << "#{element.get_ancestor(:feature_file).path}:#{element.source_line}"
25
+ when format == :test_object
26
+ test_cases << element
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,44 @@
1
+ require "cuke_slicer/helpers/helpers"
2
+ require "cuke_slicer/collections/tag_collection"
3
+ require "cuke_slicer/collections/path_collection"
4
+
5
+
6
+ # Internal helper module that is not part of the public API. Subject to change at any time.
7
+ # :nodoc: all
8
+ module CukeSlicer
9
+ class FilterSet
10
+
11
+ include Helpers
12
+
13
+
14
+ def initialize filter_type, filter_value
15
+ self.filter_type = filter_type
16
+ self.filter_value = filter_value
17
+ end
18
+
19
+ def validate
20
+ block_unknown
21
+ block_invalid
22
+
23
+ if filter_value.is_a?(Array)
24
+ TagCollection.new(filter_value).validate if is_tag?(filter_type)
25
+ PathCollection.new(filter_value).validate if is_path?(filter_type)
26
+ end
27
+ end
28
+
29
+
30
+ private
31
+
32
+
33
+ def block_unknown
34
+ raise(ArgumentError, "Unknown filter '#{filter_type}'") unless CukeSlicer::Slicer.known_filters.include?(filter_type)
35
+ end
36
+
37
+ def block_invalid
38
+ raise(ArgumentError, "Invalid filter '#{filter_value}'. Must be a String, Regexp, or Array thereof. Got #{filter_value.class}") unless str_regex_arr?(filter_value)
39
+ end
40
+
41
+ attr_accessor :filter_type, :filter_value
42
+
43
+ end
44
+ end
@@ -0,0 +1,44 @@
1
+ # Internal helper module that is not part of the public API. Subject to change at any time.
2
+ # :nodoc: all
3
+ module CukeSlicer
4
+ module ExtractionHelpers
5
+
6
+ include FilterHelpers
7
+
8
+
9
+ def extract_runnable_block_elements(things, filters, &block)
10
+ Array.new.tap do |elements|
11
+ things.each do |thing|
12
+ if thing.is_a?(CukeModeler::Outline)
13
+ elements.concat(thing.examples)
14
+ else
15
+ elements << thing
16
+ end
17
+ end
18
+
19
+ filter_excluded_paths(elements, filters[:excluded_paths])
20
+ filter_included_paths(elements, filters[:included_paths])
21
+ filter_excluded_tags(elements, filters[:excluded_tags])
22
+ filter_included_tags(elements, filters[:included_tags])
23
+
24
+ apply_custom_filter(elements, &block)
25
+ end
26
+ end
27
+
28
+ def extract_runnable_elements(things)
29
+ method_for_row_models = Gem.loaded_specs['cuke_modeler'].version.version[/^0/] ? :row_elements : :rows
30
+
31
+ Array.new.tap do |elements|
32
+ things.each do |thing|
33
+ if thing.is_a?(CukeModeler::Example)
34
+ # Slicing in order to remove the parameter row element
35
+ elements.concat(thing.send(method_for_row_models).slice(1, thing.rows.count))
36
+ else
37
+ elements << thing
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,62 @@
1
+ # Internal helper module that is not part of the public API. Subject to change at any time.
2
+ # :nodoc: all
3
+ module CukeSlicer
4
+ module FilterHelpers
5
+
6
+ include MatchingHelpers
7
+
8
+
9
+ def apply_custom_filter(elements, &block)
10
+ if block
11
+ elements.reject! do |element|
12
+ block.call(element)
13
+ end
14
+ end
15
+ end
16
+
17
+ def filter_excluded_tags(elements, filters)
18
+ if filters
19
+ filters = [filters] unless filters.is_a?(Array)
20
+
21
+ unless filters.empty?
22
+ elements.reject! do |element|
23
+ matching_tag?(element, filters)
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ def filter_included_tags(elements, filters)
30
+ if filters
31
+ filters = [filters] unless filters.is_a?(Array)
32
+
33
+ elements.keep_if do |element|
34
+ matching_tag?(element, filters)
35
+ end
36
+ end
37
+ end
38
+
39
+ def filter_excluded_paths(elements, filters)
40
+ if filters
41
+ filters = [filters] unless filters.is_a?(Array)
42
+
43
+ elements.reject! do |element|
44
+ matching_path?(element, filters)
45
+ end
46
+ end
47
+ end
48
+
49
+ def filter_included_paths(elements, filters)
50
+ if filters
51
+ filters = [filters] unless filters.is_a?(Array)
52
+
53
+ unless filters.empty?
54
+ elements.keep_if do |element|
55
+ matching_path?(element, filters)
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ end
62
+ end