Kevin Clark | dd33025 | 2008-06-18 01:11:18 +0000 | [diff] [blame] | 1 | require File.dirname(__FILE__) + '/spec_helper' |
| 2 | require 'thrift/transport/httpclient' |
| 3 | |
| 4 | class 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| |
| 23 | http.should_receive(:post).with("/path/to/service", "a test frame").and_return([nil, "data"]) |
| 24 | end |
| 25 | end |
| 26 | @client.flush |
| 27 | @client.read(10).should == "data" |
| 28 | end |
| 29 | end |
| 30 | end |