Sha256: 6a87b744cad554c416f9e407ffe0b1695085fbe055b6c57f886e8779a15fa295

Contents?: true

Size: 1.48 KB

Versions: 3

Compression:

Stored size: 1.48 KB

Contents

require "spec_helper"
require "shamu/attributes"

describe Shamu::Attributes::Equality do
  let( :klass ) do
    Class.new do
      include Shamu::Attributes
      include Shamu::Attributes::Equality

      attribute :name
      attribute :random, ignore_equality: true
    end
  end

  let( :value )     { klass.new( name: "same" ) }
  let( :same )      { klass.new( name: "same" ) }
  let( :different ) { klass.new( name: "different" ) }


  it "is eql? for the same attributes" do
    expect( value ).to eq same
  end

  it "isn't eql? for different attributes" do
    expect( value ).not_to eq different
  end

  it "isn't eql? for different types with the same attributes" do
    other_klass = Class.new do
      include Shamu::Attributes
      include Shamu::Attributes::Equality

      attribute :name
    end

    other = other_klass.new( name: value.name )

    expect( value ).not_to eq other
  end

  it "is eql? for derived types with same attributes" do
    derived_klass = Class.new( klass )
    derived = derived_klass.new( name: value.name )

    expect( value ).to eq derived
    expect( derived ).to eq value
  end

  it "has the same hash for the same attributes" do
    expect( value.hash ).to eq same.hash
  end

  it "has a different hash for different attributes" do
    expect( value.hash ).not_to eq different.hash
  end

  it "ignores excluded attributes" do
    v1 = klass.new( name: "same", random: 123 )
    v2 = klass.new( name: "same", random: 456 )

    expect( v1 ).to eq v2
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
shamu-0.0.24 spec/lib/shamu/attributes/equality_spec.rb
shamu-0.0.21 spec/lib/shamu/attributes/equality_spec.rb
shamu-0.0.20 spec/lib/shamu/attributes/equality_spec.rb