File: subclass_spec.rb

package info (click to toggle)
ruby-equatable 0.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 160 kB
  • sloc: ruby: 394; makefile: 4
file content (63 lines) | stat: -rw-r--r-- 1,369 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# frozen_string_literal: true

require "spec/spec_helper"

RSpec.describe Equatable, 'subclass' do
  let(:name) { 'Value' }

  context 'when subclass' do
    let(:value) { 11 }
    let(:klass) {
      ::Class.new do
        include Equatable

        attr_reader :value

        def initialize(value)
          @value = value
        end
      end
    }
    let(:subclass) { ::Class.new(klass) }

    subject { subclass.new(value) }

    before { allow(klass).to receive(:name).and_return(name) }

    it { expect(subclass.superclass).to eq(klass) }

    it { is_expected.to respond_to(:value) }

    describe '#inspect' do
      it { expect(subject.inspect).to eql('#<Value value=11>') }
    end

    describe '#eql?' do
      context 'when objects are similar' do
        let(:other) { subject.dup }

        it { expect(subject.eql?(other)).to eql(true) }
      end

      context 'when objects are different' do
        let(:other) { double('other') }

        it { expect(subject.eql?(other)).to eql(false) }
      end
    end

    describe '#==' do
      context 'when objects are similar' do
        let(:other) { subject.dup }

        it { expect(subject == other).to eql(true) }
      end

      context 'when objects are different' do
        let(:other) { double('other') }

        it { expect(subject == other).to eql(false) }
      end
    end
  end
end