Sha256: 2bfe35ba289afa44869a71b8962893b78fb7fa0226d0c4942013077c6c5d5065

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 KB

Contents

require 'device_map'

RSpec.describe DeviceMap::Properties::DSL do
  describe '.property' do
    let(:model) do
      Class.new do
        include DeviceMap::Properties::DSL
      end
    end

    it 'defines class attribute' do
      property_value = 'test'
      model.property :property
      model_instance = model.new('property' => property_value)

      expect(model_instance.property).to eq property_value
    end

    it 'allows to change attribute name' do
      property_value = 'test'
      model.property :property, attr_name: :other_property
      model_instance = model.new('property' => property_value)
      expect(model_instance.other_property).to eq property_value
    end

    it 'can cast property value to integer' do
      model.property :property, type: :integer
      model_instance = model.new('property' => '8')
      expect(model_instance.property).to eq 8
    end

    it 'can cast property value to boolean' do
      model.property :property, type: :boolean
      model_instance = model.new('property' => 'false')
      expect(model_instance.property).to eq false
    end

    it 'raises exception during initialization if given param is unknown' do
      expect do
        model.new('unknown_param' => 'value')
      end.to raise_error(DeviceMap::Properties::UnknownProperty)
    end

    it 'is equal to other object if it has the same properties' do
      property_value = 'test'
      model.property :property
      model_instance1 = model.new('property' => property_value)
      model_instance2 = model.new('property' => property_value)

      expect(model_instance1).to eq model_instance2
    end

    it 'is not equal to other object if it has different properties' do
      model.property :property
      model_instance1 = model.new('property' => 'test1')
      model_instance2 = model.new('property' => 'test2')

      expect(model_instance1).not_to eq model_instance2
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
device_map-0.1.0 spec/properties/dsl_spec.rb