yajl-ruby 1.2.3 → 1.3.0

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.

Potentially problematic release.


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

@@ -8,20 +8,20 @@ describe "Passing options to HttpStream instance methods" do
8
8
  end
9
9
 
10
10
  it "should not create a new socket it one is provided" do
11
- TCPSocket.should_not_receive(:new)
11
+ expect(TCPSocket).not_to receive(:new)
12
12
  options = {:socket => :my_provided_socket}
13
13
 
14
14
  @stream.send(:initialize_socket, URI.parse("http://google.com"), options)
15
15
 
16
- options[:socket].should == :my_provided_socket
16
+ expect(options[:socket]).to eq(:my_provided_socket)
17
17
  end
18
18
 
19
19
  it "should create a new socket if one is not provided" do
20
- TCPSocket.should_receive(:new).with("google.com", 80).and_return( :tcp_socket )
20
+ expect(TCPSocket).to receive(:new).with("google.com", 80).and_return( :tcp_socket )
21
21
  options = {}
22
22
 
23
23
  @stream.send(:initialize_socket, URI.parse("http://google.com"), options)
24
24
 
25
- options[:socket].should == :tcp_socket
25
+ expect(options[:socket]).to eq(:tcp_socket)
26
26
  end
27
27
  end
@@ -7,109 +7,109 @@ describe "JSON Gem compatability API" do
7
7
  it "shoud not mixin #to_json on base objects until compatability has been enabled" do
8
8
  d = Dummy.new
9
9
 
10
- d.respond_to?(:to_json).should_not be_true
11
- "".respond_to?(:to_json).should_not be_true
12
- 1.respond_to?(:to_json).should_not be_true
13
- "1.5".to_f.respond_to?(:to_json).should_not be_true
14
- [].respond_to?(:to_json).should_not be_true
15
- {:foo => "bar"}.respond_to?(:to_json).should_not be_true
16
- true.respond_to?(:to_json).should_not be_true
17
- false.respond_to?(:to_json).should_not be_true
18
- nil.respond_to?(:to_json).should_not be_true
10
+ expect(d.respond_to?(:to_json)).not_to be_truthy
11
+ expect("".respond_to?(:to_json)).not_to be_truthy
12
+ expect(1.respond_to?(:to_json)).not_to be_truthy
13
+ expect("1.5".to_f.respond_to?(:to_json)).not_to be_truthy
14
+ expect([].respond_to?(:to_json)).not_to be_truthy
15
+ expect({:foo => "bar"}.respond_to?(:to_json)).not_to be_truthy
16
+ expect(true.respond_to?(:to_json)).not_to be_truthy
17
+ expect(false.respond_to?(:to_json)).not_to be_truthy
18
+ expect(nil.respond_to?(:to_json)).not_to be_truthy
19
19
  end
20
20
 
21
21
  it "should mixin #to_json on base objects after compatability has been enabled" do
22
22
  require 'yajl/json_gem'
23
23
  d = Dummy.new
24
24
 
25
- d.respond_to?(:to_json).should be_true
26
- "".respond_to?(:to_json).should be_true
27
- 1.respond_to?(:to_json).should be_true
28
- "1.5".to_f.respond_to?(:to_json).should be_true
29
- [].respond_to?(:to_json).should be_true
30
- {:foo => "bar"}.respond_to?(:to_json).should be_true
31
- true.respond_to?(:to_json).should be_true
32
- false.respond_to?(:to_json).should be_true
33
- nil.respond_to?(:to_json).should be_true
25
+ expect(d.respond_to?(:to_json)).to be_truthy
26
+ expect("".respond_to?(:to_json)).to be_truthy
27
+ expect(1.respond_to?(:to_json)).to be_truthy
28
+ expect("1.5".to_f.respond_to?(:to_json)).to be_truthy
29
+ expect([].respond_to?(:to_json)).to be_truthy
30
+ expect({:foo => "bar"}.respond_to?(:to_json)).to be_truthy
31
+ expect(true.respond_to?(:to_json)).to be_truthy
32
+ expect(false.respond_to?(:to_json)).to be_truthy
33
+ expect(nil.respond_to?(:to_json)).to be_truthy
34
34
  end
35
35
 
36
36
  it "should require yajl/json_gem to enable the compatability API" do
37
- defined?(JSON).should be_true
37
+ expect(defined?(JSON)).to be_truthy
38
38
 
