Sha256: 58bd7da5c7671f4474b6690f3a932932749e9cd0680e5b438d2eb1676d0507c9

Contents?: true

Size: 1.19 KB

Versions: 11

Compression:

Stored size: 1.19 KB

Contents

# encoding: utf-8

require 'spec_helper'
require 'ice_nine'

describe IceNine::Freezer::Range, '.deep_freeze' do
  subject { object.deep_freeze(value) }

  let(:object) { described_class }

  let(:element_class) do
    Class.new do
      attr_reader :number, :range
      protected :number, :range

      def initialize(number)
        @number = number
        @range  = nil
      end

      def succ
        self.class.new(number.succ, range)
      end

      def <=>(other)
        range <=> other.range && number <=> other.number
      end

      # allow for circular references
      def range=(range)
        @range = range
      end
    end
  end

  context 'with a Range' do
    let(:value) { element_class.new(1)..element_class.new(100) }

    context 'without a circular reference' do
      it_behaves_like 'IceNine::Freezer::Range.deep_freeze'
    end

    context 'with a circular reference in the first element' do
      before { value.begin.range = value }

      it_behaves_like 'IceNine::Freezer::Range.deep_freeze'
    end

    context 'with a circular reference in the last element' do
      before { value.end.range = value }

      it_behaves_like 'IceNine::Freezer::Range.deep_freeze'
    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/ice_nine-0.11.2/spec/unit/ice_nine/freezer/range/class_methods/deep_freeze_spec.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/ice_nine-0.11.2/spec/unit/ice_nine/freezer/range/class_methods/deep_freeze_spec.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/ice_nine-0.11.2/spec/unit/ice_nine/freezer/range/class_methods/deep_freeze_spec.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/ice_nine-0.11.2/spec/unit/ice_nine/freezer/range/class_methods/deep_freeze_spec.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/ice_nine-0.11.2/spec/unit/ice_nine/freezer/range/class_methods/deep_freeze_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/ice_nine-0.11.2/spec/unit/ice_nine/freezer/range/class_methods/deep_freeze_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/ice_nine-0.11.2/spec/unit/ice_nine/freezer/range/class_methods/deep_freeze_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/ice_nine-0.11.2/spec/unit/ice_nine/freezer/range/class_methods/deep_freeze_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/ice_nine-0.11.2/spec/unit/ice_nine/freezer/range/class_methods/deep_freeze_spec.rb
ice_nine-0.11.2 spec/unit/ice_nine/freezer/range/class_methods/deep_freeze_spec.rb
ice_nine-0.11.1 spec/unit/ice_nine/freezer/range/class_methods/deep_freeze_spec.rb