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.76.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.76.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.75.2 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.75.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.75.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.74.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.74.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.73.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.72.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.70.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.70.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.69.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.69.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.68.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.67.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.67.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.66.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.65.1 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.65.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb
eac_tools-0.64.0 sub/eac_ruby_utils/spec/lib/eac_ruby_utils/compare_by_spec.rb