39
- JSON.respond_to?(:parse).should be_true
40
- JSON.respond_to?(:generate).should be_true
41
- JSON.respond_to?(:pretty_generate).should be_true
42
- JSON.respond_to?(:load).should be_true
43
- JSON.respond_to?(:dump).should be_true
39
+ expect(JSON.respond_to?(:parse)).to be_truthy
40
+ expect(JSON.respond_to?(:generate)).to be_truthy
41
+ expect(JSON.respond_to?(:pretty_generate)).to be_truthy
42
+ expect(JSON.respond_to?(:load)).to be_truthy
43
+ expect(JSON.respond_to?(:dump)).to be_truthy
44
44
  end
45
45
 
46
46
  it "should allow default parsing options be set with JSON.default_options" do
47
47
  default = JSON.default_options[:symbolize_keys]
48
- JSON.parse('{"foo": 1234}').should === {"foo" => 1234}
48
+ expect(JSON.parse('{"foo": 1234}')).to be === {"foo" => 1234}
49
49
  JSON.default_options[:symbolize_keys] = true
50
- JSON.parse('{"foo": 1234}').should === {:foo => 1234}
50
+ expect(JSON.parse('{"foo": 1234}')).to be === {:foo => 1234}
51
51
  JSON.default_options[:symbolize_keys] = default # ensure the rest of the test cases expect the default
52
52
  end
53
53
 
54
54
  it "should also allow the json gem's symbolize_names key" do
55
- JSON.parse('{"foo": 1234}', :symbolize_names => true).should === {:foo => 1234}
55
+ expect(JSON.parse('{"foo": 1234}', :symbolize_names => true)).to be === {:foo => 1234}
56
56
  end
57
57
 
58
58
  it "should encode arbitrary classes via their default to_json method" do
59
59
  d = Dummy.new
60
- d.to_json.should == "\"#{d.to_s}\""
60
+ expect(d.to_json).to eq("\"#{d.to_s}\"")
61
61
 
62
62
  t = Time.now
63
- t.to_json.should == "\"#{t.to_s}\""
63
+ expect(t.to_json).to eq("\"#{t.to_s}\"")
64
64
 
65
65
  da = Date.today
66
- da.to_json.should == "\"#{da.to_s}\""
66
+ expect(da.to_json).to eq("\"#{da.to_s}\"")
67
67
 
68
68
  dt = DateTime.new
69
- dt.to_json.should == "\"#{dt.to_s}\""
69
+ expect(dt.to_json).to eq("\"#{dt.to_s}\"")
70
70
  end
71
71
 
72
72
  it "should have the standard parsing and encoding exceptions mapped" do
73
- JSON::JSONError.new.is_a?(StandardError).should be_true
74
- JSON::ParserError.new.is_a?(JSON::JSONError).should be_true
75
- JSON::GeneratorError.new.is_a?(JSON::JSONError).should be_true
73
+ expect(JSON::JSONError.new.is_a?(StandardError)).to be_truthy
74
+ expect(JSON::ParserError.new.is_a?(JSON::JSONError)).to be_truthy
75
+ expect(JSON::GeneratorError.new.is_a?(JSON::JSONError)).to be_truthy
76
76
 
77
- lambda {
77
+ expect {
78
78
  JSON.parse("blah")
79
- }.should raise_error(JSON::ParserError)
79
+ }.to raise_error(JSON::ParserError)
80
80
 
81
- lambda {
81
+ expect {
82
82
  JSON.generate(0.0/0.0)
83
- }.should raise_error(JSON::GeneratorError)
83
+ }.to raise_error(JSON::GeneratorError)
84
84
  end
85
85
 
86
86
  context "ported tests for Unicode" do
87
87
  it "should be able to encode and parse unicode" do
88
- '""'.should eql(''.to_json)
89
- '"\\b"'.should eql("\b".to_json)
90
- '"\u0001"'.should eql(0x1.chr.to_json)
91
- '"\u001F"'.should eql(0x1f.chr.to_json)
92
- '" "'.should eql(' '.to_json)
93
- "\"#{0x7f.chr}\"".should eql(0x7f.chr.to_json)
88
+ expect('""').to eql(''.to_json)
89
+ expect('"\\b"').to eql("\b".to_json)
90
+ expect('"\u0001"').to eql(0x1.chr.to_json)
91
+ expect('"\u001F"').to eql(0x1f.chr.to_json)
92
+ expect('" "').to eql(' '.to_json)
93
+ expect("\"#{0x7f.chr}\"").to eql(0x7f.chr.to_json)
94
94
  utf8 = [ "© ≠ €! \01" ]
