Sha256: cf97449a80aa5d08acd581ca53f0eed0536e6fa9bfa5ce635633c41cbbebfd7a

Contents?: true

Size: 463 Bytes

Versions: 16

Compression:

Stored size: 463 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::Error)
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
strong_json-0.9.0 spec/optional_spec.rb
strong_json-0.8.0 spec/optional_spec.rb
strong_json-0.7.1 spec/optional_spec.rb
strong_json-0.7.0 spec/optional_spec.rb
strong_json-0.6.0 spec/optional_spec.rb
strong_json-0.5.0 spec/optional_spec.rb
strong_json-0.4.0 spec/optional_spec.rb
strong_json-0.3.0 spec/optional_spec.rb
strong_json-0.2.0 spec/optional_spec.rb
strong_json-0.1.2 spec/optional_spec.rb
strong_json-0.1.1 spec/optional_spec.rb
strong_json-0.1.0 spec/optional_spec.rb
strong_json-0.0.4 spec/optional_spec.rb
strong_json-0.0.3 spec/optional_spec.rb
strong_json-0.0.2 spec/optional_spec.rb
strong_json-0.0.1 spec/optional_spec.rb