Sha256: 0a3c8d00322a2adcdad06ab504546256ec34a6b677a0988351c4c2e88216db1c

Contents?: true

Size: 902 Bytes

Versions: 3

Compression:

Stored size: 902 Bytes

Contents

# frozen_string_literal: true

module Spout
  module Tests
    module DomainExistenceValidation

      def assert_domain_existence(item)
        domain_names = Dir.glob("domains/**/*.json").collect{|file| file.split('/').last.to_s.downcase.split('.json').first}

        result = begin
          domain_name = JSON.parse(File.read(item))["domain"]
          domain_names.include?(domain_name)
        rescue JSON::ParserError
          domain_name = ''
          false
        end

        message = "The domain #{domain_name} referenced by #{item} does not exist."

        assert result, message
      end

      Dir.glob("variables/**/*.json").each do |file|
        if (not [nil, ''].include?(JSON.parse(File.read(file))["domain"]) rescue false)
          define_method("test_domain_exists: "+file) do
            assert_domain_existence file
          end
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spout-0.12.0.beta2 lib/spout/tests/domain_existence_validation.rb
spout-0.12.0.beta1 lib/spout/tests/domain_existence_validation.rb
spout-0.11.1 lib/spout/tests/domain_existence_validation.rb