Skip to content

Commit

Permalink
Refactor to use rspec filtering.
Browse files Browse the repository at this point in the history
  • Loading branch information
djberg96 committed Mar 21, 2024
1 parent 0423d3b commit 00ba722
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "bundler"
Bundler::GemHelper.install_tasks

require "standard/rake"
require "rake"
require "rubocop/rake_task"

require "rspec/core/rake_task"
Expand Down
5 changes: 1 addition & 4 deletions spec/multi_json/adapters/gson_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
require "spec_helper"

return if skip_adapter?("gson")

require "shared/adapter"
require "multi_json/adapters/gson"

describe MultiJson::Adapters::Gson do
RSpec.describe MultiJson::Adapters::Gson, :gson => true do
it_behaves_like "an adapter", described_class
end
5 changes: 1 addition & 4 deletions spec/multi_json/adapters/jr_jackson_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
require "spec_helper"

return if skip_adapter?("jr_jackson")

require "shared/adapter"
require "multi_json/adapters/jr_jackson"

describe MultiJson::Adapters::JrJackson do
RSpec.describe MultiJson::Adapters::JrJackson, :jrjackson => true do
it_behaves_like "an adapter", described_class
end
2 changes: 1 addition & 1 deletion spec/multi_json/adapters/json_gem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "shared/json_common_adapter"
require "multi_json/adapters/json_gem"

describe MultiJson::Adapters::JsonGem do
RSpec.describe MultiJson::Adapters::JsonGem, :json => true do
it_behaves_like "an adapter", described_class
it_behaves_like "JSON-like adapter", described_class
end
5 changes: 1 addition & 4 deletions spec/multi_json/adapters/json_pure_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
require "spec_helper"

return if skip_adapter?("json_pure")

require "shared/adapter"
require "shared/json_common_adapter"
require "multi_json/adapters/json_pure"

describe MultiJson::Adapters::JsonPure do
RSpec.describe MultiJson::Adapters::JsonPure, :json_pure => true do
it_behaves_like "an adapter", described_class
it_behaves_like "JSON-like adapter", described_class
end
5 changes: 1 addition & 4 deletions spec/multi_json/adapters/oj_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
require "spec_helper"

return if skip_adapter?("oj")

require "shared/adapter"
require "multi_json/adapters/oj"

describe MultiJson::Adapters::Oj do
RSpec.describe MultiJson::Adapters::Oj, :oj => true do
it_behaves_like "an adapter", described_class

describe ".dump" do
Expand Down
2 changes: 1 addition & 1 deletion spec/multi_json/adapters/ok_json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
require "shared/adapter"
require "multi_json/adapters/ok_json"

describe MultiJson::Adapters::OkJson do
RSpec.describe MultiJson::Adapters::OkJson, :ok_json => true do
it_behaves_like "an adapter", described_class
end
5 changes: 1 addition & 4 deletions spec/multi_json/adapters/yajl_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
require "spec_helper"

return if skip_adapter?("yajl")

require "shared/adapter"
require "multi_json/adapters/yajl"

describe MultiJson::Adapters::Yajl do
RSpec.describe MultiJson::Adapters::Yajl, :yajl => true do
it_behaves_like "an adapter", described_class
end
58 changes: 31 additions & 27 deletions spec/multi_json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,29 @@
end
end

it "defaults to the best available gem" do
# Clear cache variable already set by previous tests
described_class.send(:remove_instance_variable, :@adapter) if described_class.instance_variable_defined?(:@adapter)

if jruby? && !skip_adapter?("jr_jackson")
expect(described_class.adapter.to_s).to eq("MultiJson::Adapters::JrJackson")
elsif jruby?
expect(described_class.adapter.to_s).to eq("MultiJson::Adapters::JsonGem")
else
expect(described_class.adapter.to_s).to eq("MultiJson::Adapters::Oj")
context "automatic adapter loading" do
before{ MultiJson::OptionsCache.reset }

