Class: CukeCataloger::UniqueTestCaseTagger
- Inherits:
-
Object
- Object
- CukeCataloger::UniqueTestCaseTagger
- Defined in:
- lib/cuke_cataloger/unique_test_case_tagger.rb
Overview
A tagger that handles test case cataloging.
Constant Summary collapse
- SUB_ID_PATTERN =
The pattern of a sub id
/^\d+\-\d+$/
- SUB_ID_MATCH_PATTERN =
The pattern of a sub id, with id capture
/^\d+\-(\d+)$/
Instance Attribute Summary collapse
-
#tag_location ⇒ Object
Where the id tag should be placed, relative to the other tags on the test.
Instance Method Summary collapse
-
#determine_known_ids(feature_directory, tag_prefix = '@test_case_', id_column_name = 'test_case_id') ⇒ Object
Finds existing id tags in feature_directory based on tag_prefix.
-
#initialize ⇒ UniqueTestCaseTagger
constructor
Creates a new UniqueTestCaseTagger object.
-
#scan_for_tagged_tests(feature_directory, tag_prefix = '@test_case_', id_column_name = 'test_case_id') ⇒ Object
Finds existing id tags and their associated tests in feature_directory based on tag_prefix.
-
#tag_tests(feature_directory, tag_prefix = '@test_case_', explicit_indexes = {}, tag_rows = true, id_column_name = 'test_case_id') ⇒ Object
Adds id tags based on tag_prefix to the tests found in feature_directory.
-
#validate_test_ids(feature_directory, tag_prefix = '@test_case_', tag_rows = true, id_column_name = 'test_case_id') ⇒ Object
Checks for cataloging problems in feature_directory based on tag_prefix.
Constructor Details
#initialize ⇒ UniqueTestCaseTagger
Creates a new UniqueTestCaseTagger object
19 20 21 22 |
# File 'lib/cuke_cataloger/unique_test_case_tagger.rb', line 19 def initialize @file_line_increases = Hash.new(0) @tag_location = :adjacent end |
Instance Attribute Details
#tag_location ⇒ Object
Where the id tag should be placed, relative to the other tags on the test
16 17 18 |
# File 'lib/cuke_cataloger/unique_test_case_tagger.rb', line 16 def tag_location @tag_location end |
Instance Method Details
#determine_known_ids(feature_directory, tag_prefix = '@test_case_', id_column_name = 'test_case_id') ⇒ Object
Finds existing id tags in feature_directory based on tag_prefix
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/cuke_cataloger/unique_test_case_tagger.rb', line 92 def determine_known_ids(feature_directory, tag_prefix = '@test_case_', id_column_name = 'test_case_id') known_ids = [] found_tagged_objects = scan_for_tagged_tests(feature_directory, tag_prefix, id_column_name) .collect { |result| result[:object] } found_tagged_objects.each do |element| if element.is_a?(CukeModeler::Row) row_id = row_id_for(element, id_column_name) known_ids << row_id if well_formed_sub_id?(row_id) else known_ids << test_id_for(element) end end known_ids end |
#scan_for_tagged_tests(feature_directory, tag_prefix = '@test_case_', id_column_name = 'test_case_id') ⇒ Object
Finds existing id tags and their associated tests in feature_directory based on tag_prefix
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/cuke_cataloger/unique_test_case_tagger.rb', line 53 def scan_for_tagged_tests(feature_directory, tag_prefix = '@test_case_', id_column_name = 'test_case_id') @results = [] @known_id_tags = {} configure_id_tag(tag_prefix) configure_test_suite_model(feature_directory) @tests.each do |test| add_to_results(test) if id_tag?(test) next unless test.is_a?(CukeModeler::Outline) test.examples.each do |example| next unless id_parameter?(example, id_column_name) example_rows_for(example).each do |row| add_to_results(row) if row_id?(row, id_column_name) end end end @results end |
#tag_tests(feature_directory, tag_prefix = '@test_case_', explicit_indexes = {}, tag_rows = true, id_column_name = 'test_case_id') ⇒ Object
Adds id tags based on tag_prefix to the tests found in feature_directory
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cuke_cataloger/unique_test_case_tagger.rb', line 25 def tag_tests(feature_directory, tag_prefix = '@test_case_', explicit_indexes = {}, tag_rows = true, id_column_name = 'test_case_id') # rubocop:disable Metrics/LineLength warn('This script will potentially rewrite all of your feature files. Please be patient and remember to tip your source control system.') # rubocop:disable Metrics/LineLength @known_id_tags = {} configure_id_tag(tag_prefix) configure_test_suite_model(feature_directory) @start_indexes = merge_indexes(default_start_indexes(determine_known_ids(feature_directory, tag_prefix, id_column_name)), explicit_indexes) @next_index = @start_indexes[:primary] # Analysis and output @tests.each do |test| case when test.is_a?(CukeModeler::Scenario) process_scenario(test) when test.is_a?(CukeModeler::Outline) process_outline(test, tag_rows, id_column_name) else raise("Unknown test type: #{test.class}") end end end |
#validate_test_ids(feature_directory, tag_prefix = '@test_case_', tag_rows = true, id_column_name = 'test_case_id') ⇒ Object
Checks for cataloging problems in feature_directory based on tag_prefix
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/cuke_cataloger/unique_test_case_tagger.rb', line 78 def validate_test_ids(feature_directory, tag_prefix = '@test_case_', tag_rows = true, id_column_name = 'test_case_id') # rubocop:disable Metrics/LineLength @results = [] @known_id_tags = {} configure_id_tag(tag_prefix) configure_test_suite_model(feature_directory) @features.each { |feature| validate_feature(feature) } @tests.each { |test| validate_test(test, tag_rows, id_column_name) } @results end |