Sha256: 43013dbad712558edef741cb5e38b6858170788c9eaa13b95e7550666762c7c6

Contents?: true

Size: 1.6 KB

Versions: 3

Compression:

Stored size: 1.6 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe TTY::Table::Row, '#==' do
  let(:attributes) { [:id] }
  let(:data) { ['1'] }
  let(:object) { described_class.new(data, attributes) }

  subject { object == other }

  context 'with the same object' do
    let(:other) { object }

    it { is_expected.to eql(true) }

    it 'is symmetric' do
      is_expected.to eql(other == object)
    end
  end

  context 'with an equivalent object' do
    let(:other) { object.dup }

    it { is_expected.to eql(true) }

    it 'is symmetric' do
      is_expected.to eql(other == object)
    end
  end

  context 'with an equivalent object of subclass' do
    let(:other) { Class.new(described_class).new(data, attributes: attributes) }

    it { is_expected.to eql(true) }

    it 'is symmetric' do
      is_expected.to eql(other == object)
    end
  end

  context 'with an object having a different attributes' do
    let(:other_attributes) { [:text] }
    let(:other) { described_class.new(data, attributes: other_attributes) }

    it { is_expected.to eql(true) }

    it 'is symmetric' do
      is_expected.to eql(other == object)
    end
  end

  context 'with an object having a different attributes' do
    let(:other_data) { [2] }
    let(:other) { described_class.new(other_data, attributes: attributes) }

    it { is_expected.to eql(false) }

    it 'is symmetric' do
      is_expected.to eql(other == object)
    end
  end

  context 'with an equivalent object responding to_ary' do
    let(:other) { data }

    it { is_expected.to eql(true) }

    it 'is symmetric' do
      is_expected.to eql(other == object)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tty-0.1.2 spec/tty/table/row/equality_spec.rb
tty-0.1.1 spec/tty/table/row/equality_spec.rb
tty-0.1.0 spec/tty/table/row/equality_spec.rb