it "defaults to the best available gem" do
# Clear cache variable already set by previous tests
#described_class.send(:remove_instance_variable, :@adapter) if described_class.instance_variable_defined?(:@adapter)
#allow(described_class).to receive(:adapter).and_return(nil)
#allow(Kernel).to receive(:defined?).with("@adapter").and_return(false)

if RUBY_PLATFORM == 'java' && !skip_adapter?("jr_jackson")
expect(described_class.adapter.to_s).to eq("MultiJson::Adapters::JrJackson")
elsif RUBY_PLATFORM == 'java'
expect(described_class.adapter.to_s).to eq("MultiJson::Adapters::JsonGem")
else
expect(described_class.adapter.to_s).to eq("MultiJson::Adapters::Oj")
end
end
end

it "looks for adapter even if @adapter variable is nil" do
described_class.send(:instance_variable_set, :@adapter, nil)
allow(described_class).to receive(:default_adapter).and_return(:ok_json)
expect(described_class.adapter).to eq(MultiJson::Adapters::OkJson)
it "looks for adapter even if @adapter variable is nil" do
described_class.send(:instance_variable_set, :@adapter, nil)
allow(described_class).to receive(:default_adapter).and_return(:ok_json)
expect(described_class.adapter).to eq(MultiJson::Adapters::OkJson)
end
end

it "is settable via a symbol" do
Expand Down Expand Up @@ -142,7 +148,7 @@
end

it "JSON gem does not create symbols on parse" do
skip "breaks in JRuby" if jruby?
skip "java based implementations" if RUBY_ENGINE == 'java'

described_class.with_engine(:json_gem) do
described_class.load('{"json_class":"ZOMG"}')
Expand Down Expand Up @@ -170,18 +176,16 @@

it_behaves_like "has options", described_class

describe "aliases" do
unless skip_adapter?("jr_jackson")
describe "jrjackson" do
it "allows jrjackson alias as symbol" do
expect { described_class.use :jrjackson }.not_to raise_error
expect(described_class.adapter).to eq(MultiJson::Adapters::JrJackson)
end
describe "aliases", :jrjackson => true do
describe "jrjackson" do
it "allows jrjackson alias as symbol" do
expect { described_class.use :jrjackson }.not_to raise_error
expect(described_class.adapter).to eq(MultiJson::Adapters::JrJackson)
end

it "allows jrjackson alias as string" do
expect { described_class.use "jrjackson" }.not_to raise_error
expect(described_class.adapter).to eq(MultiJson::Adapters::JrJackson)
end
it "allows jrjackson alias as string" do
expect { described_class.use "jrjackson" }.not_to raise_error
expect(described_class.adapter).to eq(MultiJson::Adapters::JrJackson)
end
end
end
Expand Down
24 changes: 17 additions & 7 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@
config.expect_with :rspec do |c|
c.syntax = :expect
end

skip = ENV['SKIP_ADAPTERS'].to_s.split(',').map(&:strip).map(&:downcase)

config.filter_run_excluding(:gson) if skip.include?('gson')
config.filter_run_excluding(:json) if skip.include?('json')
config.filter_run_excluding(:json_pure) if skip.include?('json_pure')
config.filter_run_excluding(:ok_json) if skip.include?('ok_json')
config.filter_run_excluding(:oj) if skip.include?('oj')
config.filter_run_excluding(:yajl) if skip.include?('yajl')

if RUBY_PLATFORM != 'java' || skip.include?('java')
config.filter_run_excluding(:java)
config.filter_run_excluding(:jrjackson)
end
end

def silence_warnings
Expand All @@ -15,20 +29,16 @@ def silence_warnings
$VERBOSE = old_verbose
end

def macruby?
defined?(RUBY_ENGINE) && RUBY_ENGINE == "macruby"
end

def jruby?
defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
def java?
RUBY_PLATFORM == 'java'
end

def skip_adapter?(adapter_name)
@skip ||=
ENV.fetch("SKIP_ADAPTERS", "")
.split(",")
.then do |skip|
if jruby?
if java?
%w[oj yajl] + skip
else
%w[gson] + skip
Expand Down

0 comments on commit 00ba722

Please sign in to comment.