class RainforestCli::Validator
Constants
- API_TOKEN_ERROR
- VALIDATIONS_FAILED
- VALIDATIONS_PASSED
Attributes
local_tests[R]
remote_tests[R]
Public Class Methods
new(options, local_tests = nil, remote_tests = nil)
click to toggle source
# File lib/rainforest_cli/validator.rb, line 9 def initialize(options, local_tests = nil, remote_tests = nil) @local_tests = local_tests || RainforestCli::TestFiles.new(options) @remote_tests = remote_tests || RainforestCli::RemoteTests.new(options) end
Public Instance Methods
invalid?()
click to toggle source
# File lib/rainforest_cli/validator.rb, line 30 def invalid? # Assign result to variables to ensure both methods are called # (no short-circuiting with ||) parsing_errors = has_parsing_errors? dependency_errors = has_test_dependency_errors? duplicate_rfml_id_errors = has_duplicate_rfml_id_errors? is_invalid = parsing_errors || dependency_errors || duplicate_rfml_id_errors logger.info '' logger.info(is_invalid ? VALIDATIONS_FAILED : VALIDATIONS_PASSED) is_invalid end
validate()
click to toggle source
# File lib/rainforest_cli/validator.rb, line 14 def validate check_test_directory_for_tests! exit 1 if invalid? end
validate_with_exception!()
click to toggle source
# File lib/rainforest_cli/validator.rb, line 19 def validate_with_exception! check_test_directory_for_tests! unless http_client.api_token_set? logger.error API_TOKEN_ERROR exit 2 end exit 1 if invalid? end
Private Instance Methods
all_rfml_ids()
click to toggle source
# File lib/rainforest_cli/validator.rb, line 127 def all_rfml_ids local_rfml_ids + remote_rfml_ids end
check_for_nested_embed(rfml_test, root_id, root_file)
click to toggle source
# File lib/rainforest_cli/validator.rb, line 106 def check_for_nested_embed(rfml_test, root_id, root_file) rfml_test.embedded_ids.each do |embed_id| descendant = test_dictionary[embed_id] # existence for embedded tests is covered in #has_nonexisting_tests? next unless descendant if descendant.embedded_ids.include?(root_id) circular_dependencies_notification(root_file, descendant.file_name) if descendant.embedded_ids.include?(root_id) return true end check_for_nested_embed(descendant, root_id, root_file) end false end
check_test_directory_for_tests!()
click to toggle source
# File lib/rainforest_cli/validator.rb, line 46 def check_test_directory_for_tests! unless local_tests.count > 0 logger.error "No tests found in directory: #{local_tests.test_folder}" exit 3 end end
circular_dependencies_notification(file_a, file_b)
click to toggle source
# File lib/rainforest_cli/validator.rb, line 164 def circular_dependencies_notification(file_a, file_b) logger.error 'The following files are embedding one another:' logger.error '' logger.error "\t#{file_a}" logger.error "\t#{file_b}" logger.error '' end
collect_duplicate_rfml_ids()
click to toggle source
# File lib/rainforest_cli/validator.rb, line 60 def collect_duplicate_rfml_ids rfml_ids_and_counts = Hash.new(0) local_tests.test_data.each do |test| rfml_ids_and_counts[test.rfml_id] += 1 end rfml_ids_and_counts.select {|_, count| count > 1} end
duplicate_rfml_ids_notification(duplicate_rfml_ids_and_counts)
click to toggle source
# File lib/rainforest_cli/validator.rb, line 172 def duplicate_rfml_ids_notification(duplicate_rfml_ids_and_counts) logger.error "The test ids are not unique!" logger.error '' duplicate_rfml_ids_and_counts.each do |rfml_id, count| count_str = count == 1 ? 'is 1 file' : "are #{count} files" logger.error "\tThere #{count_str} with an id of #{rfml_id}" end logger.error '' end
has_circular_dependencies?()
click to toggle source
# File lib/rainforest_cli/validator.rb, line 96 def has_circular_dependencies? # TODO: Check embedded tests for remote tests as well. The Rainforest Ruby client # doesn't appear to support elements yet. has_circular_dependencies = false rfml_tests.each do |rfml_test| has_circular_dependencies ||= check_for_nested_embed(rfml_test, rfml_test.rfml_id, rfml_test.file_name) end has_circular_dependencies end
has_duplicate_rfml_id_errors?()
click to toggle source
# File lib/rainforest_cli/validator.rb, line 53 def has_duplicate_rfml_id_errors? duped_rfml_ids_and_counts = collect_duplicate_rfml_ids return false unless duped_rfml_ids_and_counts.size > 0 duplicate_rfml_ids_notification(duped_rfml_ids_and_counts) true end
has_nonexisting_tests?()
click to toggle source
# File lib/rainforest_cli/validator.rb, line 87 def has_nonexisting_tests? contains_nonexistent_ids = rfml_tests.select { |t| (t.embedded_ids - all_rfml_ids).any? } return false unless contains_nonexistent_ids.any? nonexisting_embedded_id_notification(contains_nonexistent_ids) true end
has_parsing_errors?()
click to toggle source
# File lib/rainforest_cli/validator.rb, line 68 def has_parsing_errors? logger.info 'Validating parsing errors...' has_parsing_errors = rfml_tests.select { |t| t.errors.any? } return false unless has_parsing_errors.any? parsing_error_notification(has_parsing_errors) true end
has_test_dependency_errors?()
click to toggle source
# File lib/rainforest_cli/validator.rb, line 78 def has_test_dependency_errors? logger.info 'Validating embedded test IDs...' # Assign result to variables to ensure both methods are called nonexisting_tests = has_nonexisting_tests? circular_dependencies = has_circular_dependencies? nonexisting_tests || circular_dependencies end
http_client()
click to toggle source
# File lib/rainforest_cli/validator.rb, line 186 def http_client RainforestCli.http_client end
local_rfml_ids()
click to toggle source
# File lib/rainforest_cli/validator.rb, line 131 def local_rfml_ids @local_rfml_ids ||= local_tests.rfml_ids end
logger()
click to toggle source
# File lib/rainforest_cli/validator.rb, line 182 def logger RainforestCli.logger end
nonexisting_embedded_id_notification(rfml_tests)
click to toggle source
# File lib/rainforest_cli/validator.rb, line 155 def nonexisting_embedded_id_notification(rfml_tests) logger.error 'The following files contain unknown embedded test IDs:' logger.error '' rfml_tests.each do |rfml_test| logger.error "\t#{rfml_test.file_name}" end logger.error '' end
parsing_error_notification(rfml_tests)
click to toggle source
# File lib/rainforest_cli/validator.rb, line 143 def parsing_error_notification(rfml_tests) logger.error 'Parsing errors:' logger.error '' rfml_tests.each do |rfml_test| logger.error "\t#{rfml_test.file_name}" rfml_test.errors.each do |_line, error| logger.error "\t#{error}" end end logger.error '' end
remote_rfml_ids()
click to toggle source
# File lib/rainforest_cli/validator.rb, line 135 def remote_rfml_ids @remote_rfml_ids ||= remote_tests.rfml_ids end
rfml_tests()
click to toggle source
# File lib/rainforest_cli/validator.rb, line 123 def rfml_tests @rfml_tests ||= local_tests.test_data end
test_dictionary()
click to toggle source
# File lib/rainforest_cli/validator.rb, line 139 def test_dictionary @test_dictionary ||= local_tests.test_dictionary end