From 7cf052607d425a968bcfa18370b2d2a089421c33 Mon Sep 17 00:00:00 2001 From: Mauro George Date: Mon, 11 Jan 2016 19:17:42 -0200 Subject: [PATCH] Remove the json_schema dependency We do not want to include the json_schema as a dependency of the gem, since the idea is to the json_schema to be used only by the test helper. This patch load the json_schema only inside the `assert_response_schema` test helper and raises a good error message when the the json_schema gem is not installed. --- active_model_serializers.gemspec | 3 +-- docs/howto/test.md | 6 ++++++ lib/active_model_serializers/test/schema.rb | 9 +++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/active_model_serializers.gemspec b/active_model_serializers.gemspec index 5a3fab9ff..2f5def5a2 100644 --- a/active_model_serializers.gemspec +++ b/active_model_serializers.gemspec @@ -46,8 +46,6 @@ Gem::Specification.new do |spec| # activesupport # activemodel - spec.add_runtime_dependency 'json_schema' - # Soft dependency for pagination spec.add_development_dependency 'kaminari', ' ~> 0.16.3' spec.add_development_dependency 'will_paginate', '~> 3.0', '>= 3.0.7' @@ -56,4 +54,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'timecop', '~> 0.7' spec.add_development_dependency 'minitest-reporters' spec.add_development_dependency 'grape', ['>= 0.13', '< 1.0'] + spec.add_development_dependency 'json_schema' end diff --git a/docs/howto/test.md b/docs/howto/test.md index c23b21e60..c7f935abe 100644 --- a/docs/howto/test.md +++ b/docs/howto/test.md @@ -1,5 +1,11 @@ # How to test +## Dependencies + +To use the `assert_response_schema` you need to have the +[`json_schema`](https://github.com/brandur/json_schema) on your Gemfile. Please +add it to your Gemfile and run `$ bundle install`. + ## Minitest test helpers ActiveModelSerializers provides a `assert_response_schema` method to be used on your controller tests to diff --git a/lib/active_model_serializers/test/schema.rb b/lib/active_model_serializers/test/schema.rb index 42d5255fb..695d0a39b 100644 --- a/lib/active_model_serializers/test/schema.rb +++ b/lib/active_model_serializers/test/schema.rb @@ -1,5 +1,3 @@ -require 'json_schema' - module ActiveModelSerializers module Test module Schema @@ -23,6 +21,7 @@ class AssertResponseSchema attr_reader :schema_path, :response, :message def initialize(schema_path, response, message) + require_json_schema! @response = response @schema_path = schema_path || schema_path_default @message = message @@ -92,6 +91,12 @@ def load_json_file(path) rescue Errno::ENOENT raise MissingSchema, "No Schema file at #{schema_full_path}" end + + def require_json_schema! + require 'json_schema' + rescue LoadError + raise LoadError, "You don't have json_schema installed in your application. Please add it to your Gemfile and run bundle install" + end end end end