File: http_stream_options_spec.rb

package info (click to toggle)
ruby-yajl 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 4,036 kB
  • sloc: ansic: 3,068; ruby: 2,619; makefile: 4; sh: 3
file content (27 lines) | stat: -rw-r--r-- 834 bytes parent folder | download | duplicates (3)
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
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
require 'yajl/http_stream'
require 'socket'

describe "Passing options to HttpStream instance methods" do
  before(:all) do
    @stream = Yajl::HttpStream.new
  end

  it "should not create a new socket it one is provided" do
    expect(TCPSocket).not_to receive(:new)
    options = {:socket => :my_provided_socket}

    @stream.send(:initialize_socket, URI.parse("http://google.com"), options)

    expect(options[:socket]).to eq(:my_provided_socket)
  end

  it "should create a new socket if one is not provided" do
    expect(TCPSocket).to receive(:new).with("google.com", 80).and_return( :tcp_socket )
    options = {}

    @stream.send(:initialize_socket, URI.parse("http://google.com"), options)

    expect(options[:socket]).to eq(:tcp_socket)
  end
end