Sha256: 1a7a2b36c0ac3254116666c07099ee23b8322733b7a2b804061669f2064170b8

Contents?: true

Size: 819 Bytes

Versions: 3

Compression:

Stored size: 819 Bytes

Contents

# frozen_string_literal: true

module Spout
  module Tests
    module DomainFormat

      def assert_domain_format(item)
        result = begin
          json = JSON.parse(File.read(item))
          if json.is_a?(Array)
            json.empty? or json.select{|o| not o.is_a?(Hash)}.size == 0
          else
            false
          end
        rescue JSON::ParserError
          false
        end

        message = "Must be an array of choice hashes. Ex:\n[\n  {\n    \"value\":        \"1\",\n    \"display_name\": \"Option 1\",\n    \"description\":  \"...\"\n  },\n  { ... },\n  ...\n]"

        assert result, message
      end

      Dir.glob("domains/**/*.json").each do |file|
        define_method("test_domain_format: "+file) do
          assert_domain_format file
        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_format.rb
spout-0.12.0.beta1 lib/spout/tests/domain_format.rb
spout-0.11.1 lib/spout/tests/domain_format.rb