yajl-ruby 1.0.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of yajl-ruby might be problematic. Click here for more details.

Files changed (152) hide show
  1. data/.gitignore +12 -0
  2. data/.rspec +2 -0
  3. data/CHANGELOG.md +327 -0
  4. data/Gemfile +3 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +362 -0
  7. data/Rakefile +2 -0
  8. data/benchmark/encode.rb +72 -0
  9. data/benchmark/encode_json_and_marshal.rb +42 -0
  10. data/benchmark/encode_json_and_yaml.rb +53 -0
  11. data/benchmark/http.rb +32 -0
  12. data/benchmark/parse.rb +94 -0
  13. data/benchmark/parse_json_and_marshal.rb +50 -0
  14. data/benchmark/parse_json_and_yaml.rb +55 -0
  15. data/benchmark/parse_stream.rb +54 -0
  16. data/benchmark/subjects/item.json +1 -0
  17. data/benchmark/subjects/ohai.json +1216 -0
  18. data/benchmark/subjects/ohai.marshal_dump +0 -0
  19. data/benchmark/subjects/ohai.yml +975 -0
  20. data/benchmark/subjects/twitter_search.json +1 -0
  21. data/benchmark/subjects/twitter_stream.json +430 -0
  22. data/benchmark/subjects/unicode.json +1 -0
  23. data/examples/encoding/chunked_encoding.rb +27 -0
  24. data/examples/encoding/one_shot.rb +13 -0
  25. data/examples/encoding/to_an_io.rb +12 -0
  26. data/examples/http/twitter_search_api.rb +12 -0
  27. data/examples/http/twitter_stream_api.rb +26 -0
  28. data/examples/parsing/from_file.rb +14 -0
  29. data/examples/parsing/from_stdin.rb +9 -0
  30. data/examples/parsing/from_string.rb +13 -0
  31. data/ext/yajl/api/yajl_common.h +89 -0
  32. data/ext/yajl/api/yajl_gen.h +161 -0
  33. data/ext/yajl/api/yajl_parse.h +196 -0
  34. data/ext/yajl/api/yajl_version.h +23 -0
  35. data/ext/yajl/extconf.rb +7 -0
  36. data/ext/yajl/yajl.c +164 -0
  37. data/ext/yajl/yajl_alloc.c +65 -0
  38. data/ext/yajl/yajl_alloc.h +50 -0
  39. data/ext/yajl/yajl_buf.c +119 -0
  40. data/ext/yajl/yajl_buf.h +73 -0
  41. data/ext/yajl/yajl_bytestack.h +85 -0
  42. data/ext/yajl/yajl_encode.c +201 -0
  43. data/ext/yajl/yajl_encode.h +52 -0
  44. data/ext/yajl/yajl_ext.c +905 -0
  45. data/ext/yajl/yajl_ext.h +135 -0
  46. data/ext/yajl/yajl_gen.c +344 -0
  47. data/ext/yajl/yajl_lex.c +748 -0
  48. data/ext/yajl/yajl_lex.h +135 -0
  49. data/ext/yajl/yajl_parser.c +450 -0
  50. data/ext/yajl/yajl_parser.h +82 -0
  51. data/ext/yajl/yajl_version.c +7 -0
  52. data/lib/yajl.rb +75 -0
  53. data/lib/yajl/1.8/yajl.so +0 -0
  54. data/lib/yajl/1.9/yajl.so +0 -0
  55. data/lib/yajl/bzip2.rb +11 -0
  56. data/lib/yajl/bzip2/stream_reader.rb +31 -0
  57. data/lib/yajl/bzip2/stream_writer.rb +14 -0
  58. data/lib/yajl/deflate.rb +6 -0
  59. data/lib/yajl/deflate/stream_reader.rb +43 -0
  60. data/lib/yajl/deflate/stream_writer.rb +20 -0
  61. data/lib/yajl/gzip.rb +6 -0
  62. data/lib/yajl/gzip/stream_reader.rb +30 -0
  63. data/lib/yajl/gzip/stream_writer.rb +13 -0
  64. data/lib/yajl/http_stream.rb +212 -0
  65. data/lib/yajl/json_gem.rb +15 -0
  66. data/lib/yajl/json_gem/encoding.rb +51 -0
  67. data/lib/yajl/json_gem/parsing.rb +26 -0
  68. data/lib/yajl/version.rb +3 -0
  69. data/lib/yajl/yajl.rb +2 -0
  70. data/spec/encoding/encoding_spec.rb +271 -0
  71. data/spec/global/global_spec.rb +54 -0
  72. data/spec/http/fixtures/http.bzip2.dump +0 -0
  73. data/spec/http/fixtures/http.chunked.dump +11 -0
  74. data/spec/http/fixtures/http.deflate.dump +0 -0
  75. data/spec/http/fixtures/http.error.dump +12 -0
  76. data/spec/http/fixtures/http.gzip.dump +0 -0
  77. data/spec/http/fixtures/http.html.dump +1220 -0
  78. data/spec/http/fixtures/http.raw.dump +1226 -0
  79. data/spec/http/http_delete_spec.rb +98 -0
  80. data/spec/http/http_error_spec.rb +32 -0
  81. data/spec/http/http_get_spec.rb +109 -0
  82. data/spec/http/http_post_spec.rb +123 -0
  83. data/spec/http/http_put_spec.rb +105 -0
  84. data/spec/http/http_stream_options_spec.rb +27 -0
  85. data/spec/json_gem_compatibility/compatibility_spec.rb +203 -0
  86. data/spec/parsing/active_support_spec.rb +64 -0
  87. data/spec/parsing/chunked_spec.rb +96 -0
  88. data/spec/parsing/fixtures/fail.15.json +1 -0
  89. data/spec/parsing/fixtures/fail.16.json +1 -0
  90. data/spec/parsing/fixtures/fail.17.json +1 -0
  91. data/spec/parsing/fixtures/fail.26.json +1 -0
  92. data/spec/parsing/fixtures/fail11.json +1 -0
  93. data/spec/parsing/fixtures/fail12.json +1 -0
  94. data/spec/parsing/fixtures/fail13.json +1 -0
  95. data/spec/parsing/fixtures/fail14.json +1 -0
  96. data/spec/parsing/fixtures/fail19.json +1 -0
  97. data/spec/parsing/fixtures/fail20.json +1 -0
  98. data/spec/parsing/fixtures/fail21.json +1 -0
  99. data/spec/parsing/fixtures/fail22.json +1 -0
  100. data/spec/parsing/fixtures/fail23.json +1 -0
  101. data/spec/parsing/fixtures/fail24.json +1 -0
  102. data/spec/parsing/fixtures/fail25.json +1 -0
  103. data/spec/parsing/fixtures/fail27.json +2 -0
  104. data/spec/parsing/fixtures/fail28.json +2 -0
  105. data/spec/parsing/fixtures/fail3.json +1 -0
  106. data/spec/parsing/fixtures/fail4.json +1 -0
  107. data/spec/parsing/fixtures/fail5.json +1 -0
  108. data/spec/parsing/fixtures/fail6.json +1 -0
  109. data/spec/parsing/fixtures/fail9.json +1 -0
  110. data/spec/parsing/fixtures/pass.array.json +6 -0
  111. data/spec/parsing/fixtures/pass.codepoints_from_unicode_org.json +1 -0
  112. data/spec/parsing/fixtures/pass.contacts.json +1 -0
  113. data/spec/parsing/fixtures/pass.db100.xml.json +1 -0
  114. data/spec/parsing/fixtures/pass.db1000.xml.json +1 -0
  115. data/spec/parsing/fixtures/pass.dc_simple_with_comments.json +11 -0
  116. data/spec/parsing/fixtures/pass.deep_arrays.json +1 -0
  117. data/spec/parsing/fixtures/pass.difficult_json_c_test_case.json +1 -0
  118. data/spec/parsing/fixtures/pass.difficult_json_c_test_case_with_comments.json +1 -0
  119. data/spec/parsing/fixtures/pass.doubles.json +1 -0
  120. data/spec/parsing/fixtures/pass.empty_array.json +1 -0
  121. data/spec/parsing/fixtures/pass.empty_string.json +1 -0
  122. data/spec/parsing/fixtures/pass.escaped_bulgarian.json +4 -0
  123. data/spec/parsing/fixtures/pass.escaped_foobar.json +1 -0
  124. data/spec/parsing/fixtures/pass.item.json +1 -0
  125. data/spec/parsing/fixtures/pass.json-org-sample1.json +23 -0
  126. data/spec/parsing/fixtures/pass.json-org-sample2.json +11 -0
  127. data/spec/parsing/fixtures/pass.json-org-sample3.json +26 -0
  128. data/spec/parsing/fixtures/pass.json-org-sample4-nows.json +88 -0
  129. data/spec/parsing/fixtures/pass.json-org-sample4.json +89 -0
  130. data/spec/parsing/fixtures/pass.json-org-sample5.json +27 -0
  131. data/spec/parsing/fixtures/pass.map-spain.xml.json +1 -0
  132. data/spec/parsing/fixtures/pass.ns-invoice100.xml.json +1 -0
  133. data/spec/parsing/fixtures/pass.ns-soap.xml.json +1 -0
  134. data/spec/parsing/fixtures/pass.numbers-fp-4k.json +6 -0
  135. data/spec/parsing/fixtures/pass.numbers-fp-64k.json +61 -0
  136. data/spec/parsing/fixtures/pass.numbers-int-4k.json +11 -0
  137. data/spec/parsing/fixtures/pass.numbers-int-64k.json +154 -0
  138. data/spec/parsing/fixtures/pass.twitter-search.json +1 -0
  139. data/spec/parsing/fixtures/pass.twitter-search2.json +1 -0
  140. data/spec/parsing/fixtures/pass.unicode.json +3315 -0
  141. data/spec/parsing/fixtures/pass.yelp.json +1 -0
  142. data/spec/parsing/fixtures/pass1.json +56 -0
  143. data/spec/parsing/fixtures/pass2.json +1 -0
  144. data/spec/parsing/fixtures/pass3.json +6 -0
  145. data/spec/parsing/fixtures_spec.rb +40 -0
  146. data/spec/parsing/one_off_spec.rb +85 -0
  147. data/spec/rcov.opts +3 -0
  148. data/spec/spec_helper.rb +16 -0
  149. data/tasks/compile.rake +35 -0
  150. data/tasks/rspec.rake +16 -0
  151. data/yajl-ruby.gemspec +24 -0
  152. metadata +335 -0
