Sha256: ac6d9f0a4c49cd3c4f35e37f65fc71e4fcebecd6acee63f182681dd5a767a7f5

Contents?: true

Size: 1.57 KB

Versions: 11

Compression:

Stored size: 1.57 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Axiom::Types::Infinity, '#coerce' do
  subject { object.coerce(other) }

  let(:object) { described_class.instance }

  [
    1,                # Fixnum
    2**63,            # Bignum
    1.0,              # Float
    Rational(1, 1),   # Rational
    BigDecimal('1'),  # BigDecimal
  ].each do |number|
    context "when other is a #{number.class}" do
      let(:other) { number }

      it 'coerces into an array containing inverse and self' do
        should eql([Axiom::Types::NegativeInfinity.instance, object])
      end

      it 'coerces when comparing' do
        expect(other).to     be < object
        expect(other).to_not be == object
      end
    end
  end

  context 'when other is a Float::INFINITY' do
    let(:other) { Float::INFINITY }

    it 'coerces into an array containing inverse and self' do
      should eql([Axiom::Types::Infinity.instance, object])
    end

    it 'coerces when comparing' do
      expect(other).to_not be < object
      expect(other).to     be == object
    end
  end

  context 'when other is a -Float::INFINITY' do
    let(:other) { -Float::INFINITY }

    it 'coerces into an array containing inverse and self' do
      should eql([Axiom::Types::NegativeInfinity.instance, object])
    end

    it 'coerces when comparing' do
      expect(other).to     be < object
      expect(other).to_not be == object
    end
  end

  context 'when other is not a number' do
    let(:other) { 'string' }

    specify do
      expect { subject }.to raise_error(TypeError, 'String cannot be coerced')
    end
  end
end

Version data entries

11 entries across 9 versions & 4 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/infinity/coerce_spec.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/infinity/coerce_spec.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/infinity/coerce_spec.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/infinity/coerce_spec.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/infinity/coerce_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/infinity/coerce_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/infinity/coerce_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/infinity/coerce_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/infinity/coerce_spec.rb
axiom-types-0.1.1 spec/unit/axiom/types/infinity/coerce_spec.rb
axiom-types-0.1.0 spec/unit/axiom/types/infinity/coerce_spec.rb