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