95
95
  json = "[\"© ≠ €! \\u0001\"]"
96
- json.should eql(utf8.to_json)
97
- utf8.should eql(JSON.parse(json))
96
+ expect(json).to eql(utf8.to_json)
97
+ expect(utf8).to eql(JSON.parse(json))
98
98
  utf8 = ["\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212"]
99
99
  json = "[\"あいうえお\"]"
100
- json.should eql(utf8.to_json)
101
- utf8.should eql(JSON.parse(json))
100
+ expect(json).to eql(utf8.to_json)
101
+ expect(utf8).to eql(JSON.parse(json))
102
102
  utf8 = ['საქართველო']
103
103
  json = "[\"საქართველო\"]"
104
- json.should eql(utf8.to_json)
105
- utf8.should eql(JSON.parse(json))
106
- '["Ã"]'.should eql(JSON.generate(["Ã"]))
107
- ["€"].should eql(JSON.parse('["\u20ac"]'))
104
+ expect(json).to eql(utf8.to_json)
105
+ expect(utf8).to eql(JSON.parse(json))
106
+ expect('["Ã"]').to eql(JSON.generate(["Ã"]))
107
+ expect(["€"]).to eql(JSON.parse('["\u20ac"]'))
108
108
  utf8_str = "\xf0\xa0\x80\x81"
109
109
  utf8 = [utf8_str]
110
110
  json = "[\"#{utf8_str}\"]"
111
- json.should eql(JSON.generate(utf8))
112
- utf8.should eql(JSON.parse(json))
111
+ expect(json).to eql(JSON.generate(utf8))
112
+ expect(utf8).to eql(JSON.parse(json))
113
113
  end
114
114
  end
115
115
 
@@ -144,25 +144,25 @@ describe "JSON Gem compatability API" do
144
144
 
145
145
  it "should be able to unparse" do
146
146
  json = JSON.generate(@hash)
147
- JSON.parse(@json2).should == JSON.parse(json)
147
+ expect(JSON.parse(@json2)).to eq(JSON.parse(json))
148
148
  parsed_json = JSON.parse(json)
149
- @hash.should == parsed_json
149
+ expect(@hash).to eq(parsed_json)
150
150
  json = JSON.generate({1=>2})
151
- '{"1":2}'.should eql(json)
151
+ expect('{"1":2}').to eql(json)
152
152
  parsed_json = JSON.parse(json)
153
- {"1"=>2}.should == parsed_json
153
+ expect({"1"=>2}).to eq(parsed_json)
154
154
  end
155
155
 
156
156
  it "should be able to unparse pretty" do
157
157
  json = JSON.pretty_generate(@hash)
158
- JSON.parse(@json3).should == JSON.parse(json)
158
+ expect(JSON.parse(@json3)).to eq(JSON.parse(json))
159
159
  parsed_json = JSON.parse(json)
160
- @hash.should == parsed_json
160
+ expect(@hash).to eq(parsed_json)
161
161
  json = JSON.pretty_generate({1=>2})
162
162
  test = "{\n \"1\": 2\n}".chomp
163
- test.should == json
163
+ expect(test).to eq(json)
164
164
  parsed_json = JSON.parse(json)
165
- {"1"=>2}.should == parsed_json
165
+ expect({"1"=>2}).to eq(parsed_json)
166
166
  end
167
167
  end
168
168
 
@@ -174,33 +174,33 @@ describe "JSON Gem compatability API" do
174
174
 
175
175
  JSON_FAILED.each do |name, source|
176
176
  it "should not be able to parse #{File.basename(name)} as an IO" do
177
- lambda {
177
+ expect {
178
178
  JSON.parse(StringIO.new(source))
179
- }.should raise_error(JSON::ParserError)
179
+ }.to raise_error(JSON::ParserError)
180
180
  end
181
181
  end
182
182
 
183
183
  JSON_FAILED.each do |name, source|
184
184
  it "should not be able to parse #{File.basename(name)} as a string" do
185
- lambda {
185
+ expect {
186
186
  JSON.parse(source)
187
- }.should raise_error(JSON::ParserError)
187
+ }.to raise_error(JSON::ParserError)
188
188
  end
189
189
  end
190
190
 
191
191
  JSON_PASSED.each do |name, source|
192
192
  it "should be able to parse #{File.basename(name)} as an IO" do
193
- lambda {
193
+ expect {
194
194
  JSON.parse(StringIO.new(source))
195
- }.should_not raise_error
195
+ }.not_to raise_error
196
196
  end
