Sha256: 608750faab80803ff7c830b1589a535ecbff380a57965a2ee8beacc1a688d552

Contents?: true

Size: 1.44 KB

Versions: 9

Compression:

Stored size: 1.44 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

  describe "=~" do
    it "returns true for array" do
      type = StrongJSON::Type::Array.new(StrongJSON::Type::Base.new(:number))
      expect(type =~ []).to be_truthy
    end

    it "returns false for number" do
      type = StrongJSON::Type::Array.new(StrongJSON::Type::Base.new(:number))
      expect(type =~ 3.0).to be_falsey
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
strong_json-0.9.0 spec/array_spec.rb
strong_json-0.8.0 spec/array_spec.rb
strong_json-0.7.1 spec/array_spec.rb
strong_json-0.7.0 spec/array_spec.rb
strong_json-0.6.0 spec/array_spec.rb
strong_json-0.5.0 spec/array_spec.rb
strong_json-0.4.0 spec/array_spec.rb
strong_json-0.3.0 spec/array_spec.rb
strong_json-0.2.0 spec/array_spec.rb