Sha256: a68f0630aa995a48cf49dcd161be644d521e7535d69e4aa1f95f6bcbe3883fb5

Contents?: true

Size: 1.88 KB

Versions: 3

Compression:

Stored size: 1.88 KB

Contents

# encoding: utf-8

require 'spec_helper'
require 'veritas/adapter/data_objects'

shared_examples_for 'it uses the data_objects driver' do
  let(:connection) { mock('Connection', :close => nil) }

  before do
    DataObjects::Connection.stub!(:new).and_return(connection)
  end

  it 'opens a connection' do
    DataObjects::Connection.should_receive(:new).with(uri).and_return(connection)
    subject
  end

  it 'closes a connection' do
    connection.should_receive(:close).with(no_args)
    subject
  end

  it 'does not close a connection if the constructor throws an exception' do
    mock_exception = Class.new(Exception)
    DataObjects::Connection.should_receive(:new).and_raise(mock_exception)
    connection.should_not_receive(:close)
    expect { subject }.to raise_error(mock_exception)
  end
end

describe Adapter::DataObjects, '#read' do
  let(:uri)       { stub                     }
  let(:object)    { described_class.new(uri) }
  let(:relation)  { mock('Relation')         }
  let(:statement) { mock('Statement')        }
  let(:rows)      { [ [ 1 ], [ 2 ], [ 3 ] ]  }
  let(:yields)    { []                       }

  before do
    expectation = statement.stub(:each)
    rows.each { |row| expectation.and_yield(row) }

    described_class::Statement.stub!(:new).and_return(statement)
  end

  context 'with a block' do
    subject { object.read(relation) { |row| yields << row } }


    it_should_behave_like 'it uses the data_objects driver'
    it_should_behave_like 'a command method'

    it 'yields each row' do
      expect { subject }.to change { yields.dup }.
        from([]).
        to(rows)
    end

    it 'initializes a statement' do
      described_class::Statement.should_receive(:new).with(connection, relation).and_return(statement)
      subject
    end
  end

  context 'without a block' do
    subject { object.read(relation) }

    it { should be_instance_of(to_enum.class) }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
veritas-do-adapter-0.0.7 spec/unit/veritas/adapter/data_objects/read_spec.rb
veritas-do-adapter-0.0.6 spec/unit/veritas/adapter/data_objects/read_spec.rb
veritas-do-adapter-0.0.5 spec/unit/veritas/adapter/data_objects/read_spec.rb