197
197
  end
198
198
 
199
199
  JSON_PASSED.each do |name, source|
200
200
  it "should be able to parse #{File.basename(name)} as a string" do
201
- lambda {
201
+ expect {
202
202
  JSON.parse(source)
203
- }.should_not raise_error
203
+ }.not_to raise_error
204
204
  end
205
205
  end
206
206
  end
@@ -36,29 +36,29 @@ describe "ActiveSupport test cases" do
36
36
 
37
37
  TESTS.each do |json, expected|
38
38
  it "should be able to parse #{json} as an IO" do
39
- lambda {
40
- Yajl::Parser.parse(StringIO.new(json)).should == expected
41
- }.should_not raise_error
39
+ expect {
40
+ expect(Yajl::Parser.parse(StringIO.new(json))).to eq(expected)
41
+ }.not_to raise_error
42
42
  end
43
43
  end
44
44
 
45
45
  TESTS.each do |json, expected|
46
46
  it "should be able to parse #{json} as a string" do
47
- lambda {
48
- Yajl::Parser.parse(json).should == expected
49
- }.should_not raise_error
47
+ expect {
48
+ expect(Yajl::Parser.parse(json)).to eq(expected)
49
+ }.not_to raise_error
50
50
  end
51
51
  end
52
52
 
53
53
  it "should fail parsing {: 1} as an IO" do
54
- lambda {
54
+ expect {
55
55
  Yajl::Parser.parse(StringIO.new("{: 1}"))
56
- }.should raise_error(Yajl::ParseError)
56
+ }.to raise_error(Yajl::ParseError)
57
57
  end
58
58
 
59
59
  it "should fail parsing {: 1} as a string" do
60
- lambda {
60
+ expect {
61
61
  Yajl::Parser.parse("{: 1}")
62
- }.should raise_error(Yajl::ParseError)
62
+ }.to raise_error(Yajl::ParseError)
63
63
  end
64
64
  end
@@ -14,25 +14,25 @@ describe "Chunked parser" do
14
14
  end
15
15
 
16
16
  it "should parse a single chunk" do
17
- @callback.should_receive(:call).with(@final)
17
+ expect(@callback).to receive(:call).with(@final)
18
18
  @parser << '[{"abc": 123},{"def": 456}]'
19
19
  end
20
20
 
21
21
  it "should parse a single chunk, 3 times" do
22
- @callback.should_receive(:call).with(@final).exactly(3).times
22
+ expect(@callback).to receive(:call).with(@final).exactly(3).times
23
23
  @parser << '[{"abc": 123},{"def": 456}]'
24
24
  @parser << '[{"abc": 123},{"def": 456}]'
25
25
  @parser << '[{"abc": 123},{"def": 456}]'
26
26
  end
27
27
 
28
28
  it "should parse in two chunks" do
29
- @callback.should_receive(:call).with(@final)
29
+ expect(@callback).to receive(:call).with(@final)
30
30
  @parser << '[{"abc": 123},'
31
31
  @parser << '{"def": 456}]'
32
32
  end
33
33
 
34
34
  it "should parse in 2 chunks, twice" do
35
- @callback.should_receive(:call).with(@final).exactly(2).times
35
+ expect(@callback).to receive(:call).with(@final).exactly(2).times
36
36
  @parser << '[{"abc": 123},'
37
37
  @parser << '{"def": 456}]'
38
38
  @parser << '[{"abc": 123},'
@@ -40,57 +40,57 @@ describe "Chunked parser" do
40
40
  end
41
41
 
42
42
  it "should parse 2 JSON strings, in 3 chunks" do
43
- @callback.should_receive(:call).with(@final).exactly(2).times
43
+ expect(@callback).to receive(:call).with(@final).exactly(2).times
44
44
  @parser << '[{"abc": 123},'
45
45
  @parser << '{"def": 456}][{"abc": 123},{"def":'
46
46
  @parser << ' 456}]'
47
47
  end
48
48
 
49
49
  it "should parse 2 JSON strings in 1 chunk" do
50
- @callback.should_receive(:call).with(@final).exactly(2).times
50
+ expect(@callback).to receive(:call).with(@final).exactly(2).times
51
51
  @parser << '[{"abc": 123},{"def": 456}][{"abc": 123},{"def": 456}]'
52
52
  end
53
53
 
54
54
  it "should parse 2 JSON strings from an IO" do