@@ -0,0 +1,98 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
2
+ begin
3
+ require 'yajl/bzip2'
4
+ rescue
5
+ warn "Couldn't load yajl/bzip2, maybe you don't have bzip2-ruby installed? Continuing without running bzip2 specs."
6
+ end
7
+ require 'yajl/gzip'
8
+ require 'yajl/deflate'
9
+ require 'yajl/http_stream'
10
+
11
+ def parse_off_headers(io)
12
+ io.each_line do |line|
13
+ if line == "\r\n" # end of the headers
14
+ break
15
+ end
16
+ end
17
+ end
18
+
19
+ describe "Yajl HTTP DELETE request" do
20
+ before(:all) do
21
+ raw = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.raw.dump'), 'r')
22
+ parse_off_headers(raw)
23
+ @template_hash = Yajl::Parser.parse(raw)
24
+
25
+ raw.rewind
26
+ parse_off_headers(raw)
27
+ @template_hash_symbolized = Yajl::Parser.parse(raw, :symbolize_keys => true)
28
+
29
+ @deflate = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.deflate.dump'), 'r')
30
+ @gzip = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.gzip.dump'), 'r')
31
+ end
32
+
33
+ after(:each) do
34
+ @file_path = nil
35
+ end
36
+
37
+ def prepare_mock_request_dump(format=:raw)
38
+ @request = File.new(File.expand_path(File.dirname(__FILE__) + "/fixtures/http.#{format}.dump"), 'r')
39
+ @uri = 'file://'+File.expand_path(File.dirname(__FILE__) + "/fixtures/http/http.#{format}.dump")
40
+ TCPSocket.should_receive(:new).and_return(@request)
41
+ @request.should_receive(:write)
42
+ end
43
+
44
+ it "should parse a raw response" do
45
+ prepare_mock_request_dump :raw
46
+ @template_hash.should == Yajl::HttpStream.delete(@uri)
47
+ end
48
+
49
+ it "should parse a raw response using instance method" do
50
+ prepare_mock_request_dump :raw
51
+ @uri.should_receive(:host)
52
+ @uri.should_receive(:port)
53
+ stream = Yajl::HttpStream.new
54
+ @template_hash.should == stream.delete(@uri)
55
+ end
56
+
57
+ it "should parse a raw response and symbolize keys" do
58
+ prepare_mock_request_dump :raw
59
+ @template_hash_symbolized.should == Yajl::HttpStream.delete(@uri, :symbolize_keys => true)
60
+ end
61
+
62
+ if defined?(Yajl::Bzip2::StreamReader)
63
+ it "should parse a bzip2 compressed response" do
64
+ prepare_mock_request_dump :bzip2
65
+ @template_hash.should == Yajl::HttpStream.delete(@uri)
66
+ end
67
+
68
+ it "should parse a bzip2 compressed response and symbolize keys" do
69
+ prepare_mock_request_dump :bzip2
70
+ @template_hash_symbolized.should == Yajl::HttpStream.delete(@uri, :symbolize_keys => true)
71
+ end
72
+ end
73
+
74
+ it "should parse a deflate compressed response" do
75
+ prepare_mock_request_dump :deflate
76
+ @template_hash.should == Yajl::HttpStream.delete(@uri)
77
+ end
78
+
79
+ it "should parse a deflate compressed response and symbolize keys" do
80
+ prepare_mock_request_dump :deflate
81
+ @template_hash_symbolized.should == Yajl::HttpStream.delete(@uri, :symbolize_keys => true)
82
+ end
83
+
84
+ it "should parse a gzip compressed response" do
85
+ prepare_mock_request_dump :gzip
86
+ @template_hash.should == Yajl::HttpStream.delete(@uri)
87
+ end
88
+
89
+ it "should parse a gzip compressed response and symbolize keys" do
90
+ prepare_mock_request_dump :gzip
91
+ @template_hash_symbolized.should == Yajl::HttpStream.delete(@uri, :symbolize_keys => true)
92
+ end
93
+
94
+ it "should raise when an HTTP code that isn't 200 is returned" do
95
+ prepare_mock_request_dump :error
96
+ lambda { Yajl::HttpStream.delete(@uri) }.should raise_exception(Yajl::HttpStream::HttpError)
97
+ end
98
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
2
+ begin
3
+ require 'yajl/bzip2'
4
+ rescue
5
+ warn "Couldn't load yajl/bzip2, maybe you don't have bzip2-ruby installed? Continuing without running bzip2 specs."
6
+ end
7
+ require 'yajl/gzip'
8
+ require 'yajl/deflate'
9
+ require 'yajl/http_stream'
10
+
11
+ describe "Yajl HTTP error" do
12
+ before(:all) do
13
+ @request = File.new(File.expand_path(File.dirname(__FILE__) + "/fixtures/http.error.dump"), 'r')
14
+ @uri = 'file://'+File.expand_path(File.dirname(__FILE__) + "/fixtures/http/http.error.dump")
15
+ TCPSocket.should_receive(:new).and_return(@request)
16
+ @request.should_receive(:write)
17
+
18
+ begin
19
+ Yajl::HttpStream.get(@uri)
20
+ rescue Yajl::HttpStream::HttpError => e
21
+ @error = e
22
+ end
23
+ end
24
+
25
+ it "should contain the error code in the message" do
26
+ @error.message.should match(/404/)
27
+ end
28
+
29
+ it "should provide the HTTP response headers" do
30
+ @error.headers.keys.should include('ETag', 'Content-Length', 'Server')
31
+ end
32
+ end
@@ -0,0 +1,109 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
2
+ begin
3
+ require 'yajl/bzip2'
4
+ rescue
5
+ warn "Couldn't load yajl/bzip2, maybe you don't have bzip2-ruby installed? Continuing without running bzip2 specs."
6
+ end
7
+ require 'yajl/gzip'
8
+ require 'yajl/deflate'
9
+ require 'yajl/http_stream'
10
+
11
+ def parse_off_headers(io)
12
+ io.each_line do |line|
13
+ if line == "\r\n" # end of the headers
14
+ break
15
+ end
16
+ end
17
+ end
18
+
19
+ describe "Yajl HTTP GET request" do
20
+ before(:all) do
21
+ raw = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.raw.dump'), 'r')
22
+ parse_off_headers(raw)
23
+ @template_hash = Yajl::Parser.parse(raw)
24
+
25
+ raw.rewind
26
+ parse_off_headers(raw)
27
+ @template_hash_symbolized = Yajl::Parser.parse(raw, :symbolize_keys => true)
28
+
29
+ @deflate = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.deflate.dump'), 'r')
30
+ @gzip = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.gzip.dump'), 'r')
31
+ @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}}
32
+ end
33
+
34
+ after(:each) do
35
+ @file_path = nil
36
+ end
37
+
38
+ def prepare_mock_request_dump(format=:raw)
39
+ @request = File.new(File.expand_path(File.dirname(__FILE__) + "/fixtures/http.#{format}.dump"), 'r')
40
+ @uri = 'file://'+File.expand_path(File.dirname(__FILE__) + "/fixtures/http/http.#{format}.dump")
41
+ TCPSocket.should_receive(:new).and_return(@request)
42
+ @request.should_receive(:write)
43
+ end
44
+
45
+ it "should parse a raw response" do
46
+ prepare_mock_request_dump :raw
47
+ @template_hash.should == Yajl::HttpStream.get(@uri)
48
+ end
49
+
50
+ it "should parse a raw response and symbolize keys" do
51
+ prepare_mock_request_dump :raw
52
+ @template_hash_symbolized.should == Yajl::HttpStream.get(@uri, :symbolize_keys => true)
53
+ end
54
+
55
+ it "should parse a raw response using instance method" do
56
+ prepare_mock_request_dump :raw
57
+ @uri.should_receive(:host)
58
+ @uri.should_receive(:port)
59
+ stream = Yajl::HttpStream.new
60
+ @template_hash.should == stream.get(@uri)
61
+ end
62
+
63
+ it "should parse a chunked response using instance method" do
64
+ prepare_mock_request_dump :chunked
65
+ @uri.should_receive(:host)
66
+ @uri.should_receive(:port)
67
+ stream = Yajl::HttpStream.new
68
+ stream.get(@uri) do |obj|
69
+ obj.should eql(@chunked_body)
70
+ end
71
+ end
72
+
73
+ if defined?(Yajl::Bzip2::StreamReader)
74
+ it "should parse a bzip2 compressed response" do
75
+ prepare_mock_request_dump :bzip2
76
+ @template_hash.should == Yajl::HttpStream.get(@uri)
77
+ end
78
+
79
+ it "should parse a bzip2 compressed response and symbolize keys" do
80
+ prepare_mock_request_dump :bzip2
81
+ @template_hash_symbolized.should == Yajl::HttpStream.get(@uri, :symbolize_keys => true)
82
+ end
83
+ end
84
+
85
+ it "should parse a deflate compressed response" do
86
+ prepare_mock_request_dump :deflate
87
+ @template_hash.should == Yajl::HttpStream.get(@uri)
88
+ end
89
+
90
+ it "should parse a deflate compressed response and symbolize keys" do
91
+ prepare_mock_request_dump :deflate
92
+ @template_hash_symbolized.should == Yajl::HttpStream.get(@uri, :symbolize_keys => true)
93
+ end
94
+
95
+ it "should parse a gzip compressed response" do
96
+ prepare_mock_request_dump :gzip
97
+ @template_hash.should == Yajl::HttpStream.get(@uri)
98
+ end
99
+
100
+ it "should parse a gzip compressed response and symbolize keys" do
101
+ prepare_mock_request_dump :gzip
102
+ @template_hash_symbolized.should == Yajl::HttpStream.get(@uri, :symbolize_keys => true)
103
+ end
104
+
105
+ it "should raise when an HTTP code that isn't 200 is returned" do
106
+ prepare_mock_request_dump :error
107
+ lambda { Yajl::HttpStream.get(@uri) }.should raise_exception(Yajl::HttpStream::HttpError)
108
+ end
109
+ end
@@ -0,0 +1,123 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
2
+ begin
3
+ require 'yajl/bzip2'
4
+ rescue
5
+ warn "Couldn't load yajl/bzip2, maybe you don't have bzip2-ruby installed? Continuing without running bzip2 specs."
6
+ end
7
+ require 'yajl/gzip'
8
+ require 'yajl/deflate'
9
+ require 'yajl/http_stream'
10
+
11
+ def parse_off_headers(io)
12
+ io.each_line do |line|
13
+ if line == "\r\n" # end of the headers
14
+ break
15
+ end
16
+ end
17
+ end
18
+
19
+ describe "Yajl HTTP POST request" do
20
+ before(:all) do
21
+ raw = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.raw.dump'), 'r')
22
+ parse_off_headers(raw)
23
+ @template_hash = Yajl::Parser.parse(raw)
24
+
25
+ raw.rewind
26
+ parse_off_headers(raw)
27
+ @template_hash_symbolized = Yajl::Parser.parse(raw, :symbolize_keys => true)
28
+
29
+ @deflate = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.deflate.dump'), 'r')
30
+ @gzip = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.gzip.dump'), 'r')
31
+ @body = "blah=foo&bar=baz"
32
+ @hashed_body = {:blah => 'foo', 'bar' => 'baz'}
33
+ @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}}
34
+ end
35
+
36
+ after(:each) do
37
+ @file_path = nil
38
+ end
39
+
40
+ def prepare_mock_request_dump(format=:raw)
41
+ @request = File.new(File.expand_path(File.dirname(__FILE__) + "/fixtures/http.#{format}.dump"), 'r')
42
+ @uri = 'file://'+File.expand_path(File.dirname(__FILE__) + "/fixtures/http/http.#{format}.dump")
43
+ TCPSocket.should_receive(:new).and_return(@request)
44
+ @request.should_receive(:write)
45
+ end
46
+
47
+ it "should parse a raw response" do
48
+ prepare_mock_request_dump :raw
49
+ @template_hash.should == Yajl::HttpStream.post(@uri, @body)
50
+ end
51
+
52
+ it "should parse a raw response using instance method" do
53
+ prepare_mock_request_dump :raw
54
+ @uri.should_receive(:host)
55
+ @uri.should_receive(:port)
56
+ stream = Yajl::HttpStream.new
57
+ @template_hash.should == stream.post(@uri, @body)
58
+ end
59
+
60
+ it "should parse a raw response with hashed body" do
61
+ prepare_mock_request_dump :raw
62
+ @template_hash.should == Yajl::HttpStream.post(@uri, @hashed_body)
63
+ end
64
+
65
+ it "should parse a raw response and symbolize keys" do
66
+ prepare_mock_request_dump :raw
67
+ @template_hash_symbolized.should == Yajl::HttpStream.post(@uri, @body, :symbolize_keys => true)
68
+ end
69
+
70
+ if defined?(Yajl::Bzip2::StreamReader)
71
+ it "should parse a bzip2 compressed response" do
72
+ prepare_mock_request_dump :bzip2
73
+ @template_hash.should == Yajl::HttpStream.post(@uri, @body)
74
+ end
75
+
76
+ it "should parse a bzip2 compressed response and symbolize keys" do
77
+ prepare_mock_request_dump :bzip2
78
+ @template_hash_symbolized.should == Yajl::HttpStream.post(@uri, @body, :symbolize_keys => true)
79
+ end
80
+ end
81
+
82
+ it "should parse a deflate compressed response" do
83
+ prepare_mock_request_dump :deflate
84
+ @template_hash.should == Yajl::HttpStream.post(@uri, @body)
85
+ end
86
+
87
+ it "should parse a deflate compressed response and symbolize keys" do
88
+ prepare_mock_request_dump :deflate
89
+ @template_hash_symbolized.should == Yajl::HttpStream.post(@uri, @body, :symbolize_keys => true)
90
+ end
91
+
92
+ it "should parse a gzip compressed response" do
93
+ prepare_mock_request_dump :gzip
94
+ @template_hash.should == Yajl::HttpStream.post(@uri, @body)
95
+ end
96
+
97
+ it "should parse a gzip compressed response and symbolize keys" do
98
+ prepare_mock_request_dump :gzip
99
+ @template_hash_symbolized.should == Yajl::HttpStream.post(@uri, @body, :symbolize_keys => true)
100
+ end
101
+
102
+ it "should parse a chunked raw response" do
103
+ prepare_mock_request_dump :chunked
104
+ Yajl::HttpStream.post(@uri, @body) do |obj|
105
+ obj.should eql(@chunked_body)
106
+ end
107
+ end
108
+
109
+ it "should throw Exception if chunked response and no block given" do
110
+ prepare_mock_request_dump :chunked
111
+ lambda {Yajl::HttpStream.post(@uri, @body)}.should raise_error(Exception)
112
+ end
113
+
114
+ it "should throw InvalidContentType if unable to handle the MIME type" do
115
+ prepare_mock_request_dump :html
116
+ lambda {Yajl::HttpStream.post(@uri, @body)}.should raise_error(Yajl::HttpStream::InvalidContentType)
117
+ end
118
+
119
+ it "should raise when an HTTP code that isn't 200 is returned" do
120
+ prepare_mock_request_dump :error
121
+ lambda { Yajl::HttpStream.post(@uri, @body) }.should raise_exception(Yajl::HttpStream::HttpError)
122
+ end
123
+ end
@@ -0,0 +1,105 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
2
+ begin
3
+ require 'yajl/bzip2'
4
+ rescue
5
+ warn "Couldn't load yajl/bzip2, maybe you don't have bzip2-ruby installed? Continuing without running bzip2 specs."
6
+ end
7
+ require 'yajl/gzip'
8
+ require 'yajl/deflate'
9
+ require 'yajl/http_stream'
10
+
11
+ def parse_off_headers(io)
12
+ io.each_line do |line|
13
+ if line == "\r\n" # end of the headers
14
+ break
15
+ end
16
+ end
17
+ end
18
+
19
+ describe "Yajl HTTP PUT request" do
20
+ before(:all) do
21
+ raw = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.raw.dump'), 'r')
22
+ parse_off_headers(raw)
23
+ @template_hash = Yajl::Parser.parse(raw)
24
+
25
+ raw.rewind
26
+ parse_off_headers(raw)
27
+ @template_hash_symbolized = Yajl::Parser.parse(raw, :symbolize_keys => true)
28
+
29
+ @deflate = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.deflate.dump'), 'r')
30
+ @gzip = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.gzip.dump'), 'r')
31
+ @body = "blah=foo&bar=baz"
32
+ @hashed_body = {:blah => 'foo', 'bar' => 'baz'}
33
+ end
34
+
35
+ after(:each) do
36
+ @file_path = nil
37
+ end
38
+
39
+ def prepare_mock_request_dump(format=:raw)
40
+ @request = File.new(File.expand_path(File.dirname(__FILE__) + "/fixtures/http.#{format}.dump"), 'r')
41
+ @uri = 'file://'+File.expand_path(File.dirname(__FILE__) + "/fixtures/http/http.#{format}.dump")
42
+ TCPSocket.should_receive(:new).and_return(@request)
43
+ @request.should_receive(:write)
44
+ end
45
+
46
+ it "should parse a raw response" do
47
+ prepare_mock_request_dump :raw
48
+ @template_hash.should == Yajl::HttpStream.put(@uri, @body)
49
+ end
50
+
51
+ it "should parse a raw response using instance method" do
52
+ prepare_mock_request_dump :raw
53
+ @uri.should_receive(:host)
54
+ @uri.should_receive(:port)
55
+ stream = Yajl::HttpStream.new
56
+ @template_hash.should == stream.put(@uri, @body)
57
+ end
58
+
59
+ it "should parse a raw response with hashed body" do
60
+ prepare_mock_request_dump :raw
61
+ @template_hash.should == Yajl::HttpStream.post(@uri, @hashed_body)
62
+ end
63
+
64
+ it "should parse a raw response and symbolize keys" do
65
+ prepare_mock_request_dump :raw
66
+ @template_hash_symbolized.should == Yajl::HttpStream.put(@uri, @body, :symbolize_keys => true)
67
+ end
68
+
69
+ if defined?(Yajl::Bzip2::StreamReader)
70
+ it "should parse a bzip2 compressed response" do
71
+ prepare_mock_request_dump :bzip2
72
+ @template_hash.should == Yajl::HttpStream.put(@uri, @body)
73
+ end
74
+
75
+ it "should parse a bzip2 compressed response and symbolize keys" do
76
+ prepare_mock_request_dump :bzip2
77
+ @template_hash_symbolized.should == Yajl::HttpStream.put(@uri, @body, :symbolize_keys => true)
78
+ end
79
+ end
80
+
81
+ it "should parse a deflate compressed response" do
82
+ prepare_mock_request_dump :deflate
83
+ @template_hash.should == Yajl::HttpStream.put(@uri, @body)
84
+ end
85
+
86
+ it "should parse a deflate compressed response and symbolize keys" do
87
+ prepare_mock_request_dump :deflate
88
+ @template_hash_symbolized.should == Yajl::HttpStream.put(@uri, @body, :symbolize_keys => true)
89
+ end
90
+
91
+ it "should parse a gzip compressed response" do
92
+ prepare_mock_request_dump :gzip
93
+ @template_hash.should == Yajl::HttpStream.put(@uri, @body)
94
+ end
95
+
96
+ it "should parse a gzip compressed response and symbolize keys" do
97
+ prepare_mock_request_dump :gzip
98
+ @template_hash_symbolized.should == Yajl::HttpStream.put(@uri, @body, :symbolize_keys => true)
99
+ end
100
+
101
+ it "should raise when an HTTP code that isn't 200 is returned" do
102
+ prepare_mock_request_dump :error
103
+ lambda { Yajl::HttpStream.put(@uri, @body) }.should raise_exception(Yajl::HttpStream::HttpError)
104
+ end
105
+ end