Sha256: f4c2e4e9ed03951bd944b42426a6b3790bce3cfa0c09efd94301e7201f214169

Contents?: true

Size: 843 Bytes

Versions: 3

Compression:

Stored size: 843 Bytes

Contents

# frozen_string_literal: true

module Spout
  module Tests
    module JsonValidation
      def assert_valid_json(item, msg = nil)
        result = begin
          !!JSON.parse(File.read(item, encoding: "utf-8"))
        rescue JSON::ParserError => e
          error = e
          false
        end

        message = error.to_s
        assert result, message
      end

      Dir.glob("variables/**/*.json").each do |file|
        define_method("test_json: "+file) do
          assert_valid_json file
        end
      end

      Dir.glob("domains/**/*.json").each do |file|
        define_method("test_json: "+file) do
          assert_valid_json file
        end
      end

      Dir.glob("forms/**/*.json").each do |file|
        define_method("test_json: "+file) do
          assert_valid_json file
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spout-1.0.0 lib/spout/tests/json_validation.rb
spout-1.0.0.beta3 lib/spout/tests/json_validation.rb
spout-1.0.0.beta2 lib/spout/tests/json_validation.rb