55
- @callback.should_receive(:call).with(@final).exactly(2).times
55
+ expect(@callback).to receive(:call).with(@final).exactly(2).times
56
56
  @parser.parse(StringIO.new('[{"abc": 123},{"def": 456}][{"abc": 123},{"def": 456}]'))
57
57
  end
58
58
 
59
59
  it "should parse a JSON string an IO and fire callback once" do
60
- @callback.should_receive(:call).with(@final)
60
+ expect(@callback).to receive(:call).with(@final)
61
61
  @parser.parse(StringIO.new('[{"abc": 123},{"def": 456}]'))
62
62
  end
63
63
 
64
64
  it "should parse twitter_stream.json and fire callback 430 times" do
65
65
  path = File.expand_path(File.dirname(__FILE__) + '/../../benchmark/subjects/twitter_stream.json')
66
66
  json = File.new(path, 'r')
67
- @callback.should_receive(:call).exactly(430).times
68
- lambda {
67
+ expect(@callback).to receive(:call).exactly(430).times
68
+ expect {
69
69
  @parser.parse(json)
70
- }.should_not raise_error
70
+ }.not_to raise_error
71
71
  end
72
72
 
73
73
  it "should parse twitter_stream.json and fire callback 430 times, with a block as the callback" do
74
74
  path = File.expand_path(File.dirname(__FILE__) + '/../../benchmark/subjects/twitter_stream.json')
75
75
  json = File.new(path, 'r')
76
- @callback.should_receive(:call).exactly(0).times
76
+ expect(@callback).to receive(:call).exactly(0).times
77
77
  @parser.on_parse_complete = nil
78
- lambda {
78
+ expect {
79
79
  times = 0
80
80
  @parser.parse(json) do |hsh|
81
81
  times += 1
82
82
  end
83
- times.should eql(430)
84
- }.should_not raise_error
83
+ expect(times).to eql(430)
84
+ }.not_to raise_error
85
85
  end
86
86
 
87
87
  it "should raise a Yajl::ParseError error if multiple JSON strings were found when no on_parse_complete callback assigned" do
88
88
  path = File.expand_path(File.dirname(__FILE__) + '/../../benchmark/subjects/twitter_stream.json')
89
89
  json = File.new(path, 'r')
90
90
  @parser.on_parse_complete = nil
91
- @callback.should_receive(:call).exactly(0).times
92
- lambda {
91
+ expect(@callback).to receive(:call).exactly(0).times
92
+ expect {
93
93
  @parser.parse(json)
94
- }.should raise_error(Yajl::ParseError)
94
+ }.to raise_error(Yajl::ParseError)
95
95
  end
96
96
  end
@@ -8,33 +8,33 @@ describe "Parsing JSON Fixtures" do
8
8
 
9
9
  FAILED.each do |name, source|
10
10
  it "should not be able to parse #{File.basename(name)} as an IO" do
11
- lambda {
11
+ expect {
12
12
  Yajl::Parser.parse(StringIO.new(source))
13
- }.should raise_error(Yajl::ParseError)
13
+ }.to raise_error(Yajl::ParseError)
14
14
  end
15
15
  end
16
16
 
17
17
  FAILED.each do |name, source|
18
18
  it "should not be able to parse #{File.basename(name)} as a string" do
19
- lambda {
19
+ expect {
20
20
  Yajl::Parser.parse(source)
21
- }.should raise_error(Yajl::ParseError)
21
+ }.to raise_error(Yajl::ParseError)
22
22
  end
23
23
  end
24
24
 
25
25
  PASSED.each do |name, source|
26
26
  it "should be able to parse #{File.basename(name)} as an IO" do
27
- lambda {
27
+ expect {
28
28
  Yajl::Parser.parse(StringIO.new(source))
29
- }.should_not raise_error
29
+ }.not_to raise_error
30
30
  end
31
31
  end
32
32
 
33
33
  PASSED.each do |name, source|
34
34
  it "should be able to parse #{File.basename(name)} as a string" do
35
- lambda {
35
+ expect {
36
36
  Yajl::Parser.parse(source)
37
- }.should_not raise_error
37
+ }.not_to raise_error
38
38
  end
39
39
  end
40
40
  end
@@ -40,7 +40,7 @@ describe 'Parsing very long text' do
40
40
 
41
41
  it 'runs successfully' do
42
42
  out, err, status = capture('ruby', script)
43
- [err, status.exitstatus].should eq(['', 0])
43
+ expect([err, status.exitstatus]).to eq(['', 0])
44
44
  end
45
45
  end
46
46