File: connection_spec.rb

package info (click to toggle)
ruby-riddle 2.3.1-2~deb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 10,752 kB
  • sloc: sql: 25,022; php: 5,992; ruby: 4,757; sh: 59; makefile: 5
file content (66 lines) | stat: -rw-r--r-- 1,851 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# frozen_string_literal: true

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 not override OutOfBoundsError instances" do
      client.connection = lambda { |client|
        raise Riddle::OutOfBoundsError
      }
      lambda { client.query('smith') }.
        should raise_error(Riddle::OutOfBoundsError)
    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