Skip to content

Commit

Permalink
Remove multi_json dependency, yajl-ruby use only JSON (vcr#815)
Browse files Browse the repository at this point in the history
  • Loading branch information
olleolleolle authored Apr 13, 2020
1 parent b38369d commit a9b6541
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 32 deletions.
3 changes: 0 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,3 @@ platform :mri do
gem "curb", "~> 0.9.0"
end

platform :ruby do
gem "yajl-ruby"
end
4 changes: 2 additions & 2 deletions features/cassettes/format.feature
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ Feature: Cassette format
(such as on ruby 1.8), to ensure that syck is always used.
- `:psych`--Uses psych (the new ruby 1.9 YAML engine). This is useful when
you want to ensure that psych is always used.
- `:json`--Uses [multi_json](https://github.com/intridea/multi_json)
to serialize the cassette data as JSON.
- `:json`--Uses Ruby's standard library to serialize the cassette data as
JSON.
- `:compressed`--Wraps the default YAML serializer with Zlib, writing
compressed cassettes to disk.

Expand Down
5 changes: 2 additions & 3 deletions features/step_definitions/cli_steps.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'vcr'
require 'multi_json'

module VCRHelpers

Expand Down Expand Up @@ -140,8 +139,8 @@ def modify_file(file_name, orig_text, new_text)

Then(/^the file "([^"]*)" should contain JSON like:$/) do |file_name, expected_content|
actual_content = cd('.') { File.read(file_name) }
actual = MultiJson.decode(actual_content)
expected = MultiJson.decode(expected_content.to_s)
actual = JSON.parse(actual_content)
expected = JSON.parse(expected_content.to_s)
expect(normalize_cassette_hash(actual)).to eq(normalize_cassette_hash(expected))
end

Expand Down
14 changes: 7 additions & 7 deletions lib/vcr/cassette/serializers/json.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'multi_json'
require 'json'

module VCR
class Cassette
Expand All @@ -13,8 +13,8 @@ module JSON
extend EncodingErrorHandling

# @private
ENCODING_ERRORS = [MultiJson::DecodeError, ArgumentError]
ENCODING_ERRORS << EncodingError if defined?(EncodingError)
ENCODING_ERRORS = [ArgumentError]
ENCODING_ERRORS << ::JSON::GeneratorError

# The file extension to use for this serializer.
#
Expand All @@ -23,23 +23,23 @@ def file_extension
"json"
end

# Serializes the given hash using `MultiJson`.
# Serializes the given hash using `JSON`.
#
# @param [Hash] hash the object to serialize
# @return [String] the JSON string
def serialize(hash)
handle_encoding_errors do
MultiJson.encode(hash)
::JSON.generate(hash)
end
end

# Deserializes the given string using `MultiJson`.
# Deserializes the given string using `JSON`.
#
# @param [String] string the JSON string
# @return [Hash] the deserialized object
def deserialize(string)
handle_encoding_errors do
MultiJson.decode(string)
::JSON.parse(string)
end
end
end
Expand Down
19 changes: 3 additions & 16 deletions spec/lib/vcr/cassette/serializers_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'support/ruby_interpreter'
require 'vcr/cassette/serializers'
require 'multi_json'
require 'json'

begin
require 'psych' # ensure psych is loaded for these tests if its available
Expand Down Expand Up @@ -73,21 +73,8 @@ class Cassette
end

it_behaves_like "a serializer", :json, "json", :lazily_loaded do
engines = {}

if RUBY_INTERPRETER == :jruby
# don't test yajl on jruby
else
engines[:yajl] = MultiJson::LoadError
end

engines.each do |engine, error|
context "when MultiJson is configured to use #{engine.inspect}", :unless => (RUBY_INTERPRETER == :jruby) do
before { MultiJson.engine = engine }
it_behaves_like "encoding error handling", :json, error do
let(:string) { "\xFA" }
end
end
it_behaves_like "encoding error handling", :json, ::JSON::GeneratorError do
let(:string) { "\xFA" }
end
end

Expand Down
1 change: 0 additions & 1 deletion vcr.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "httpclient"
spec.add_development_dependency "excon", ">= 0.62.0"
spec.add_development_dependency "timecop"
spec.add_development_dependency "multi_json"
spec.add_development_dependency "json"
spec.add_development_dependency "relish"
spec.add_development_dependency "mime-types"
Expand Down

0 comments on commit a9b6541

Please sign in to comment.