Permalink
Browse files

rename parsing specs to reflect their purpose, add Yajl::HttpStream.g…

…et spec
  • Loading branch information...
1 parent e7a70ff commit c4d83e7c8f6ddd1cab52d323d1cd0543ce2c76de @brianmario brianmario committed May 19, 2009
File renamed without changes.
File renamed without changes.
View
@@ -0,0 +1,98 @@
+# encoding: UTF-8
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper.rb')
+require 'yajl/bzip2'
+require 'yajl/gzip'
+require 'yajl/deflate'
+require 'yajl/http_stream'
+
+def parse_off_headers(io)
+ io.each_line do |line|
+ if line == "\r\n" # end of the headers
+ break
+ end
+ end
+end
+
+describe "Yajl HTTP GET request" do
+ before(:all) do
+ @raw = File.new(File.expand_path(File.dirname(__FILE__) + '/http/http.raw.dump'), 'r')
+ @bzip2 = File.new(File.expand_path(File.dirname(__FILE__) + '/http/http.bzip2.dump'), 'r')
+ @deflate = File.new(File.expand_path(File.dirname(__FILE__) + '/http/http.deflate.dump'), 'r')
+ @gzip = File.new(File.expand_path(File.dirname(__FILE__) + '/http/http.gzip.dump'), 'r')
+
+ parse_off_headers(@raw)
+ @raw_template_hash = Yajl::Stream.parse(@raw)
+ @raw.rewind
+ end
+
+ after(:all) do
+ @raw.close unless @raw.closed?
+ @bzip2.close unless @bzip2.closed?
+ @deflate.close unless @deflate.closed?
+ @gzip.close unless @gzip.closed?
+ end
+
+ after(:each) do
+ GC.start
+ end
+
+ it "should parse a raw response" do
+ file = File.expand_path(File.dirname(__FILE__) + '/http/http.raw.dump')
+ uri = 'file://'+file
+
+ TCPSocket.should_receive(:new).and_return(@raw)
+ @raw.should_receive(:write)
+ uri.should_receive(:host).at_least(2).times
+ uri.should_receive(:port)
+ uri.should_receive(:path)
+ uri.should_receive(:query)
+ uri.should_receive(:userinfo)
+
+ @raw_template_hash.should == Yajl::HttpStream.get(uri)
+ end
+
+ it "should parse a bzip2 compressed response" do
+ file = File.expand_path(File.dirname(__FILE__) + '/http/http.bzip2.dump')
+ uri = 'file://'+file
+
+ TCPSocket.should_receive(:new).and_return(@bzip2)
+ @bzip2.should_receive(:write)
+ uri.should_receive(:host).at_least(2).times
+ uri.should_receive(:port)
+ uri.should_receive(:path)
+ uri.should_receive(:query)
+ uri.should_receive(:userinfo)
+
+ @raw_template_hash.should == Yajl::HttpStream.get(uri)
+ end
+
+ it "should parse a deflate compressed response" do
+ file = File.expand_path(File.dirname(__FILE__) + '/http/http.deflate.dump')
+ uri = 'file://'+file
+
+ TCPSocket.should_receive(:new).and_return(@deflate)
+ @deflate.should_receive(:write)
+ uri.should_receive(:host).at_least(2).times
+ uri.should_receive(:port)
+ uri.should_receive(:path)
+ uri.should_receive(:query)
+ uri.should_receive(:userinfo)
+
+ @raw_template_hash.should == Yajl::HttpStream.get(uri)
+ end
+
+ it "should parse a gzip compressed response" do
+ file = File.expand_path(File.dirname(__FILE__) + '/http/http.gzip.dump')
+ uri = 'file://'+file
+
+ TCPSocket.should_receive(:new).and_return(@gzip)
+ @gzip.should_receive(:write)
+ uri.should_receive(:host).at_least(2).times
+ uri.should_receive(:port)
+ uri.should_receive(:path)
+ uri.should_receive(:query)
+ uri.should_receive(:userinfo)
+
+ @raw_template_hash.should == Yajl::HttpStream.get(uri)
+ end
+end
File renamed without changes.
View
@@ -64,7 +64,6 @@ Gem::Specification.new do |s|
"lib/yajl/gzip/stream_reader.rb",
"lib/yajl/gzip/stream_writer.rb",
"lib/yajl/http_stream.rb",
- "spec/active_support_spec.rb",
"spec/fixtures/fail.15.json",
"spec/fixtures/fail.16.json",
"spec/fixtures/fail.17.json",
@@ -122,12 +121,10 @@ Gem::Specification.new do |s|
"spec/fixtures/pass1.json",
"spec/fixtures/pass2.json",
"spec/fixtures/pass3.json",
- "spec/fixtures_spec.rb",
"spec/http/http.bzip2.dump",
"spec/http/http.deflate.dump",
"spec/http/http.gzip.dump",
"spec/http/http.raw.dump",
- "spec/one_off_spec.rb",
"spec/spec_helper.rb",
"yajl-ruby.gemspec"
]
@@ -137,9 +134,10 @@ Gem::Specification.new do |s|
s.rubygems_version = %q{1.3.3}
s.summary = %q{Ruby C bindings to the excellent Yajl JSON stream-based parser library.}
s.test_files = [
- "spec/active_support_spec.rb",
- "spec/fixtures_spec.rb",
- "spec/one_off_spec.rb",
+ "spec/parsing_active_support_spec.rb",
+ "spec/parsing_fixtures_spec.rb",
+ "spec/parsing_http_spec.rb",
+ "spec/parsing_one_off_spec.rb",
"spec/spec_helper.rb"
]

0 comments on commit c4d83e7

Please sign in to comment.