brianmario-yajl-ruby 0.5.6 → 0.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,80 +15,71 @@ end
15
15
 
16
16
  describe "Yajl HTTP GET request" do
17
17
  before(:all) do
18
- @raw = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.raw.dump'), 'r')
19
- @bzip2 = File.new(File.expand_path(File.dirname(__FILE__) + '/fixtures/http.bzip2.dump'), 'r')
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(:all) do
29
- @raw.close unless @raw.closed?
30
- @bzip2.close unless @bzip2.closed?
31
- @deflate.close unless @deflate.closed?
32
- @gzip.close unless @gzip.closed?
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
- file = File.expand_path(File.dirname(__FILE__) + '/http/http.raw.dump')
37
- uri = 'file://'+file
38
-
39
- TCPSocket.should_receive(:new).and_return(@raw)
40
- @raw.should_receive(:write)
41
- uri.should_receive(:host).at_least(2).times
42
- uri.should_receive(:port)
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
- file = File.expand_path(File.dirname(__FILE__) + '/http/http.bzip2.dump')
52
- uri = 'file://'+file
53
-
54
- TCPSocket.should_receive(:new).and_return(@bzip2)
55
- @bzip2.should_receive(:write)
56
- uri.should_receive(:host).at_least(2).times
57
- uri.should_receive(:port)
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
- file = File.expand_path(File.dirname(__FILE__) + '/http/http.deflate.dump')
67
- uri = 'file://'+file
68
-
69
- TCPSocket.should_receive(:new).and_return(@deflate)
70
- @deflate.should_receive(:write)
71
- uri.should_receive(:host).at_least(2).times
72
- uri.should_receive(:port)
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
- file = File.expand_path(File.dirname(__FILE__) + '/http/http.gzip.dump')
82
- uri = 'file://'+file
83
-
84
- TCPSocket.should_receive(:new).and_return(@gzip)
85
- @gzip.should_receive(:write)
86
- uri.should_receive(:host).at_least(2).times
87
- uri.should_receive(:port)
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
- parser = Yajl::Parser.new
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
- parser = Yajl::Parser.new
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
- parser = Yajl::Parser.new
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
- parser = Yajl::Parser.new
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
- parser = Yajl::Parser.new
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
- parser = Yajl::Parser.new
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
- parser = Yajl::Parser.new
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
- parser = Yajl::Parser.new
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
- parser = Yajl::Parser.new
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
- parser.parse(json)
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
- parser.parse(json)
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
- parser = Yajl::Parser.new(:symbolize_keys => true)
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
@@ -0,0 +1,4 @@
1
+ --exclude spec,gem
2
+ --text-summary
3
+ --spec-only
4
+ --sort coverage --sort-reverse
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --format specdoc
2
+ --colour
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
- begin
5
- require './yajl_ext'
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.6"
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-19}
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.6
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-19 00:00:00 -07:00
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