Sha256: fba720df9ae6b5debca634a84485cc30a4b6af08ccb4e59d9698489fbfb9df1f

Contents?: true

Size: 1.13 KB

Versions: 11

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Arstotzka::HashReader do
  subject(:reader) { described_class.new(options) }

  describe '#hash' do
    let(:klass)    { Arstotzka::Fetcher::Dummy }
    let(:json)     { { key: SecureRandom.hex } }
    let(:instance) { klass.new(json) }
    let(:options)  { { instance: instance } }

    context 'when no extra options are given' do
      it 'reads hash from instance json method' do
        expect(reader.hash).to eq(json)
      end
    end

    context 'when fetching from instance variable' do
      let(:klass)   { Arstotzka::Fetcher::NoAccessor }
      let(:options) { { instance: instance, json: :@hash } }

      it 'reads hash from instance variable' do
        expect(reader.hash).to eq(json)
      end
    end

    context 'when fetching from class variable' do
      let(:klass)    { Arstotzka::Fetcher::ClassVariable }
      let(:options)  { { instance: instance, json: :@@json } }
      let(:instance) { klass.new }

      before do
        klass.json = json
      end

      it 'reads hash from class variable' do
        expect(reader.hash).to eq(json)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
arstotzka-1.6.2 spec/lib/arstotzka/hash_reader_spec.rb
arstotzka-1.6.1 spec/lib/arstotzka/hash_reader_spec.rb
arstotzka-1.6.0 spec/lib/arstotzka/hash_reader_spec.rb
arstotzka-1.5.0 spec/lib/arstotzka/hash_reader_spec.rb
arstotzka-1.4.4 spec/lib/arstotzka/hash_reader_spec.rb
arstotzka-1.4.3 spec/lib/arstotzka/hash_reader_spec.rb
arstotzka-1.4.2 spec/lib/arstotzka/hash_reader_spec.rb
arstotzka-1.4.1 spec/lib/arstotzka/hash_reader_spec.rb
arstotzka-1.4.0 spec/lib/arstotzka/hash_reader_spec.rb
arstotzka-1.3.2 spec/lib/arstotzka/hash_reader_spec.rb
arstotzka-1.3.1 spec/lib/arstotzka/hash_reader_spec.rb