spec/http/http_post_spec.rb in yajl-ruby-0.6.5 vs spec/http/http_post_spec.rb in yajl-ruby-0.6.6
- old
+ new
@@ -28,10 +28,12 @@
@template_hash_symbolized = Yajl::Parser.parse(raw, :symbolize_keys => true)
@deflate = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.deflate.dump'), 'r')
@gzip = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.gzip.dump'), 'r')
@body = "blah=foo&bar=baz"
+ @hashed_body = {:blah => 'foo', 'bar' => 'baz'}
+ @chunked_body = {"item"=>{"price"=>1.99, "updated_by_id"=>nil, "cached_tag_list"=>"", "name"=>"generated", "created_at"=>"2009-03-24T05:25:09Z", "cost"=>0.597, "delta"=>false, "created_by_id"=>nil, "updated_at"=>"2009-03-24T05:25:09Z", "import_tag"=>nil, "account_id"=>16, "id"=>1, "taxable"=>true, "unit"=>nil, "sku"=>"06317-0306", "company_id"=>0, "description"=>nil, "active"=>true}}
end
after(:each) do
@file_path = nil
end
@@ -45,15 +47,26 @@
@uri.should_receive(:port)
@uri.should_receive(:path)
@uri.should_receive(:query)
@uri.should_receive(:userinfo)
end
-
+
it "should parse a raw response" do
prepare_mock_request_dump :raw
@template_hash.should == Yajl::HttpStream.post(@uri, @body)
end
+
+ it "should parse a raw response using instance method" do
+ prepare_mock_request_dump :raw
+ stream = Yajl::HttpStream.new
+ @template_hash.should == stream.post(@uri, @body)
+ end
+
+ it "should parse a raw response with hashed body" do
+ prepare_mock_request_dump :raw
+ @template_hash.should == Yajl::HttpStream.post(@uri, @hashed_body)
+ end
it "should parse a raw response and symbolize keys" do
prepare_mock_request_dump :raw
@template_hash_symbolized.should == Yajl::HttpStream.post(@uri, @body, :symbolize_keys => true)
end
@@ -86,7 +99,24 @@
end
it "should parse a gzip compressed response and symbolize keys" do
prepare_mock_request_dump :gzip
@template_hash_symbolized.should == Yajl::HttpStream.post(@uri, @body, :symbolize_keys => true)
+ end
+
+ it "should parse a chunked raw response" do
+ prepare_mock_request_dump :chunked
+ Yajl::HttpStream.post(@uri, @body) do |obj|
+ obj.should eql(@chunked_body)
+ end
+ end
+
+ it "should throw Exception if chunked response and no block given" do
+ prepare_mock_request_dump :chunked
+ lambda {Yajl::HttpStream.post(@uri, @body)}.should raise_error(Exception)
+ end
+
+ it "should throw InvalidContentType if unable to handle the MIME type" do
+ prepare_mock_request_dump :html
+ lambda {Yajl::HttpStream.post(@uri, @body)}.should raise_error(Yajl::HttpStream::InvalidContentType)
end
end
\ No newline at end of file