Sha256: 59d5911e50cff2c893420e05656c35dc6f83534c3edf7720888e353673a9095b

Contents?: true

Size: 1008 Bytes

Versions: 2

Compression:

Stored size: 1008 Bytes

Contents

require 'helper'
require 'json'

module Hana
  class TestIETF < TestCase
    TESTDIR = File.dirname File.expand_path __FILE__
    json    = File.read File.join TESTDIR, 'json-patch-tests', 'tests.json'
    tests = JSON.load json
    tests.each_with_index do |test, i|
      next unless test['doc']

      define_method("test_#{test['comment'] || i }") do
        skip "disabled" if test['disabled']

        doc   = test['doc']
        patch = test['patch']

        patch = Hana::Patch.new patch

        if test['error']
          assert_raises(ex(test['error'])) do
            patch.apply doc
          end
        else
          assert_equal(test['expected'] || doc, patch.apply(doc))
        end
      end
    end

    private

    def ex msg
      case msg
      when /Out of bounds/i then Hana::Patch::OutOfBoundsException
      when /Object operation on array/ then
        Hana::Patch::ObjectOperationOnArrayException
      else
        Hana::Patch::FailedTestException
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hana-1.2.0 test/test_ietf.rb
hana-1.1.0 test/test_ietf.rb