Sha256: fd736e0a64a382336350c0c34cb8baa3b54a9e3db41ab925d0cdd46d1a79fba6

Contents?: true

Size: 1.86 KB

Versions: 23

Compression:

Stored size: 1.86 KB

Contents

# frozen_string_literal: true

require 'test_helper'

module Vedeu

  module Coercers

    describe Position do

      let(:described) { Vedeu::Coercers::Position }
      let(:instance)  { described.new(_value) }
      let(:_value)    {}
      let(:klass)     { Vedeu::Geometries::Position }

      describe '#initialize' do
        it { instance.must_be_instance_of(described) }
        it { instance.instance_variable_get('@value').must_equal(_value) }
      end

      describe '.coerce' do
        it { described.must_respond_to(:coerce) }
      end

      describe '#coerce' do
        subject { instance.coerce }

        context 'when the value is already the target class' do
          let(:_value) { klass.new }

          it { subject.must_be_instance_of(klass) }
          it { subject.must_equal(_value) }
        end

        context 'when the value is an Array' do
          let(:_value) { [2, 8] }

          it { subject.must_be_instance_of(klass) }
          it { subject.y.must_equal(2) }
          it { subject.x.must_equal(8) }
        end

        context 'when the value is an Fixnum' do
          let(:_value) { 2 }

          it { subject.must_be_instance_of(klass) }
          it { subject.y.must_equal(2) }
          it { subject.x.must_equal(1) }
        end

        context 'when the value is a Hash' do
          let(:_value) { { y: 3, x: 9 } }

          it { subject.must_be_instance_of(klass) }
          it { subject.y.must_equal(3) }
          it { subject.x.must_equal(9) }
        end

        context 'when the value is a NilClass' do
          let(:_value) {}

          it { subject.must_be_instance_of(NilClass) }
        end

        context 'when the value is something unhandled' do
          let(:_value) { :invalid }

          it { proc { subject }.must_raise(Vedeu::Error::Fatal) }
        end
      end

    end # Position

  end # Coercers

end # Vedeu

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
vedeu-0.8.32 test/lib/vedeu/coercers/position_test.rb
vedeu-0.8.31 test/lib/vedeu/coercers/position_test.rb
vedeu-0.8.30 test/lib/vedeu/coercers/position_test.rb
vedeu-0.8.29 test/lib/vedeu/coercers/position_test.rb
vedeu-0.8.28 test/lib/vedeu/coercers/position_test.rb
vedeu-0.8.27 test/lib/vedeu/coercers/position_test.rb
vedeu-0.8.26 test/lib/vedeu/coercers/position_test.rb
vedeu-0.8.25 test/lib/vedeu/coercers/position_test.rb
vedeu-0.8.24 test/lib/vedeu/coercers/position_test.rb
vedeu-0.8.23 test/lib/vedeu/coercers/position_test.rb
vedeu-0.8.22 test/lib/vedeu/coercers/position_test.rb
vedeu-0.8.21 test/lib/vedeu/coercers/position_test.rb
vedeu-0.8.20 test/lib/vedeu/coercers/position_test.rb
vedeu-0.8.19 test/lib/vedeu/coercers/position_test.rb
vedeu-0.8.18 test/lib/vedeu/coercers/position_test.rb
vedeu-0.8.17 test/lib/vedeu/coercers/position_test.rb
vedeu-0.8.16 test/lib/vedeu/coercers/position_test.rb
vedeu-0.8.15 test/lib/vedeu/coercers/position_test.rb
vedeu-0.8.14 test/lib/vedeu/coercers/position_test.rb
vedeu-0.8.13 test/lib/vedeu/coercers/position_test.rb