Sha256: c3c7c214926d09193138086e2c80cc4ca4074014321f3fb3bd649c875139914d

Contents?: true

Size: 1.42 KB

Versions: 7

Compression:

Stored size: 1.42 KB

Contents

require "strong_json"

describe StrongJSON::Type::ErrorPath do
  ErrorPath = StrongJSON::Type::ErrorPath
  include StrongJSON::Types

  describe "root path" do
    let(:path) { ErrorPath.root(string) }

    it "does not have parent" do
      expect(path.parent).to be_nil
    end

    it "has type" do
      expect(path.type).to be_a(StrongJSON::Type::Base)
    end

    it "prints" do
      expect(path.to_s).to eq("$")
    end
  end

  describe "appended path" do
    let(:path) {
      ErrorPath.root(object(foo: array(number)))
        .dig(key: :foo, type: array(number))
        .dig(key: 0, type: number)
    }

    it "does have parent" do
      expect(path.parent).to be_a(Array)
      expect(path.parent[0]).to eq(0)
      expect(path.parent[1]).to be_a(ErrorPath)
    end

    it "has type" do
      expect(path.type).to be_a(StrongJSON::Type::Base)
    end

    it "prints" do
      expect(path.to_s).to eq("$.foo[0]")
    end
  end

  describe "expanded path" do
    let(:path) {
      ErrorPath.root(array(enum(number, string)))
        .dig(key: 0, type: enum(number, string))
        .expand(type: string)
    }

    it "does have parent" do
      expect(path.parent).to be_a(Array)
      expect(path.parent[0]).to be_nil
      expect(path.parent[1]).to be_a(ErrorPath)
    end

    it "has type" do
      expect(path.type).to be_a(StrongJSON::Type::Base)
    end

    it "prints" do
      expect(path.to_s).to eq("$[0]")
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
strong_json-2.1.2 spec/error_spec.rb
strong_json-2.1.1 spec/error_spec.rb
strong_json-2.1.0 spec/error_spec.rb
strong_json-2.0.0 spec/error_spec.rb
strong_json-1.1.0 spec/error_spec.rb
strong_json-1.0.1 spec/error_spec.rb
strong_json-1.0.0 spec/error_spec.rb