Sha256: 85f0f2293239a6360670d6b3bc51d3beb40bd202ffd8ba3616829b71424fe1d7

Contents?: true

Size: 1.09 KB

Versions: 11

Compression:

Stored size: 1.09 KB

Contents

require 'test_helper'

module Schemacop
  class CollectorTest < Minitest::Test
    def test_no_root_node
      s = Schema.new do
        req :a, :string
      end

      col = s.validate(a: 0)
      assert col.exceptions.first[:path].first !~ %r{^/root}, 'Root node is present in the path.'
    end

    def test_correct_path
      s = Schema.new do
        req :long_symbol, :string
        req 'long_string', :string
        req 123, :string
      end

      col = s.validate('long_string' => 0, long_symbol: 0, 123 => 0)

      symbol = col.exceptions[0]
      string = col.exceptions[1]
      number = col.exceptions[2]

      assert symbol[:path].first =~ %r{^/long_symbol}
      assert string[:path].first =~ %r{^/long_string}
      assert number[:path].first =~ %r{^/123}
    end

    def test_nested_paths
      s = Schema.new do
        req :one do
          req :two, :string
        end
        req :three, :string
      end

      col = s.validate(one: { two: 0 }, three: 0)
      assert_equal 2, col.exceptions[0][:path].length
      assert_equal 1, col.exceptions[1][:path].length
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
schemacop-2.4.7 test/collector_test.rb
schemacop-2.4.6 test/collector_test.rb
schemacop-2.4.5 test/collector_test.rb
schemacop-2.4.4 test/collector_test.rb
schemacop-2.4.3 test/collector_test.rb
schemacop-2.4.2 test/collector_test.rb
schemacop-2.4.1 test/collector_test.rb
schemacop-2.4.0 test/collector_test.rb
schemacop-2.3.2 test/collector_test.rb
schemacop-2.3.1 test/collector_test.rb
schemacop-2.3.0 test/collector_test.rb