Sha256: 3c5165d33bed5f6cbbab08d1c7201aed00127bb13ebad5c8409fc5e8ea649ef1

Contents?: true

Size: 891 Bytes

Versions: 129

Compression:

Stored size: 891 Bytes

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/patches/module/compare_by'

RSpec.describe ::Module do
  let(:klass) do
    ::Class.new do
      compare_by :field1, :field2
      attr_reader :field1, :field2
      def initialize(field1, field2)
        @field1 = field1
        @field2 = field2
      end
    end
  end
  let(:o1) { klass.new(1, 2) }
  let(:o2) { klass.new(2, 1) }
  let(:o3) { klass.new(1, 1) }

  describe '#comparable' do
    it { expect(o1).to be < o2 }
    it { expect(o1).to be > o3 }
    it { expect(o2).to be > o3 }
    it { expect([o1, o2, o3].sort).to eq([o3, o1, o2]) }
  end

  describe '#equality' do
    it { expect(o1).not_to eq(o2) }
    it { expect(o1).not_to eq(o3) }
    it { expect(o2).not_to eq(o3) }

    it { expect(o1).to eq(klass.new(1, 2)) }
    it { expect(o2).to eq(klass.new(2, 1)) }
    it { expect(o3).to eq(klass.new(1, 1)) }
  end
end

Version data entries

129 entries across 129 versions & 2 rubygems

Version Path
eac_tools-0.76.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/compare_by_spec.rb
eac_tools-0.76.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/compare_by_spec.rb
eac_tools-0.75.2 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/compare_by_spec.rb
eac_tools-0.75.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/compare_by_spec.rb
eac_tools-0.75.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/compare_by_spec.rb
eac_tools-0.74.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/compare_by_spec.rb
eac_tools-0.74.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/compare_by_spec.rb
eac_tools-0.73.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/compare_by_spec.rb
eac_tools-0.72.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/compare_by_spec.rb
eac_tools-0.70.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/compare_by_spec.rb
eac_tools-0.70.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/compare_by_spec.rb
eac_tools-0.69.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/compare_by_spec.rb
eac_tools-0.69.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/compare_by_spec.rb
eac_tools-0.68.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/compare_by_spec.rb
eac_tools-0.67.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/compare_by_spec.rb
eac_tools-0.67.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/compare_by_spec.rb
eac_tools-0.66.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/compare_by_spec.rb
eac_tools-0.65.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/compare_by_spec.rb
eac_tools-0.65.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/compare_by_spec.rb
eac_tools-0.64.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/compare_by_spec.rb