Sha256: fd6ff31543db3fe26e3c9ab2433038f037a52e4b5cdae20de37fe399ff500908

Contents?: true

Size: 1.32 KB

Versions: 7

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Sinclair::EqualsChecker::Reader do
  subject(:reader) { described_class.new(attribute) }

  let(:attribute) { :information }
  let(:model)     { SampleModel.new(name: name, age: age) }
  let(:name)      { 'The Name' }
  let(:age)       { 25 }

  describe '.attributes_match?' do
    let(:other)      { SampleModel.new(name: other_name) }
    let(:attribute)  { :name }

    context 'when the value match' do
      let(:other_name) { name }

      it do
        expect(described_class)
          .to be_attributes_match(attribute, model, other)
      end
    end

    context 'when the value does not match' do
      let(:other_name) { 'Other Name' }

      it do
        expect(described_class)
          .not_to be_attributes_match(attribute, model, other)
      end
    end
  end

  describe '#read_from' do
    context 'when reading from a method' do
      it 'returns the value from the method' do
        expect(reader.read_from(model)).to eq('The Name: 25 yo')
      end
    end

    context 'when reading from a variable' do
      let(:attribute) { :@inner_variable }

      before do
        model.instance_variable_set(:@inner_variable, 301)
      end

      it 'returns the value from the variable' do
        expect(reader.read_from(model)).to eq(301)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sinclair-2.1.1 spec/lib/sinclair/equals_checker/reader_spec.rb
sinclair-2.1.0 spec/lib/sinclair/equals_checker/reader_spec.rb
sinclair-2.0.1 spec/lib/sinclair/equals_checker/reader_spec.rb
sinclair-2.0.0 spec/lib/sinclair/equals_checker/reader_spec.rb
sinclair-1.16.3 spec/lib/sinclair/equals_checker/reader_spec.rb
sinclair-1.16.2 spec/lib/sinclair/equals_checker/reader_spec.rb
sinclair-1.16.1 spec/lib/sinclair/equals_checker/reader_spec.rb