brianmario-yajl-ruby 0.5.6 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -0
- data/README.rdoc +7 -1
- data/Rakefile +8 -2
- data/VERSION.yml +1 -1
- data/examples/http/twitter_stream_api.rb +3 -1
- data/lib/yajl/deflate/stream_reader.rb +2 -1
- data/lib/yajl/http_stream.rb +6 -6
- data/lib/yajl.rb +1 -1
- data/spec/http/fixtures/http.bzip2.dump +0 -0
- data/spec/http/fixtures/http.deflate.dump +0 -0
- data/spec/http/fixtures/http.gzip.dump +0 -0
- data/spec/http/fixtures/http.raw.dump +1220 -6
- data/spec/http/http_spec.rb +50 -59
- data/spec/parsing/active_support_spec.rb +4 -8
- data/spec/parsing/fixtures_spec.rb +4 -8
- data/spec/parsing/one_off_spec.rb +4 -8
- data/spec/rcov.opts +4 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +2 -7
- data/yajl-ruby.gemspec +4 -2
- metadata +4 -2
data/spec/http/http_spec.rb
CHANGED
@@ -15,80 +15,71 @@ end
|
|
15
15
|
|
16
16
|
describe "Yajl HTTP GET request" do
|
17
17
|
before(:all) do
|
18
|
-
|
19
|
-
|
18
|
+
raw = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.raw.dump'), 'r')
|
19
|
+
parse_off_headers(raw)
|
20
|
+
@template_hash = Yajl::Parser.parse(raw)
|
21
|
+
|
22
|
+
raw.rewind
|
23
|
+
parse_off_headers(raw)
|
24
|
+
@template_hash_symbolized = Yajl::Parser.parse(raw, :symbolize_keys => true)
|
25
|
+
|
20
26
|
@deflate = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.deflate.dump'), 'r')
|
21
27
|
@gzip = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.gzip.dump'), 'r')
|
22
|
-
|
23
|
-
parse_off_headers(@raw)
|
24
|
-
@raw_template_hash = Yajl::Parser.new.parse(@raw)
|
25
|
-
@raw.rewind
|
26
28
|
end
|
27
29
|
|
28
|
-
after(:
|
29
|
-
@
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
after(:each) do
|
31
|
+
@file_path = nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def prepare_mock_request_dump(format=:raw)
|
35
|
+
@request = File.new(File.expand_path(File.dirname(__FILE__) + "/fixtures/http.#{format}.dump"), 'r')
|
36
|
+
@uri = 'file://'+File.expand_path(File.dirname(__FILE__) + "/fixtures/http/http.#{format}.dump")
|
37
|
+
TCPSocket.should_receive(:new).and_return(@request)
|
38
|
+
@request.should_receive(:write)
|
39
|
+
@uri.should_receive(:host).at_least(2).times
|
40
|
+
@uri.should_receive(:port)
|
41
|
+
@uri.should_receive(:path)
|
42
|
+
@uri.should_receive(:query)
|
43
|
+
@uri.should_receive(:userinfo)
|
33
44
|
end
|
34
45
|
|
35
46
|
it "should parse a raw response" do
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
uri.should_receive(:path)
|
44
|
-
uri.should_receive(:query)
|
45
|
-
uri.should_receive(:userinfo)
|
46
|
-
|
47
|
-
@raw_template_hash.should == Yajl::HttpStream.get(uri)
|
47
|
+
prepare_mock_request_dump :raw
|
48
|
+
@template_hash.should == Yajl::HttpStream.get(@uri)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should parse a raw response and symbolize keys" do
|
52
|
+
prepare_mock_request_dump :raw
|
53
|
+
@template_hash_symbolized.should == Yajl::HttpStream.get(@uri, :symbolize_keys => true)
|
48
54
|
end
|
49
55
|
|
50
56
|
it "should parse a bzip2 compressed response" do
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
uri.should_receive(:path)
|
59
|
-
uri.should_receive(:query)
|
60
|
-
uri.should_receive(:userinfo)
|
61
|
-
|
62
|
-
@raw_template_hash.should == Yajl::HttpStream.get(uri)
|
57
|
+
prepare_mock_request_dump :bzip2
|
58
|
+
@template_hash.should == Yajl::HttpStream.get(@uri)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should parse a bzip2 compressed response and symbolize keys" do
|
62
|
+
prepare_mock_request_dump :bzip2
|
63
|
+
@template_hash_symbolized.should == Yajl::HttpStream.get(@uri, :symbolize_keys => true)
|
63
64
|
end
|
64
65
|
|
65
66
|
it "should parse a deflate compressed response" do
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
uri.should_receive(:path)
|
74
|
-
uri.should_receive(:query)
|
75
|
-
uri.should_receive(:userinfo)
|
76
|
-
|
77
|
-
@raw_template_hash.should == Yajl::HttpStream.get(uri)
|
67
|
+
prepare_mock_request_dump :deflate
|
68
|
+
@template_hash.should == Yajl::HttpStream.get(@uri)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should parse a deflate compressed response and symbolize keys" do
|
72
|
+
prepare_mock_request_dump :deflate
|
73
|
+
@template_hash_symbolized.should == Yajl::HttpStream.get(@uri, :symbolize_keys => true)
|
78
74
|
end
|
79
75
|
|
80
76
|
it "should parse a gzip compressed response" do
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
uri.should_receive(:path)
|
89
|
-
uri.should_receive(:query)
|
90
|
-
uri.should_receive(:userinfo)
|
91
|
-
|
92
|
-
@raw_template_hash.should == Yajl::HttpStream.get(uri)
|
77
|
+
prepare_mock_request_dump :gzip
|
78
|
+
@template_hash.should == Yajl::HttpStream.get(@uri)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should parse a gzip compressed response and symbolize keys" do
|
82
|
+
prepare_mock_request_dump :gzip
|
83
|
+
@template_hash_symbolized.should == Yajl::HttpStream.get(@uri, :symbolize_keys => true)
|
93
84
|
end
|
94
85
|
end
|
@@ -37,8 +37,7 @@ describe "ActiveSupport test cases" do
|
|
37
37
|
TESTS.each do |json, expected|
|
38
38
|
it "should be able to parse #{json} as an IO" do
|
39
39
|
lambda {
|
40
|
-
|
41
|
-
parser.parse(StringIO.new(json)).should == expected
|
40
|
+
Yajl::Parser.parse(StringIO.new(json)).should == expected
|
42
41
|
}.should_not raise_error(Yajl::ParseError)
|
43
42
|
end
|
44
43
|
end
|
@@ -46,23 +45,20 @@ describe "ActiveSupport test cases" do
|
|
46
45
|
TESTS.each do |json, expected|
|
47
46
|
it "should be able to parse #{json} as a string" do
|
48
47
|
lambda {
|
49
|
-
|
50
|
-
parser.parse(json).should == expected
|
48
|
+
Yajl::Parser.parse(json).should == expected
|
51
49
|
}.should_not raise_error(Yajl::ParseError)
|
52
50
|
end
|
53
51
|
end
|
54
52
|
|
55
53
|
it "should fail parsing {: 1} as an IO" do
|
56
54
|
lambda {
|
57
|
-
|
58
|
-
parser.parse(StringIO.new("{: 1}"))
|
55
|
+
Yajl::Parser.parse(StringIO.new("{: 1}"))
|
59
56
|
}.should raise_error(Yajl::ParseError)
|
60
57
|
end
|
61
58
|
|
62
59
|
it "should fail parsing {: 1} as a string" do
|
63
60
|
lambda {
|
64
|
-
|
65
|
-
parser.parse("{: 1}")
|
61
|
+
Yajl::Parser.parse("{: 1}")
|
66
62
|
}.should raise_error(Yajl::ParseError)
|
67
63
|
end
|
68
64
|
end
|
@@ -10,8 +10,7 @@ describe "Parsing JSON Fixtures" do
|
|
10
10
|
FAILED.each do |name, source|
|
11
11
|
it "should not be able to parse #{File.basename(name)} as an IO" do
|
12
12
|
lambda {
|
13
|
-
|
14
|
-
parser.parse(StringIO.new(source))
|
13
|
+
Yajl::Parser.parse(StringIO.new(source))
|
15
14
|
}.should raise_error(Yajl::ParseError)
|
16
15
|
end
|
17
16
|
end
|
@@ -19,8 +18,7 @@ describe "Parsing JSON Fixtures" do
|
|
19
18
|
FAILED.each do |name, source|
|
20
19
|
it "should not be able to parse #{File.basename(name)} as a string" do
|
21
20
|
lambda {
|
22
|
-
|
23
|
-
parser.parse(source)
|
21
|
+
Yajl::Parser.parse(source)
|
24
22
|
}.should raise_error(Yajl::ParseError)
|
25
23
|
end
|
26
24
|
end
|
@@ -28,8 +26,7 @@ describe "Parsing JSON Fixtures" do
|
|
28
26
|
PASSED.each do |name, source|
|
29
27
|
it "should be able to parse #{File.basename(name)} as an IO" do
|
30
28
|
lambda {
|
31
|
-
|
32
|
-
parser.parse(StringIO.new(source))
|
29
|
+
Yajl::Parser.parse(StringIO.new(source))
|
33
30
|
}.should_not raise_error(Yajl::ParseError)
|
34
31
|
end
|
35
32
|
end
|
@@ -37,8 +34,7 @@ describe "Parsing JSON Fixtures" do
|
|
37
34
|
PASSED.each do |name, source|
|
38
35
|
it "should be able to parse #{File.basename(name)} as a string" do
|
39
36
|
lambda {
|
40
|
-
|
41
|
-
parser.parse(source)
|
37
|
+
Yajl::Parser.parse(source)
|
42
38
|
}.should_not raise_error(Yajl::ParseError)
|
43
39
|
end
|
44
40
|
end
|
@@ -5,24 +5,21 @@ describe "One-off JSON examples" do
|
|
5
5
|
it "should parse 23456789012E666 and return Infinity" do
|
6
6
|
infinity = (1.0/0)
|
7
7
|
silence_warnings do
|
8
|
-
|
9
|
-
parser.parse(StringIO.new('{"key": 23456789012E666}')).should == {"key" => infinity}
|
8
|
+
Yajl::Parser.parse(StringIO.new('{"key": 23456789012E666}')).should == {"key" => infinity}
|
10
9
|
end
|
11
10
|
end
|
12
11
|
|
13
12
|
it "should not parse JSON with a comment, with :allow_comments set to false" do
|
14
|
-
parser = Yajl::Parser.new(:allow_comments => false)
|
15
13
|
json = StringIO.new('{"key": /* this is a comment */ "value"}')
|
16
14
|
lambda {
|
17
|
-
|
15
|
+
Yajl::Parser.parse(json, :allow_comments => false)
|
18
16
|
}.should raise_error(Yajl::ParseError)
|
19
17
|
end
|
20
18
|
|
21
19
|
it "should parse JSON with a comment, with :allow_comments set to true" do
|
22
|
-
parser = Yajl::Parser.new(:allow_comments => true)
|
23
20
|
json = StringIO.new('{"key": /* this is a comment */ "value"}')
|
24
21
|
lambda {
|
25
|
-
|
22
|
+
Yajl::Parser.parse(json, :allow_comments => true)
|
26
23
|
}.should_not raise_error(Yajl::ParseError)
|
27
24
|
end
|
28
25
|
|
@@ -40,8 +37,7 @@ describe "One-off JSON examples" do
|
|
40
37
|
end
|
41
38
|
|
42
39
|
it "should parse using it's class method, from an IO with symbolized keys" do
|
43
|
-
|
44
|
-
parser.parse('{"key": 1234}').should == {:key => 1234}
|
40
|
+
Yajl::Parser.parse('{"key": 1234}', :symbolize_keys => true).should == {:key => 1234}
|
45
41
|
end
|
46
42
|
|
47
43
|
it "should parse using it's class method, from a string" do
|
data/spec/rcov.opts
ADDED
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,6 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
require 'yajl'
|
7
|
-
rescue LoadError
|
8
|
-
require 'yajl'
|
9
|
-
end
|
10
|
-
require 'stringio'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'yajl'
|
11
6
|
require 'active_support/core_ext/kernel/reporting'
|
data/yajl-ruby.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{yajl-ruby}
|
5
|
-
s.version = "0.5.
|
5
|
+
s.version = "0.5.7"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Brian Lopez", "Lloyd Hilaiel"]
|
9
|
-
s.date = %q{2009-06-
|
9
|
+
s.date = %q{2009-06-23}
|
10
10
|
s.email = %q{seniorlopez@gmail.com}
|
11
11
|
s.extensions = ["ext/extconf.rb"]
|
12
12
|
s.extra_rdoc_files = [
|
@@ -140,6 +140,8 @@ Gem::Specification.new do |s|
|
|
140
140
|
"spec/parsing/fixtures/pass3.json",
|
141
141
|
"spec/parsing/fixtures_spec.rb",
|
142
142
|
"spec/parsing/one_off_spec.rb",
|
143
|
+
"spec/rcov.opts",
|
144
|
+
"spec/spec.opts",
|
143
145
|
"spec/spec_helper.rb",
|
144
146
|
"yajl-ruby.gemspec"
|
145
147
|
]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brianmario-yajl-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Lopez
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-06-
|
13
|
+
date: 2009-06-23 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -150,6 +150,8 @@ files:
|
|
150
150
|
- spec/parsing/fixtures/pass3.json
|
151
151
|
- spec/parsing/fixtures_spec.rb
|
152
152
|
- spec/parsing/one_off_spec.rb
|
153
|
+
- spec/rcov.opts
|
154
|
+
- spec/spec.opts
|
153
155
|
- spec/spec_helper.rb
|
154
156
|
- yajl-ruby.gemspec
|
155
157
|
has_rdoc: false
|