summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2015-07-09 10:40:37 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2015-07-09 10:40:37 -0700
commit8563dd4bb03a12bc41a7bf9b3e1ab4865a2a0110 (patch)
tree3548b0d9446ae45e68894129330c090172c1bffa
parent6d427a893b28ee71ddcdbb3a6cd64cd01c7a690f (diff)
parentba9c90591239f0dbc082df70d9785e082a737e29 (diff)
downloadffi-yajl-8563dd4bb03a12bc41a7bf9b3e1ab4865a2a0110.tar.gz
Merge pull request #66 from chef/lcg/rubocop
Lcg/rubocop
-rw-r--r--.rubocop.yml22
-rw-r--r--Gemfile2
-rw-r--r--Rakefile13
-rwxr-xr-xbin/ffi-yajl-bench9
-rw-r--r--ext/ffi_yajl/ext/encoder/extconf.rb3
-rw-r--r--ext/ffi_yajl/ext/parser/extconf.rb3
-rw-r--r--ffi-yajl-universal-java.gemspec2
-rw-r--r--ffi-yajl.gemspec2
-rw-r--r--lib/ffi_yajl/benchmark.rb1
-rw-r--r--lib/ffi_yajl/benchmark/encode.rb19
-rw-r--r--lib/ffi_yajl/benchmark/encode_profile.rb2
-rw-r--r--lib/ffi_yajl/benchmark/http.rb4
-rw-r--r--lib/ffi_yajl/benchmark/parse.rb23
-rw-r--r--lib/ffi_yajl/benchmark/parse_json_and_marshal.rb4
-rw-r--r--lib/ffi_yajl/benchmark/parse_json_and_yaml.rb4
-rw-r--r--lib/ffi_yajl/benchmark/parse_profile.rb2
-rw-r--r--lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb2
-rw-r--r--lib/ffi_yajl/benchmark/parse_stream.rb4
-rw-r--r--lib/ffi_yajl/encoder.rb2
-rw-r--r--lib/ffi_yajl/ffi.rb47
-rw-r--r--lib/ffi_yajl/ffi/encoder.rb45
-rw-r--r--lib/ffi_yajl/ffi/parser.rb57
-rw-r--r--lib/ffi_yajl/map_library_name.rb1
-rw-r--r--lib/ffi_yajl/parser.rb8
-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
28 files changed, 191 insertions, 202 deletions
diff --git a/.rubocop.yml b/.rubocop.yml
index 3d62982..170fc40 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -1,9 +1,15 @@
+AbcSize:
+ Enabled: false
AndOr:
Enabled: false
+ClassAndModuleCamelCase:
+ Enabled: false
ClassLength:
Enabled: false
CommentAnnotation:
Enabled: false
+CyclomaticComplexity:
+ Enabled: false
Documentation:
Enabled: false
DoubleNegation:
@@ -20,8 +26,18 @@ LineLength:
Enabled: false
MethodLength:
Enabled: false
-PercentLiteralDelimiters:
+ModuleLength:
Enabled: false
+PerceivedComplexity:
+ Enabled: false
+PercentLiteralDelimiters:
+ PreferredDelimiters:
+ '%': '{}'
+ '%q': '{}'
+ '%Q': '{}'
+ '%w': '{}'
+ '%W': '{}'
+ '%x': '{}'
RegexpLiteral:
Enabled: false
SignalException:
@@ -36,3 +52,7 @@ StringLiterals:
Enabled: false
TrailingComma:
EnforcedStyleForMultiline: comma
+UnusedMethodArgument:
+ Enabled: false
+UnusedBlockArgument:
+ Enabled: false
diff --git a/Gemfile b/Gemfile
index 34b35ca..3298262 100644
--- a/Gemfile
+++ b/Gemfile
@@ -12,7 +12,7 @@ group :development do
end
group :development_extras do
- gem 'rubocop', '= 0.21.0'
+ gem 'rubocop', '= 0.32.1'
gem 'reek', '= 1.3.7'
gem 'test-kitchen', '~> 1.2'
gem 'kitchen-digitalocean'
diff --git a/Rakefile b/Rakefile
index ae19344..e70a915 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,11 +1,11 @@
-$: << File.expand_path(File.join(File.dirname( __FILE__ ), "lib"))
+$LOAD_PATH << File.expand_path(File.join(File.dirname( __FILE__ ), "lib"))
require 'rspec/core/rake_task'
require 'rubygems/package_task'
require 'rake/extensiontask'
require 'ffi_yajl/version'
-Dir[File.expand_path("../*gemspec", __FILE__)].reverse.each do |gemspec_path|
+Dir[File.expand_path("../*gemspec", __FILE__)].reverse_each do |gemspec_path|
gemspec = eval(IO.read(gemspec_path))
Gem::PackageTask.new(gemspec).define
end
@@ -14,7 +14,7 @@ desc "Build it and ship it"
task :ship => [:clean, :gem] do
sh("git tag #{FFI_Yajl::VERSION}")
sh("git push --tags")
- Dir[File.expand_path("../pkg/*.gem", __FILE__)].reverse.each do |built_gem|
+ Dir[File.expand_path("../pkg/*.gem", __FILE__)].reverse_each do |built_gem|
sh("gem push #{built_gem}")
end
end
@@ -123,7 +123,7 @@ if RUBY_VERSION.to_f >= 1.9
puts "rubocop gem is not installed"
end
else
- Rubocop::RakeTask.new(:rubocop) do |t|
+ RuboCop::RakeTask.new(:rubocop) do |t|
t.fail_on_error = false
end
end
@@ -138,7 +138,7 @@ if RUBY_VERSION.to_f >= 1.9
else
Reek::Rake::Task.new(:reek) do |t|
t.fail_on_error = false
-# t.config_files = '.reek.yml'
+ # t.config_files = '.reek.yml'
end
end
end
@@ -161,12 +161,11 @@ else
end
end
-
desc 'Run all style checks'
task :style => ['style:rubocop', 'style:reek']
desc 'Run style + spec tests by default on travis'
-task :travis => ['style', 'spec']
+task :travis => %w{style spec}
desc 'Run style, spec and test kichen on travis'
task :travis_all => ['style', 'spec', 'integration:cloud']
diff --git a/bin/ffi-yajl-bench b/bin/ffi-yajl-bench
index 5b3bf85..ceff62b 100755
--- a/bin/ffi-yajl-bench
+++ b/bin/ffi-yajl-bench
@@ -1,7 +1,6 @@
#!/usr/bin/env ruby
-
-$: << File.expand_path(File.join(File.dirname( File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__ ), "../lib"))
+$LOAD_PATH << File.expand_path(File.join(File.dirname( File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__ ), "../lib"))
require 'optparse'
require 'ffi_yajl/benchmark'
@@ -30,8 +29,8 @@ ENV['FORCE_FFI_YAJL'] = 'ffi' if opts[:ffi]
ENV['FORCE_FFI_YAJL'] = 'ext' if opts[:ext]
if opts[:profile]
- FFI_Yajl::Benchmark::ParseProfileRubyProf.new().run()
+ FFI_Yajl::Benchmark::ParseProfileRubyProf.new.run
else
- FFI_Yajl::Benchmark::Parse.new().run()
- FFI_Yajl::Benchmark::Encode.new().run()
+ FFI_Yajl::Benchmark::Parse.new.run
+ FFI_Yajl::Benchmark::Encode.new.run
end
diff --git a/ext/ffi_yajl/ext/encoder/extconf.rb b/ext/ffi_yajl/ext/encoder/extconf.rb
index f7f0116..e46080a 100644
--- a/ext/ffi_yajl/ext/encoder/extconf.rb
+++ b/ext/ffi_yajl/ext/encoder/extconf.rb
@@ -1,3 +1,4 @@
+# rubocop:disable Style/GlobalVars
require 'mkmf'
require 'rubygems'
require 'libyajl2'
@@ -54,7 +55,7 @@ if !windows? && !find_header('yajl/yajl_tree.h')
dir_config('yajl', HEADER_DIRS, LIB_DIRS)
# here we use find_library in order to deliberately link with -lyajl as a useful side-effect
- if !(find_header('yajl/yajl_tree.h') && find_library('yajl', 'yajl_complete_parse'))
+ unless find_header('yajl/yajl_tree.h') && find_library('yajl', 'yajl_complete_parse')
abort "libyajl2 is missing. please install libyajl2"
end
end
diff --git a/ext/ffi_yajl/ext/parser/extconf.rb b/ext/ffi_yajl/ext/parser/extconf.rb
index 0b13bca..6f8526e 100644
--- a/ext/ffi_yajl/ext/parser/extconf.rb
+++ b/ext/ffi_yajl/ext/parser/extconf.rb
@@ -1,3 +1,4 @@
+# rubocop:disable Style/GlobalVars
require 'mkmf'
require 'rubygems'
require 'libyajl2'
@@ -54,7 +55,7 @@ if !windows? && !find_header('yajl/yajl_tree.h')
dir_config('yajl', HEADER_DIRS, LIB_DIRS)
# here we use find_library in order to deliberately link with -lyajl as a useful side-effect
- if !(find_header('yajl/yajl_tree.h') && find_library('yajl', 'yajl_complete_parse'))
+ unless find_header('yajl/yajl_tree.h') && find_library('yajl', 'yajl_complete_parse')
abort "libyajl2 is missing. please install libyajl2"
end
end
diff --git a/ffi-yajl-universal-java.gemspec b/ffi-yajl-universal-java.gemspec
index 4df0326..9e8f670 100644
--- a/ffi-yajl-universal-java.gemspec
+++ b/ffi-yajl-universal-java.gemspec
@@ -4,7 +4,7 @@ gemspec.platform = "universal-java"
# XXX: after the libyajl2-gem, we don't need to fork the
# extensions so can we simplify the gemspecs now?
-#gemspec.extensions = %w{ ext/libyajl2/extconf.rb }
+# gemspec.extensions = %w{ ext/libyajl2/extconf.rb }
gemspec.add_runtime_dependency "ffi", "~> 1.5"
diff --git a/ffi-yajl.gemspec b/ffi-yajl.gemspec
index 03086fd..83af1f6 100644
--- a/ffi-yajl.gemspec
+++ b/ffi-yajl.gemspec
@@ -1,7 +1,7 @@
gemspec = eval(IO.read(File.expand_path(File.join(File.dirname(__FILE__), "ffi-yajl.gemspec.shared"))))
gemspec.platform = Gem::Platform::RUBY
-gemspec.extensions = %w{ ext/ffi_yajl/ext/encoder/extconf.rb ext/ffi_yajl/ext/parser/extconf.rb ext/ffi_yajl/ext/dlopen/extconf.rb }
+gemspec.extensions = %w{ext/ffi_yajl/ext/encoder/extconf.rb ext/ffi_yajl/ext/parser/extconf.rb ext/ffi_yajl/ext/dlopen/extconf.rb}
gemspec.add_development_dependency "ffi", "~> 1.5"
diff --git a/lib/ffi_yajl/benchmark.rb b/lib/ffi_yajl/benchmark.rb
index 6d50c0f..e8944ca 100644
--- a/lib/ffi_yajl/benchmark.rb
+++ b/lib/ffi_yajl/benchmark.rb
@@ -25,4 +25,3 @@ require 'ffi_yajl/benchmark/encode_profile.rb'
require 'ffi_yajl/benchmark/parse.rb'
require 'ffi_yajl/benchmark/parse_profile.rb'
require 'ffi_yajl/benchmark/parse_profile_ruby_prof.rb'
-
diff --git a/lib/ffi_yajl/benchmark/encode.rb b/lib/ffi_yajl/benchmark/encode.rb
index d3f969c..eda4fe7 100644
--- a/lib/ffi_yajl/benchmark/encode.rb
+++ b/lib/ffi_yajl/benchmark/encode.rb
@@ -42,16 +42,14 @@ end
module FFI_Yajl
class Benchmark
class Encode
-
def run
- #filename = ARGV[0] || 'benchmark/subjects/ohai.json'
+ # filename = ARGV[0] || 'benchmark/subjects/ohai.json'
filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json"))
hash = File.open(filename, 'rb') { |f| FFI_Yajl::Parser.parse(f.read) }
times = ARGV[1] ? ARGV[1].to_i : 1000
puts "Starting benchmark encoding #{filename} #{times} times\n\n"
::Benchmark.bmbm { |x|
-
x.report("FFI_Yajl::Encoder.encode (to a String)") {
times.times {
output = FFI_Yajl::Encoder.encode(hash)
@@ -125,16 +123,15 @@ module FFI_Yajl
}
end
end
-# if defined?(ActiveSupport::JSON)
-# x.report("ActiveSupport::JSON.encode") {
-# times.times {
-# ActiveSupport::JSON.encode(hash)
-# }
-# }
-# end
+ # if defined?(ActiveSupport::JSON)
+ # x.report("ActiveSupport::JSON.encode") {
+ # times.times {
+ # ActiveSupport::JSON.encode(hash)
+ # }
+ # }
+ # end
}
end
end
end
-
end
diff --git a/lib/ffi_yajl/benchmark/encode_profile.rb b/lib/ffi_yajl/benchmark/encode_profile.rb
index ce98a3c..f7ac7c2 100644
--- a/lib/ffi_yajl/benchmark/encode_profile.rb
+++ b/lib/ffi_yajl/benchmark/encode_profile.rb
@@ -14,7 +14,6 @@ ENV['CPUPROFILE_FREQUENCY'] = "4000"
module FFI_Yajl
class Benchmark
class EncodeProfile
-
def run
if defined?(PerfTools)
filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json"))
@@ -32,7 +31,6 @@ module FFI_Yajl
system("pprof.rb --text /tmp/ffi_yajl_encode_profile.out")
end
end
-
end
end
end
diff --git a/lib/ffi_yajl/benchmark/http.rb b/lib/ffi_yajl/benchmark/http.rb
index 551c987..4c61df5 100644
--- a/lib/ffi_yajl/benchmark/http.rb
+++ b/lib/ffi_yajl/benchmark/http.rb
@@ -15,7 +15,7 @@ uri = URI.parse('http://search.twitter.com/search.json?q=github')
# uri = URI.parse('http://localhost/yajl-ruby.git/benchmark/subjects/contacts.json')
times = ARGV[0] ? ARGV[0].to_i : 1
-puts "Starting benchmark parsing #{uri.to_s} #{times} times\n\n"
+puts "Starting benchmark parsing #{uri} #{times} times\n\n"
Benchmark.bmbm { |x|
x.report {
puts "Yajl::HttpStream.get"
@@ -29,4 +29,4 @@ Benchmark.bmbm { |x|
JSON.parse(Net::HTTP.get_response(uri).body, :max_nesting => false)
}
}
-} \ No newline at end of file
+}
diff --git a/lib/ffi_yajl/benchmark/parse.rb b/lib/ffi_yajl/benchmark/parse.rb
index 02ad740..7e1f3a6 100644
--- a/lib/ffi_yajl/benchmark/parse.rb
+++ b/lib/ffi_yajl/benchmark/parse.rb
@@ -34,7 +34,6 @@ rescue LoadError
end
class FFI_Yajl::Benchmark::Parse
-
def run
filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "item.json"))
json = File.new(filename, 'r')
@@ -49,14 +48,14 @@ class FFI_Yajl::Benchmark::Parse
FFI_Yajl::Parser.parse(json_str)
}
}
-# ffi_parser = FFI_Yajl::Parser.new
-# x.report {
-# puts "FFI_Yajl::Parser#parse (from a String)"
-# times.times {
-# json.rewind
-# ffi_parser.parse(json.read)
-# }
-# }
+ # ffi_parser = FFI_Yajl::Parser.new
+ # x.report {
+ # puts "FFI_Yajl::Parser#parse (from a String)"
+ # times.times {
+ # json.rewind
+ # ffi_parser.parse(json.read)
+ # }
+ # }
if defined?(Yajl::Parser)
x.report {
puts "Yajl::Parser.parse (from a String)"
@@ -65,7 +64,7 @@ class FFI_Yajl::Benchmark::Parse
}
}
io_parser = Yajl::Parser.new
- io_parser.on_parse_complete = lambda {|obj|} if times > 1
+ io_parser.on_parse_complete = lambda { |obj| } if times > 1
x.report {
puts "Yajl::Parser#parse (from an IO)"
times.times {
@@ -74,7 +73,7 @@ class FFI_Yajl::Benchmark::Parse
}
}
string_parser = Yajl::Parser.new
- string_parser.on_parse_complete = lambda {|obj|} if times > 1
+ string_parser.on_parse_complete = lambda { |obj| } if times > 1
x.report {
puts "Yajl::Parser#parse (from a String)"
times.times {
@@ -140,7 +139,5 @@ class FFI_Yajl::Benchmark::Parse
end
}
json.close
-
end
end
-
diff --git a/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb b/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
index 06fe70b..163f559 100644
--- a/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
+++ b/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb
@@ -23,7 +23,7 @@ Benchmark.bmbm { |x|
x.report {
puts "Yajl::Parser#parse"
yajl = Yajl::Parser.new
- yajl.on_parse_complete = lambda {|obj|} if times > 1
+ yajl.on_parse_complete = lambda { |obj| } if times > 1
times.times {
json.rewind
hash = yajl.parse(json)
@@ -47,4 +47,4 @@ Benchmark.bmbm { |x|
}
}
json.close
-marshal_file.close \ No newline at end of file
+marshal_file.close
diff --git a/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb b/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb
index 0cc509a..4e96e02 100644
--- a/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb
+++ b/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb
@@ -18,7 +18,7 @@ times = ARGV[0] ? ARGV[0].to_i : 1000
puts "Starting benchmark parsing #{File.size(filename)} bytes of JSON data #{times} times\n\n"
Benchmark.bmbm { |x|
parser = Yajl::Parser.new
- parser.on_parse_complete = lambda {|obj|} if times > 1
+ parser.on_parse_complete = lambda { |obj| } if times > 1
x.report {
puts "Yajl::Parser#parse"
times.times {
@@ -52,4 +52,4 @@ Benchmark.bmbm { |x|
}
}
}
-yaml.close \ No newline at end of file
+yaml.close
diff --git a/lib/ffi_yajl/benchmark/parse_profile.rb b/lib/ffi_yajl/benchmark/parse_profile.rb
index 5efb1e2..39343bc 100644
--- a/lib/ffi_yajl/benchmark/parse_profile.rb
+++ b/lib/ffi_yajl/benchmark/parse_profile.rb
@@ -14,7 +14,6 @@ ENV['CPUPROFILE_FREQUENCY'] = "4000"
module FFI_Yajl
class Benchmark
class ParseProfile
-
def run
if defined?(PerfTools)
filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json"))
@@ -31,7 +30,6 @@ module FFI_Yajl
system("pprof.rb --text /tmp/ffi_yajl_encode_profile.out")
end
end
-
end
end
end
diff --git a/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb b/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb
index 5b9f73e..8d9dd5d 100644
--- a/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb
+++ b/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb
@@ -7,7 +7,6 @@ require 'ffi_yajl'
module FFI_Yajl
class Benchmark
class ParseProfileRubyProf
-
def run
begin
require 'ruby-prof'
@@ -33,7 +32,6 @@ module FFI_Yajl
end
end
-
end
end
end
diff --git a/lib/ffi_yajl/benchmark/parse_stream.rb b/lib/ffi_yajl/benchmark/parse_stream.rb
index 94c5ac3..955f22f 100644
--- a/lib/ffi_yajl/benchmark/parse_stream.rb
+++ b/lib/ffi_yajl/benchmark/parse_stream.rb
@@ -20,7 +20,7 @@ times = ARGV[0] ? ARGV[0].to_i : 100
puts "Starting benchmark parsing JSON stream (#{File.size(filename)} bytes of JSON data with 430 JSON separate strings) #{times} times\n\n"
Benchmark.bmbm { |x|
parser = Yajl::Parser.new
- parser.on_parse_complete = lambda {|obj|}
+ parser.on_parse_complete = lambda { |obj| }
x.report {
puts "Yajl::Parser#parse"
times.times {
@@ -51,4 +51,4 @@ Benchmark.bmbm { |x|
}
end
}
-json.close \ No newline at end of file
+json.close
diff --git a/lib/ffi_yajl/encoder.rb b/lib/ffi_yajl/encoder.rb
index a678221..9f2e564 100644
--- a/lib/ffi_yajl/encoder.rb
+++ b/lib/ffi_yajl/encoder.rb
@@ -54,7 +54,7 @@ module FFI_Yajl
@opts ||= {}
end
- def self.raise_error_for_status(status, token=nil)
+ def self.raise_error_for_status(status, token = nil)
# scrub token to valid utf-8 since we may be issuing an exception on an invalid utf-8 token
token = token.to_s.encode("utf-8", "binary", :undef => :replace)
case status
diff --git a/lib/ffi_yajl/ffi.rb b/lib/ffi_yajl/ffi.rb
index c56ea10..3b83bae 100644
--- a/lib/ffi_yajl/ffi.rb
+++ b/lib/ffi_yajl/ffi.rb
@@ -42,16 +42,16 @@ module FFI_Yajl
class YajlCallbacks < ::FFI::Struct
layout :yajl_null, :pointer,
- :yajl_boolean, :pointer,
- :yajl_integer, :pointer,
- :yajl_double, :pointer,
- :yajl_number, :pointer,
- :yajl_string, :pointer,
- :yajl_start_map, :pointer,
- :yajl_map_key, :pointer,
- :yajl_end_map, :pointer,
- :yajl_start_array, :pointer,
- :yajl_end_array, :pointer
+ :yajl_boolean, :pointer,
+ :yajl_integer, :pointer,
+ :yajl_double, :pointer,
+ :yajl_number, :pointer,
+ :yajl_string, :pointer,
+ :yajl_start_map, :pointer,
+ :yajl_map_key, :pointer,
+ :yajl_end_map, :pointer,
+ :yajl_start_array, :pointer,
+ :yajl_end_array, :pointer
end
enum :yajl_status, [
@@ -61,30 +61,30 @@ module FFI_Yajl
:yajl_status_error,
]
-# FFI::Enums are slow, should remove the rest
-# enum :yajl_gen_status, [
-# :yajl_gen_status_ok,
-# :yajl_gen_keys_must_be_strings,
-# :yajl_max_depth_exceeded,
-# :yajl_gen_in_error_state,
-# :yajl_gen_generation_complete,
-# :yajl_gen_invalid_number,
-# :yajl_gen_no_buf,
-# ]
+ # FFI::Enums are slow, should remove the rest
+ # enum :yajl_gen_status, [
+ # :yajl_gen_status_ok,
+ # :yajl_gen_keys_must_be_strings,
+ # :yajl_max_depth_exceeded,
+ # :yajl_gen_in_error_state,
+ # :yajl_gen_generation_complete,
+ # :yajl_gen_invalid_number,
+ # :yajl_gen_no_buf,
+ # ]
enum :yajl_option, [
:yajl_allow_comments, 0x01,
:yajl_dont_validate_strings, 0x02,
:yajl_allow_trailing_garbage, 0x04,
:yajl_allow_multiple_values, 0x08,
- :yajl_allow_partial_values, 0x10,
+ :yajl_allow_partial_values, 0x10
]
enum :yajl_gen_option, [
:yajl_gen_beautify, 0x01,
:yajl_gen_indent_string, 0x02,
:yajl_gen_print_callback, 0x04,
- :yajl_gen_validate_utf8, 0x08,
+ :yajl_gen_validate_utf8, 0x08
]
typedef :pointer, :yajl_handle
@@ -132,10 +132,9 @@ module FFI_Yajl
attach_function :yajl_gen_array_open, [:yajl_gen], :int
attach_function :yajl_gen_array_close, [:yajl_gen], :int
# yajl_gen_status yajl_gen_get_buf (yajl_gen hand, const unsigned char **buf, unsigned int *len)
- attach_function :yajl_gen_get_buf, [:yajl_gen, :pointer ,:pointer], :int
+ attach_function :yajl_gen_get_buf, [:yajl_gen, :pointer, :pointer], :int
# void yajl_gen_clear (yajl_gen hand)
attach_function :yajl_gen_clear, [:yajl_gen], :void
-
end
require 'ffi_yajl/encoder'
diff --git a/lib/ffi_yajl/ffi/encoder.rb b/lib/ffi_yajl/ffi/encoder.rb
index 71b631e..250ed68 100644
--- a/lib/ffi_yajl/ffi/encoder.rb
+++ b/lib/ffi_yajl/ffi/encoder.rb
@@ -27,7 +27,7 @@ module FFI_Yajl
module FFI
module Encoder
def do_yajl_encode(obj, yajl_gen_opts, opts)
- yajl_gen = FFI_Yajl.yajl_gen_alloc(nil);
+ yajl_gen = FFI_Yajl.yajl_gen_alloc(nil)
# configure the yajl encoder
if yajl_gen_opts[:yajl_gen_beautify]
@@ -58,9 +58,8 @@ module FFI_Yajl
FFI_Yajl.yajl_gen_free(yajl_gen)
- return string
+ string
end
-
end
end
end
@@ -68,7 +67,7 @@ end
class Hash
def ffi_yajl(yajl_gen, state)
if state[:processing_key]
- str = self.to_s
+ str = to_s
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
@@ -76,7 +75,7 @@ class Hash
if ( status = FFI_Yajl.yajl_gen_map_open(yajl_gen) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, '{')
end
- self.each do |key, value|
+ each do |key, value|
# Perf Fix: mutate state hash rather than creating new copy
state[:processing_key] = true
key.ffi_yajl(yajl_gen, state)
@@ -93,7 +92,7 @@ end
class Array
def ffi_yajl(yajl_gen, state)
if state[:processing_key]
- str = self.to_s
+ str = to_s
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
@@ -101,7 +100,7 @@ class Array
if ( status = FFI_Yajl.yajl_gen_array_open(yajl_gen) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, '[')
end
- self.each do |value|
+ each do |value|
value.ffi_yajl(yajl_gen, state)
end
if ( status = FFI_Yajl.yajl_gen_array_close(yajl_gen) ) != 0
@@ -113,7 +112,7 @@ end
class NilClass
def ffi_yajl(yajl_gen, state)
- str = self.to_s
+ str = to_s
if state[:processing_key]
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
@@ -128,7 +127,7 @@ end
class TrueClass
def ffi_yajl(yajl_gen, state)
- str = self.to_s
+ str = to_s
if state[:processing_key]
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
@@ -143,7 +142,7 @@ end
class FalseClass
def ffi_yajl(yajl_gen, state)
- str = self.to_s
+ str = to_s
if state[:processing_key]
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
@@ -158,7 +157,7 @@ end
class Fixnum
def ffi_yajl(yajl_gen, state)
- str = self.to_s
+ str = to_s
if str == "NaN" || str == "Infinity" || str == "-Infinity"
raise ::FFI_Yajl::EncodeError.new("'#{str}' is an invalid number")
end
@@ -176,7 +175,7 @@ end
class Bignum
def ffi_yajl(yajl_gen, state)
- str = self.to_s
+ str = to_s
if str == "NaN" || str == "Infinity" || str == "-Infinity"
raise ::FFI_Yajl::EncodeError.new("'#{str}' is an invalid number")
end
@@ -194,7 +193,7 @@ end
class Float
def ffi_yajl(yajl_gen, state)
- str = self.to_s
+ str = to_s
if str == "NaN" || str == "Infinity" || str == "-Infinity"
raise ::FFI_Yajl::EncodeError.new("'#{str}' is an invalid number")
end
@@ -212,7 +211,7 @@ end
class Symbol
def ffi_yajl(yajl_gen, state)
- str = self.to_s
+ str = to_s
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
@@ -221,7 +220,7 @@ end
class String
def ffi_yajl(yajl_gen, state)
- if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, self, self.bytesize) ) != 0
+ if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, self, bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, self)
end
end
@@ -229,7 +228,7 @@ end
class StringIO
def ffi_yajl(yajl_gen, state)
- str = self.read
+ str = read
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
@@ -238,7 +237,7 @@ end
class Date
def ffi_yajl(yajl_gen, state)
- str = self.to_s
+ str = to_s
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
@@ -247,7 +246,7 @@ end
class Time
def ffi_yajl(yajl_gen, state)
- str = self.strftime "%Y-%m-%d %H:%M:%S %z"
+ str = strftime "%Y-%m-%d %H:%M:%S %z"
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
@@ -256,7 +255,7 @@ end
class DateTime
def ffi_yajl(yajl_gen, state)
- str = self.to_s
+ str = to_s
if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
FFI_Yajl::Encoder.raise_error_for_status(status, str)
end
@@ -267,15 +266,13 @@ end
class Object
def ffi_yajl(yajl_gen, state)
if !state[:processing_key] && self.respond_to?(:to_json)
- str = self.to_json(state[:json_opts])
+ str = to_json(state[:json_opts])
# #yajl_gen_number outputs a string without quotes around it
status = FFI_Yajl.yajl_gen_number(yajl_gen, str, str.bytesize)
else
- str = self.to_s
+ str = to_s
status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize)
end
- if ( status ) != 0
- FFI_Yajl::Encoder.raise_error_for_status(status, str)
- end
+ FFI_Yajl::Encoder.raise_error_for_status(status, str) if ( status ) != 0
end
end
diff --git a/lib/ffi_yajl/ffi/parser.rb b/lib/ffi_yajl/ffi/parser.rb
index 77d2389..e3226c0 100644
--- a/lib/ffi_yajl/ffi/parser.rb
+++ b/lib/ffi_yajl/ffi/parser.rb
@@ -23,36 +23,32 @@
module FFI_Yajl
module FFI
module Parser
-
- def set_value(val)
- case stack.last
- when Hash
- raise FFI_Yajl::ParseError.new("internal error: missing key in parse") if key.nil?
- if @opts[:unique_key_checking] && stack.last.has_key?(key)
- raise FFI_Yajl::ParseError.new("repeated key: #{key}")
- end
- stack.last[key] = val
- when Array
- stack.last.push(val)
- else
- stack.push(val)
- end
- end
-
- def stack_pop
- if stack.length > 1
- set_value( stack.pop )
+ def set_value(val)
+ case stack.last
+ when Hash
+ raise FFI_Yajl::ParseError.new("internal error: missing key in parse") if key.nil?
+ if @opts[:unique_key_checking] && stack.last.key?(key)
+ raise FFI_Yajl::ParseError.new("repeated key: #{key}")
end
+ stack.last[key] = val
+ when Array
+ stack.last.push(val)
+ else
+ stack.push(val)
end
+ end
- def key_push
- key_stack.push(key)
- end
+ def stack_pop
+ set_value( stack.pop ) if stack.length > 1
+ end
- def key_pop
- @key = key_stack.pop()
- end
+ def key_push
+ key_stack.push(key)
+ end
+ def key_pop
+ @key = key_stack.pop
+ end
def setup_callbacks
@null_callback = ::FFI::Function.new(:int, [:pointer]) do |ctx|
@@ -68,7 +64,7 @@ module FFI_Yajl
1
end
@number_callback = ::FFI::Function.new(:int, [:pointer, :string, :size_t ]) do |ctx, stringval, stringlen|
- s = stringval.slice(0,stringlen)
+ s = stringval.slice(0, stringlen)
s.force_encoding('UTF-8') if defined? Encoding
# XXX: I can't think of a better way to do this right now. need to call to_f if and only if its a float.
v = ( s =~ /[\.eE]/ ) ? s.to_f : s.to_i
@@ -80,18 +76,18 @@ module FFI_Yajl
1
end
@string_callback = ::FFI::Function.new(:int, [:pointer, :string, :size_t]) do |ctx, stringval, stringlen|
- s = stringval.slice(0,stringlen)
+ s = stringval.slice(0, stringlen)
s.force_encoding('UTF-8') if defined? Encoding
set_value(s)
1
end
@start_map_callback = ::FFI::Function.new(:int, [:pointer]) do |ctx|
key_push # for key => { } case, save the key
- stack.push(Hash.new)
+ stack.push({})
1
end
@map_key_callback = ::FFI::Function.new(:int, [:pointer, :string, :size_t]) do |ctx, key, keylen|
- s = key.slice(0,keylen)
+ s = key.slice(0, keylen)
s.force_encoding('UTF-8') if defined? Encoding
self.key = @opts[:symbolize_keys] ? s.to_sym : s
1
@@ -103,7 +99,7 @@ module FFI_Yajl
end
@start_array_callback = ::FFI::Function.new(:int, [:pointer]) do |ctx|
key_push # for key => [ ] case, save the key
- stack.push(Array.new)
+ stack.push([])
1
end
@end_array_callback = ::FFI::Function.new(:int, [:pointer]) do |ctx|
@@ -113,7 +109,6 @@ module FFI_Yajl
end
end
-
def do_yajl_parse(str, yajl_opts = {})
setup_callbacks
callback_ptr = ::FFI::MemoryPointer.new(::FFI_Yajl::YajlCallbacks)
diff --git a/lib/ffi_yajl/map_library_name.rb b/lib/ffi_yajl/map_library_name.rb
index 8723424..249116e 100644
--- a/lib/ffi_yajl/map_library_name.rb
+++ b/lib/ffi_yajl/map_library_name.rb
@@ -29,7 +29,6 @@ require 'libyajl2'
module FFI_Yajl
module MapLibraryName
-
private
# Stub for tests to override the host_os
diff --git a/lib/ffi_yajl/parser.rb b/lib/ffi_yajl/parser.rb
index 9008a3e..6029691 100644
--- a/lib/ffi_yajl/parser.rb
+++ b/lib/ffi_yajl/parser.rb
@@ -32,14 +32,14 @@ module FFI_Yajl
# stack used to build up our complex object
#
def stack
- @stack ||= Array.new
+ @stack ||= []
end
#
# stack to keep track of keys as we create nested hashes
#
def key_stack
- @key_stack ||= Array.new
+ @key_stack ||= []
end
def self.parse(obj, *args)
@@ -81,9 +81,7 @@ module FFI_Yajl
# XXX: bug-compat with ruby-yajl
return nil if str == ""
- if str.respond_to?(:read)
- str = str.read()
- end
+ str = str.read if str.respond_to?(:read)
# call either the ext or ffi hook
do_yajl_parse(str, yajl_opts)
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