Sha256: 3ba59539681bf38f17514ee376550860647bb4235ddcaea4e763104b184668d6

Contents?: true

Size: 1.92 KB

Versions: 2

Compression:

Stored size: 1.92 KB

Contents

require 'spec_helper'
module Domain
  describe Equalizer do

    let(:domain){
      Class.new{
        def initialize(x, y)
          @x, @y = x, y
        end
        attr_reader :x, :y
        include Equalizer.new{ [x, y] }
      }
    }

    let(:object){ domain.new(1, 2) }

    describe "==" do
      subject{ object == other }

      context 'with itself' do
        let(:other){ object }
        it{ should be_true }
      end

      context 'with dupped' do
        let(:other){ object.dup }
        it{ should be_true }
      end

      context 'with equivalent' do
        let(:other){ domain.new(1, 2) }
        it{ should be_true }
      end

      context 'with equivalent of a subclass' do
        let(:other){ Class.new(domain).new(1, 2) }
        it{ should be_true }
      end

      context 'with non equivalent' do
        let(:other){ domain.new(1, 3) }
        it{ should be_false }
      end

      context 'with other class' do
        let(:other){ self }
        it{ should be_false }
      end
    end

    describe "eql?" do
      subject{ object.eql?(other) }

      context 'with itself' do
        let(:other){ object }
        it{ should be_true }
      end

      context 'with dupped' do
        let(:other){ object.dup }
        it{ should be_true }
      end

      context 'with equivalent' do
        let(:other){ domain.new(1, 2) }
        it{ should be_true }
      end

      context 'with equivalent of a subclass' do
        let(:other){ Class.new(domain).new(1, 2) }
        it{ should be_false }
      end

      context 'with non equivalent' do
        let(:other){ domain.new(1, 3) }
        it{ should be_false }
      end

      context 'with other class' do
        let(:other){ self }
        it{ should be_false }
      end
    end

    describe "hash" do
      subject{ object.hash }

      it 'should be consistent with equal' do
        subject.should eq(domain.new(1,2).hash)
      end
    end

  end
end
  

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
domain-1.0.0.rc2 spec/support/test_equalizer.rb
domain-1.0.0.rc1 spec/support/test_equalizer.rb