Sha256: 465f47018c8c7b332e777787a1c99035bb6bb8958e1e068ca70dbde16ecd97f7

Contents?: true

Size: 1.43 KB

Versions: 9

Compression:

Stored size: 1.43 KB

Contents

require 'spec_helper'
require 'command_mapper/types/type'

describe CommandMapper::Types::Type do
  describe "#validate" do
    it "must return true by default" do
      expect(subject.validate(Object.new)).to be(true)
    end
  end

  describe "#format" do
    it "must convert the given value into a String" do
      expect(subject.format(1)).to eq("1")
    end
  end
end

describe "CommandMapper::Types::Type()" do
  context "when given a CommandMapper::Types::Type" do
    let(:value) { CommandMapper::Types::Type.new }

    subject { CommandMapper::Types::Type(value) }

    it "must return the CommandMapper::Types::Type object" do
      expect(subject).to be(value)
    end
  end

  context "when given a Hash" do
    let(:value) { {allow_empty: true} }

    subject { CommandMapper::Types::Type(value) }

    it "must initialize a new CommandMapper::Types::Str" do
      expect(subject).to be_kind_of(CommandMapper::Types::Str)
      expect(subject.allow_empty?).to be(true)
    end
  end

  context "when given nil" do
    let(:value) { nil }

    subject { CommandMapper::Types::Type(value) }

    it "must return nil" do
      expect(subject).to be(nil)
    end
  end

  context "when given another kind of Object" do
    let(:value) { Object.new }

    it do
      expect {
        CommandMapper::Types::Type(value)
      }.to raise_error(ArgumentError,"value must be a CommandMapper::Types::Type, Hash, or nil: #{value.inspect}")
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
command_mapper-0.3.2 spec/types/type_spec.rb
command_mapper-0.3.1 spec/types/type_spec.rb
command_mapper-0.3.0 spec/types/type_spec.rb
command_mapper-0.2.1 spec/types/type_spec.rb
command_mapper-0.2.0 spec/types/type_spec.rb
command_mapper-0.1.2 spec/types/type_spec.rb
command_mapper-0.1.1 spec/types/type_spec.rb
command_mapper-0.1.0 spec/types/type_spec.rb
command_mapper-0.1.0.pre1 spec/types/type_spec.rb