Sha256: 739a4468295168b7219d4c5301bac4197b1a89b72b38c6187b915625cf5b9eaa

Contents?: true

Size: 955 Bytes

Versions: 129

Compression:

Stored size: 955 Bytes

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/compare_by'

RSpec.describe ::EacRubyUtils::CompareBy do
  let(:instance) { described_class.new(%i[field1 field2]) }
  let(:klass) do
    ::Class.new do
      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) }

  before { instance.apply(klass) }

  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.63.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.62.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.62.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.61.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.61.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.60.3 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.60.2 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.60.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.60.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.59.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.58.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.57.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.56.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.56.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.55.7 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.55.6 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.55.5 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.55.4 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.55.3 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.55.2 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb