Sha256: e72f388693f4dadacb7db58ec90aa3e18f1a9c79ea2335864eeb35ceb9cfe862

Contents?: true

Size: 1.1 KB

Versions: 7

Compression:

Stored size: 1.1 KB

Contents

require "strong_json"

describe StrongJSON::Type::Array, "#coerce" do
  it "returns empty" do
    type = StrongJSON::Type::Array.new(StrongJSON::Type::Base.new(:any))

    expect(type.coerce([])).to eq([])
  end

  it "test array of number" do
    type = StrongJSON::Type::Array.new(StrongJSON::Type::Base.new(:number))
    expect(type.coerce([1])).to eq([1])
  end

  it "test array of array of number" do
    a = StrongJSON::Type::Array.new(StrongJSON::Type::Base.new(:number))
    type = StrongJSON::Type::Array.new(a)
    expect(type.coerce([[1]])).to eq([[1]])
  end

  it "reject non array" do
    type = StrongJSON::Type::Array.new(StrongJSON::Type::Base.new(:number))

    expect { type.coerce({}) }.to raise_error(StrongJSON::Type::Error)
  end

  it "reject membership" do
    type = StrongJSON::Type::Array.new(StrongJSON::Type::Base.new(:number))

    expect { type.coerce(["a"]) }.to raise_error(StrongJSON::Type::Error)
  end

  it "rejects nil" do
    type = StrongJSON::Type::Array.new(StrongJSON::Type::Base.new(:number))

    expect { type.coerce(nil) }.to raise_error(StrongJSON::Type::Error)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
strong_json-0.1.2 spec/array_spec.rb
strong_json-0.1.1 spec/array_spec.rb
strong_json-0.1.0 spec/array_spec.rb
strong_json-0.0.4 spec/array_spec.rb
strong_json-0.0.3 spec/array_spec.rb
strong_json-0.0.2 spec/array_spec.rb
strong_json-0.0.1 spec/array_spec.rb