summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2015-07-09 08:39:40 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2015-07-09 08:39:40 -0700
commit8fabdd3fddbd222109976fddb0d38255a9490f1d (patch)
tree05c37181d228a244809572d16e3f2dfe2733fd90 /spec
parent6d427a893b28ee71ddcdbb3a6cd64cd01c7a690f (diff)
downloadffi-yajl-8fabdd3fddbd222109976fddb0d38255a9490f1d.tar.gz
fix lots of cops
and add a few more to be ignored
Diffstat (limited to 'spec')
-rw-r--r--spec/ffi_yajl/encoder_spec.rb41
-rw-r--r--spec/ffi_yajl/map_library_name_spec.rb2
-rw-r--r--spec/ffi_yajl/parser_spec.rb66
-rw-r--r--spec/spec_helper.rb3
4 files changed, 53 insertions, 59 deletions
diff --git a/spec/ffi_yajl/encoder_spec.rb b/spec/ffi_yajl/encoder_spec.rb
index acd7fcf..d8ee707 100644
--- a/spec/ffi_yajl/encoder_spec.rb
+++ b/spec/ffi_yajl/encoder_spec.rb
@@ -25,18 +25,17 @@ require 'spec_helper'
require 'date'
describe "FFI_Yajl::Encoder" do
-
let(:options) { {} }
let(:encoder) { FFI_Yajl::Encoder.new(options) }
it "encodes hashes in keys as strings", :ruby_gte_193 => true do
- ruby = { {'a' => 'b'} => 2 }
+ ruby = { { 'a' => 'b' } => 2 }
expect(encoder.encode(ruby)).to eq('{"{\"a\"=>\"b\"}":2}')
end
it "encodes arrays in keys as strings", :ruby_gte_193 => true do
- ruby = { [0,1] => 2 }
+ ruby = { [0, 1] => 2 }
expect(encoder.encode(ruby)).to eq('{"[0, 1]":2}')
end
@@ -66,14 +65,14 @@ describe "FFI_Yajl::Encoder" do
end
it "encodes bignums in keys as strings" do
- ruby = { 12345678901234567890 => 2 }
+ ruby = { 12_345_678_901_234_567_890 => 2 }
expect(encoder.encode(ruby)).to eq('{"12345678901234567890":2}')
end
it "encodes objects in keys as strings" do
o = Object.new
ruby = { o => 2 }
- expect(encoder.encode(ruby)).to eq(%Q{{"#{o.to_s}":2}})
+ expect(encoder.encode(ruby)).to eq(%{{"#{o}":2}})
end
it "encodes an object in a key which has a #to_json method as strings" do
@@ -84,7 +83,7 @@ describe "FFI_Yajl::Encoder" do
end
o = Thing.new
ruby = { o => 2 }
- expect(encoder.encode(ruby)).to eq(%Q{{"#{o.to_s}":2}})
+ expect(encoder.encode(ruby)).to eq(%{{"#{o}":2}})
end
# XXX: 127 == YAJL_MAX_DEPTH hardcodedness, zero control for us, it isn't even a twiddleable #define
@@ -92,14 +91,14 @@ describe "FFI_Yajl::Encoder" do
root = []
a = root
127.times { |_| a << []; a = a[0] }
- expect{ encoder.encode(root) }.to raise_error(FFI_Yajl::EncodeError)
+ expect { encoder.encode(root) }.to raise_error(FFI_Yajl::EncodeError)
end
it "raises an exception for deeply nested hashes" do
root = {}
a = root
- 127.times {|_| a["a"] = {}; a = a["a"] }
- expect{ encoder.encode(root) }.to raise_error(FFI_Yajl::EncodeError)
+ 127.times { |_| a["a"] = {}; a = a["a"] }
+ expect { encoder.encode(root) }.to raise_error(FFI_Yajl::EncodeError)
end
it "encodes symbols in keys as strings" do
@@ -113,7 +112,7 @@ describe "FFI_Yajl::Encoder" do
end
it "can encode 32-bit unsigned ints" do
- ruby = { "gid"=>4294967294 }
+ ruby = { "gid" => 4_294_967_294 }
expect(encoder.encode(ruby)).to eq('{"gid":4294967294}')
end
@@ -128,7 +127,7 @@ describe "FFI_Yajl::Encoder" do
it "can encode Date objects" do
ruby = Date.parse('2001-02-03')
- expect(encoder.encode(ruby)).to eq( %q{"2001-02-03"} )
+ expect(encoder.encode(ruby)).to eq( '"2001-02-03"' )
end
it "can encode StringIOs" do
@@ -148,13 +147,13 @@ describe "FFI_Yajl::Encoder" do
it "encodes them correctly" do
ruby = Time.local(2001, 02, 02, 21, 05, 06)
- expect(encoder.encode(ruby)).to eq( %q{"2001-02-02 21:05:06 +0000"} )
+ expect(encoder.encode(ruby)).to eq( '"2001-02-02 21:05:06 +0000"' )
end
end
it "can encode DateTime objects" do
ruby = DateTime.parse('2001-02-03T04:05:06.1+07:00')
- expect(encoder.encode(ruby)).to eq( %q{"2001-02-03T04:05:06+07:00"} )
+ expect(encoder.encode(ruby)).to eq( '"2001-02-03T04:05:06+07:00"' )
end
describe "testing .to_json for Objects" do
@@ -176,25 +175,25 @@ describe "FFI_Yajl::Encoder" do
context "when encoding invalid utf-8" do
ruby = {
- "automatic"=>{
- "etc"=>{
- "passwd"=>{
- "root"=>{"dir"=>"/root", "gid"=>0, "uid"=>0, "shell"=>"/bin/sh", "gecos"=>"Elan Ruusam\xc3\xa4e"},
- "glen"=>{"dir"=>"/home/glen", "gid"=>500, "uid"=>500, "shell"=>"/bin/bash", "gecos"=>"Elan Ruusam\xE4e"},
- }
+ "automatic" => {
+ "etc" => {
+ "passwd" => {
+ "root" => { "dir" => "/root", "gid" => 0, "uid" => 0, "shell" => "/bin/sh", "gecos" => "Elan Ruusam\xc3\xa4e" },
+ "glen" => { "dir" => "/home/glen", "gid" => 500, "uid" => 500, "shell" => "/bin/bash", "gecos" => "Elan Ruusam\xE4e" },
+ },
},
},
}
it "raises an error on invalid json" do
- expect{ encoder.encode(ruby) }.to raise_error(FFI_Yajl::EncodeError, /Invalid UTF-8 string 'Elan Ruusam.e': cannot encode to UTF-8/)
+ expect { encoder.encode(ruby) }.to raise_error(FFI_Yajl::EncodeError, /Invalid UTF-8 string 'Elan Ruusam.e': cannot encode to UTF-8/)
end
context "when validate_utf8 is off" do
let(:options) { { :validate_utf8 => false } }
it "does not raise an error" do
- expect{ encoder.encode(ruby) }.not_to raise_error
+ expect { encoder.encode(ruby) }.not_to raise_error
end
it "returns utf8" do
diff --git a/spec/ffi_yajl/map_library_name_spec.rb b/spec/ffi_yajl/map_library_name_spec.rb
index 4907d50..0b5e9cb 100644
--- a/spec/ffi_yajl/map_library_name_spec.rb
+++ b/spec/ffi_yajl/map_library_name_spec.rb
@@ -47,7 +47,6 @@ describe "FFI_Yajl::MapLibraryName" do
end
host_os_library_name_mapping.each do |host_os, library_names|
-
context "#library_names" do
it "maps #{host_os} correctly" do
allow(Test).to receive(:host_os).and_return(host_os)
@@ -112,6 +111,5 @@ describe "FFI_Yajl::MapLibraryName" do
Test.send(:ffi_open_yajl_library)
end
end
-
end
end
diff --git a/spec/ffi_yajl/parser_spec.rb b/spec/ffi_yajl/parser_spec.rb
index ed6ef2a..968e0ee 100644
--- a/spec/ffi_yajl/parser_spec.rb
+++ b/spec/ffi_yajl/parser_spec.rb
@@ -24,21 +24,20 @@
require 'spec_helper'
describe "FFI_Yajl::Parser" do
-
shared_examples_for "correct json parsing" do
context "when json has 23456789012E666" do
let(:json) { '{"key": 23456789012E666}' }
it "should return infinity" do
- infinity = (1.0/0)
- expect(parser).to eq({"key" => infinity})
+ infinity = (1.0 / 0)
+ expect(parser).to eq("key" => infinity)
end
end
context "when parsing nil" do
let(:json) { nil }
it "should not coredump ruby" do
- expect{ parser }.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
end
@@ -91,7 +90,7 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :allow_comments => false } }
it "should not parse" do
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
end
@@ -99,27 +98,27 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :allow_comments => true } }
it "should parse" do
- expect(parser).to eq({"key"=>"value"})
+ expect(parser).to eq("key" => "value")
end
end
context "by default" do
- let(:options) { }
+ let(:options) {}
it "should parse" do
- expect(parser).to eq({"key"=>"value"})
+ expect(parser).to eq("key" => "value")
end
end
end
context "when json has multiline comments" do
- let(:json) { %Q{{"key": \n/*\n this is a multiline comment \n*/\n "value"}} }
+ let(:json) { %{{"key": \n/*\n this is a multiline comment \n*/\n "value"}} }
context "when allow_comments is false" do
let(:options) { { :allow_comments => false } }
it "should not parse" do
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
end
@@ -127,19 +126,19 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :allow_comments => true } }
it "should parse" do
- expect(parser).to eq({"key"=>"value"})
+ expect(parser).to eq("key" => "value")
end
end
end
context "when json has inline comments" do
- let(:json) { %Q{{"key": \n// this is an inline comment\n "value"}} }
+ let(:json) { %{{"key": \n// this is an inline comment\n "value"}} }
context "when allow_comments is false" do
let(:options) { { :allow_comments => false } }
it "should not parse" do
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
end
@@ -147,7 +146,7 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :allow_comments => true } }
it "should parse" do
- expect(parser).to eq({"key"=>"value"})
+ expect(parser).to eq("key" => "value")
end
end
end
@@ -156,7 +155,7 @@ describe "FFI_Yajl::Parser" do
let(:json) { "[\"#{"\201\203"}\"]" }
it "should not parse by default" do
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
context "when :dont_validate_strings is set to true" do
@@ -171,7 +170,7 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :dont_validate_strings => false } }
it "should not parse" do
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
end
@@ -179,14 +178,14 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :check_utf8 => true } }
it "should not parse" do
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
context "when :dont_validate_strings is set to true" do
let(:options) { { :check_utf8 => true, :dont_validate_strings => true } }
it "should raise an ArgumentError" do
- expect{parser}.to raise_error(ArgumentError)
+ expect { parser }.to raise_error(ArgumentError)
end
end
@@ -194,7 +193,7 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :check_utf8 => true, :dont_validate_strings => false } }
it "should not parse" do
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
end
end
@@ -218,7 +217,7 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :check_utf8 => false, :dont_validate_strings => false } }
it "should raise an ArgumentError" do
- expect{parser}.to raise_error(ArgumentError)
+ expect { parser }.to raise_error(ArgumentError)
end
end
end
@@ -228,7 +227,7 @@ describe "FFI_Yajl::Parser" do
let(:json) { StringIO.new('{"key": 1234}') }
it "should parse" do
- expect(parser).to eq({"key" => 1234})
+ expect(parser).to eq("key" => 1234)
end
end
@@ -236,14 +235,14 @@ describe "FFI_Yajl::Parser" do
let(:json) { '{"key": 1234}' }
it "should parse correctly" do
- expect(parser).to eq({"key" => 1234})
+ expect(parser).to eq("key" => 1234)
end
context "when symbolize_keys is true" do
let(:options) { { :symbolize_keys => true } }
it "should symbolize keys correctly" do
- expect(parser).to eq({:key => 1234})
+ expect(parser).to eq(:key => 1234)
end
end
@@ -254,7 +253,7 @@ describe "FFI_Yajl::Parser" do
parser do |obj|
output = obj
end
- expect(output).to eq({"key" => 1234})
+ expect(output).to eq("key" => 1234)
end
end
end
@@ -305,14 +304,14 @@ describe "FFI_Yajl::Parser" do
let(:json) { '{"日本語": 1234}' }
it "should parse correctly" do
- expect(parser).to eq({"日本語" => 1234})
+ expect(parser).to eq("日本語" => 1234)
end
context "when symbolize_keys is true" do
let(:options) { { :symbolize_keys => true } }
it "should symbolize keys correctly" do
- expect(parser).to eq({:"日本語" => 1234})
+ expect(parser).to eq(:"日本語" => 1234)
end
if RUBY_VERSION.to_f >= 1.9
@@ -327,7 +326,7 @@ describe "FFI_Yajl::Parser" do
let(:json) { "{\"id\": 2147483649}" }
it "should parse corectly" do
- expect(parser).to eql({"id" => 2147483649})
+ expect(parser).to eql("id" => 2_147_483_649)
end
end
@@ -335,7 +334,7 @@ describe "FFI_Yajl::Parser" do
let(:json) { "{\"id\": 5687389800}" }
it "should parse corectly" do
- expect(parser).to eql({"id" => 5687389800})
+ expect(parser).to eql("id" => 5_687_389_800)
end
end
@@ -343,7 +342,7 @@ describe "FFI_Yajl::Parser" do
let(:json) { "{\"id\": 1046289770033519442869495707521600000000}" }
it "should parse corectly" do
- expect(parser).to eql({"id" => 1046289770033519442869495707521600000000})
+ expect(parser).to eql("id" => 1_046_289_770_033_519_442_869_495_707_521_600_000_000)
end
end
@@ -385,10 +384,9 @@ describe "FFI_Yajl::Parser" do
context "with allow_trailing_garbage" do
let(:options) { { :allow_trailing_garbage => true } }
it "parses" do
- expect(parser).to eq({"foo"=>{"foo"=>1234}})
+ expect(parser).to eq("foo" => { "foo" => 1234 })
end
end
-
end
context "when an extra bracket is present" do
@@ -480,7 +478,7 @@ describe "FFI_Yajl::Parser" do
let(:json) { '[0.' + '1' * 2**23 + ']' }
it "parses" do
- expect{ parser }.not_to raise_error
+ expect { parser }.not_to raise_error
end
end
@@ -489,7 +487,7 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :symbolize_keys => true } }
it "parses" do
- expect{ parser }.not_to raise_error
+ expect { parser }.not_to raise_error
end
end
@@ -504,7 +502,7 @@ describe "FFI_Yajl::Parser" do
let(:json) { '{"foo":"bar","foo":"baz"}' }
let(:options) { { :unique_key_checking => true } }
it "should raise" do
- expect{ parser }.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 03af269..147e124 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -20,7 +20,7 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-$: << File.expand_path(File.join(File.dirname( __FILE__ ), "../lib"))
+$LOAD_PATH << File.expand_path(File.join(File.dirname( __FILE__ ), "../lib"))
# load yajl-ruby into the same process (tests that both c-libs can be
# linked in the same process). this should work, see:
@@ -42,5 +42,4 @@ RSpec.configure do |c|
c.expect_with :rspec do |c|
c.syntax = :expect
end
-
end