blob: 90549c0a4e60a07f6e903229996f3bd21188dcff [file] [log] [blame]
Kevin Clarkdd330252008-06-18 01:11:18 +00001require File.dirname(__FILE__) + '/spec_helper'
2require 'thrift/transport/httpclient'
3
4class ThriftHTTPClientSpec < Spec::ExampleGroup
5 include Thrift
6
7 describe HTTPClient do
8 before(:each) do
9 @client = HTTPClient.new("http://my.domain.com/path/to/service")
10 end
11
12 it "should always be open" do
13 @client.should be_open
14 @client.close
15 @client.should be_open
16 end
17
18 it "should post via HTTP and return the results" do
19 @client.write "a test"
20 @client.write " frame"
21 Net::HTTP.should_receive(:new).with("my.domain.com", 80).and_return do
22 mock("Net::HTTP").tee do |http|
Kevin Clark6ca38812008-10-16 19:14:47 +000023 http.should_receive(:use_ssl=).with(false)
24 http.should_receive(:post).with("/path/to/service", "a test frame", {"Content-Type"=>"application/x-thrift"}).and_return([nil, "data"])
Kevin Clarkdd330252008-06-18 01:11:18 +000025 end
26 end
27 @client.flush
28 @client.read(10).should == "data"
29 end
30 end
31end