Sha256: c44ceb03d4f085edd44a052d4a8f463a093d809e255181bcdb7a849950040eb4

Contents?: true

Size: 1.95 KB

Versions: 11

Compression:

Stored size: 1.95 KB

Contents

require 'spec_helper'
require 'dm-core/support/ordered_set'

module DataMapper::Specs

  # Used to test duck typing behavior
  class OrderedSetDuck
    attr_reader :entries

    def initialize(columns = [])
      @entries = DataMapper::OrderedSet.new
    end
  end
end

describe 'DataMapper::OrderedSet#==' do
  subject { ordered_set == other }

  let(:original_entry)  { 1                                              }
  let(:ordered_set)     { DataMapper::OrderedSet.new([ original_entry ]) }

  context 'with the same ordered_set' do
    let(:other) { ordered_set }

    it { should be(true) }

    it 'is symmetric' do
      should == (other == ordered_set)
    end
  end

  context 'with equivalent ordered_set' do
    let(:other) { ordered_set.dup }

    it { should be(true) }

    it 'is symmetric' do
      should == (other == ordered_set)
    end
  end

  # TODO This probably needs more thought
  context 'with a class that quacks like OrderedSet and is equivalent otherwise' do
    let(:other) { DataMapper::Specs::OrderedSetDuck.new([ original_entry ]) }

    it { should be(false) }

    it 'is symmetric' do
      should == (other == ordered_set)
    end
  end

  context 'with a subclass that is equivalent otherwise' do
    let(:other) { Class.new(DataMapper::OrderedSet).new([ original_entry ]) }

    it { should be(true) }

    it 'is symmetric' do
      should == (other == ordered_set)
    end
  end

  context 'with both containing no ordered_set' do
    let(:ordered_set) { DataMapper::OrderedSet.new }
    let(:other)       { DataMapper::OrderedSet.new }

    it { should be(true) }

    it 'is symmetric' do
      should == (other == ordered_set)
    end
  end

  context 'with different ordered_set' do
    let(:different_entry) { 2                                               }
    let(:other)           { DataMapper::OrderedSet.new([ different_entry ]) }

    it { should be(false) }

    it 'is symmetric' do
      should == (other == ordered_set)
    end
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
ardm-core-1.3.0 spec/unit/data_mapper/ordered_set/equal_value_spec.rb
ardm-core-1.2.1 spec/unit/data_mapper/ordered_set/equal_value_spec.rb
dm-core-1.2.1 spec/unit/data_mapper/ordered_set/equal_value_spec.rb
ghost_dm-core-1.3.0.beta spec/unit/data_mapper/ordered_set/equal_value_spec.rb
dm-core-1.2.0 spec/unit/data_mapper/ordered_set/equal_value_spec.rb
dm-core-1.2.0.rc2 spec/unit/data_mapper/ordered_set/equal_value_spec.rb
dm-core-1.2.0.rc1 spec/unit/data_mapper/ordered_set/equal_value_spec.rb
dm-core-1.1.0 spec/unit/data_mapper/ordered_set/equal_value_spec.rb
dm-core-1.1.0.rc3 spec/unit/data_mapper/ordered_set/equal_value_spec.rb
dm-core-1.1.0.rc2 spec/unit/data_mapper/ordered_set/equal_value_spec.rb
dm-core-1.1.0.rc1 spec/unit/data_mapper/ordered_set/equal_value_spec.rb