Sha256: 5f9e5e737b51388399bf6c6e7480eaedc1670b45f7b62130fd73d152cb67f565

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

require 'spec_helper'

class RiddleSpecConnectionProcError < StandardError; end

describe 'Sphinx Client', :live => true do
  let(:client) { Riddle::Client.new 'localhost', 9313 }

  after :each do
    Riddle::Client.connection = nil
  end

  describe '.connection' do
    it "should use the given block" do
      Riddle::Client.connection = lambda { |client|
        TCPSocket.new(client.server, client.port)
      }
      client.query('smith').should be_kind_of(Hash)
    end

    it "should fail with errors from the given block" do
      Riddle::Client.connection = lambda { |client|
        raise RiddleSpecConnectionProcError
      }
      lambda { client.query('smith') }.
        should raise_error(Riddle::ResponseError)
    end
  end

  describe '#connection' do
    it "use the given block" do
      client.connection = lambda { |client|
        TCPSocket.new(client.server, client.port)
      }
      client.query('smith').should be_kind_of(Hash)
    end

    it "should fail with errors from the given block" do
      client.connection = lambda { |client|
        raise RiddleSpecConnectionProcError
      }
      lambda { client.query('smith') }.
        should raise_error(Riddle::ResponseError)
    end

    it "should prioritise instance over class connection" do
      Riddle::Client.connection = lambda { |client|
        raise RiddleSpecConnectionProcError
      }
      client.connection = lambda { |client|
        TCPSocket.new(client.server, client.port)
      }

      lambda { client.query('smith') }.should_not raise_error
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
riddle-1.5.6 spec/functional/connection_spec.rb