Sha256: 407be7dcf80b50565b2e5ab53b1b6f7dda618a9dadd3bc046519792384eecebc

Contents?: true

Size: 574 Bytes

Versions: 7

Compression:

Stored size: 574 Bytes

Contents

require "strong_json"

describe StrongJSON::Type::Optional, "#coerce" do
  context "optional(:number)" do
    let (:type) { StrongJSON::Type::Optional.new(StrongJSON::Type::Base.new(:number)) }

    it "accepts nil" do
      expect(type.coerce(nil)).to eq(nil)
    end

    it "accepts number" do
      expect(type.coerce(3)).to eq(3)
    end

    it "rejects string" do
      expect { type.coerce("a") }.to raise_error(StrongJSON::Type::TypeError) {|e|
        expect(e.path.to_s).to eq("$")
        expect(e.type).to be_a(StrongJSON::Type::Base)
      }
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

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