Sha256: e6887b14a4a9deb3da90c80b2c78b527a4cfb9c794442833df7b648bf44d65ee

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module Gladwords
  RSpec.describe Types do
    describe Types::Date do
      describe '#read' do
        subject(:read_type) { described_class.meta[:read] }

        let(:format) { described_class.meta[:format] }
        let(:date_string) { '20181231' }

        it 'parses to a Ruby Date instance' do
          expect(read_type[date_string]).to be_a ::Date
        end

        it 'includes the correct format in the metadata' do
          expect(read_type[date_string].strftime(format)).to eq date_string
        end
      end
    end

    describe Types::Statuses do
      subject(:statuses) { described_class.type }

      it 'disallows invalid strings' do
        expect { statuses['ITYPOED'] }.to raise_error Dry::Types::ConstraintError
      end

      %w[
        UNKNOWN
        ENABLED
        PAUSED
        REMOVED
      ].each do |status|
        it "allows the \"#{status}\" status" do
          expect(statuses[status]).to eq status
        end
      end
    end

    describe Types::ID do
      subject(:id) { described_class }

      it 'maps to an Integer primitive' do
        expect(id.primitive).to be Integer
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gladwords-1.0.1 spec/unit/types_spec.rb