diff options
author | Jon Moss <me@jonathanmoss.me> | 2016-11-20 10:09:20 -0500 |
---|---|---|
committer | Jon Moss <me@jonathanmoss.me> | 2016-11-20 10:46:16 -0500 |
commit | 0ab54f4a49b388f0b75862b881fdef2545b380cf (patch) | |
tree | cda3fa72a292f0e91184b8fc77c29fba2afdcdf2 | |
parent | 2bdc4ddc065cb395f287f1511f9cb14059a66652 (diff) | |
download | rails-0ab54f4a49b388f0b75862b881fdef2545b380cf.tar.gz rails-0ab54f4a49b388f0b75862b881fdef2545b380cf.tar.bz2 rails-0ab54f4a49b388f0b75862b881fdef2545b380cf.zip |
Create XMLMiniEngineTest; base class for all tests
-rw-r--r-- | activesupport/test/xml_mini/jdom_engine_test.rb | 11 | ||||
-rw-r--r-- | activesupport/test/xml_mini/libxml_engine_test.rb | 15 | ||||
-rw-r--r-- | activesupport/test/xml_mini/libxmlsax_engine_test.rb | 15 | ||||
-rw-r--r-- | activesupport/test/xml_mini/nokogiri_engine_test.rb | 15 | ||||
-rw-r--r-- | activesupport/test/xml_mini/nokogirisax_engine_test.rb | 15 | ||||
-rw-r--r-- | activesupport/test/xml_mini/rexml_engine_test.rb | 8 | ||||
-rw-r--r-- | activesupport/test/xml_mini/xml_mini_engine_test.rb (renamed from activesupport/test/xml_mini/common.rb) | 17 |
7 files changed, 33 insertions, 63 deletions
diff --git a/activesupport/test/xml_mini/jdom_engine_test.rb b/activesupport/test/xml_mini/jdom_engine_test.rb index 3034bc7148..a29949ab87 100644 --- a/activesupport/test/xml_mini/jdom_engine_test.rb +++ b/activesupport/test/xml_mini/jdom_engine_test.rb @@ -1,14 +1,9 @@ -if RUBY_PLATFORM.include?("java") - require "abstract_unit" - require "active_support/xml_mini" - require "active_support/core_ext/hash/conversions" - require_relative "./common" +require_relative "xml_mini_engine_test" - class JDOMEngineTest < ActiveSupport::TestCase +XMLMiniEngineTest.run_with_platform("java") do + class JDOMEngineTest < XMLMiniEngineTest FILES_DIR = File.dirname(__FILE__) + "/../fixtures/xml" - include CommonXMLMiniAdapterTest - def test_not_allowed_to_expand_entities_to_files attack_xml = <<-EOT <!DOCTYPE member [ diff --git a/activesupport/test/xml_mini/libxml_engine_test.rb b/activesupport/test/xml_mini/libxml_engine_test.rb index 13f66cdfe7..e3b06e24b7 100644 --- a/activesupport/test/xml_mini/libxml_engine_test.rb +++ b/activesupport/test/xml_mini/libxml_engine_test.rb @@ -1,16 +1,7 @@ -begin - require "libxml" -rescue LoadError - # Skip libxml tests -else - require "abstract_unit" - require "active_support/xml_mini" - require "active_support/core_ext/hash/conversions" - require_relative "./common" - - class LibxmlEngineTest < ActiveSupport::TestCase - include CommonXMLMiniAdapterTest +require_relative "xml_mini_engine_test" +XMLMiniEngineTest.run_with_gem("libxml") do + class LibxmlEngineTest < XMLMiniEngineTest def setup super LibXML::XML::Error.set_handler(&lambda { |error| }) #silence libxml, exceptions will do diff --git a/activesupport/test/xml_mini/libxmlsax_engine_test.rb b/activesupport/test/xml_mini/libxmlsax_engine_test.rb index eb128d533d..b677f115e5 100644 --- a/activesupport/test/xml_mini/libxmlsax_engine_test.rb +++ b/activesupport/test/xml_mini/libxmlsax_engine_test.rb @@ -1,16 +1,7 @@ -begin - require "libxml" -rescue LoadError - # Skip libxml tests -else - require "abstract_unit" - require "active_support/xml_mini" - require "active_support/core_ext/hash/conversions" - require_relative "./common" - - class LibXMLSAXEngineTest < ActiveSupport::TestCase - include CommonXMLMiniAdapterTest +require_relative "xml_mini_engine_test" +XMLMiniEngineTest.run_with_gem("libxml") do + class LibXMLSAXEngineTest < XMLMiniEngineTest private def engine diff --git a/activesupport/test/xml_mini/nokogiri_engine_test.rb b/activesupport/test/xml_mini/nokogiri_engine_test.rb index 3f976a3b57..e90dfa173f 100644 --- a/activesupport/test/xml_mini/nokogiri_engine_test.rb +++ b/activesupport/test/xml_mini/nokogiri_engine_test.rb @@ -1,16 +1,7 @@ -begin - require "nokogiri" -rescue LoadError - # Skip nokogiri tests -else - require "abstract_unit" - require "active_support/xml_mini" - require "active_support/core_ext/hash/conversions" - require_relative "./common" - - class NokogiriEngineTest < ActiveSupport::TestCase - include CommonXMLMiniAdapterTest +require_relative "xml_mini_engine_test" +XMLMiniEngineTest.run_with_gem("nokogiri") do + class NokogiriEngineTest < XMLMiniEngineTest private def engine diff --git a/activesupport/test/xml_mini/nokogirisax_engine_test.rb b/activesupport/test/xml_mini/nokogirisax_engine_test.rb index 823c6243bb..0f559dc7a5 100644 --- a/activesupport/test/xml_mini/nokogirisax_engine_test.rb +++ b/activesupport/test/xml_mini/nokogirisax_engine_test.rb @@ -1,16 +1,7 @@ -begin - require "nokogiri" -rescue LoadError - # Skip nokogiri tests -else - require "abstract_unit" - require "active_support/xml_mini" - require "active_support/core_ext/hash/conversions" - require_relative "./common" - - class NokogiriSAXEngineTest < ActiveSupport::TestCase - include CommonXMLMiniAdapterTest +require_relative "xml_mini_engine_test" +XMLMiniEngineTest.run_with_gem("nokogiri") do + class NokogiriSAXEngineTest < XMLMiniEngineTest private def engine diff --git a/activesupport/test/xml_mini/rexml_engine_test.rb b/activesupport/test/xml_mini/rexml_engine_test.rb index 4222436ae8..085cf2caf7 100644 --- a/activesupport/test/xml_mini/rexml_engine_test.rb +++ b/activesupport/test/xml_mini/rexml_engine_test.rb @@ -1,10 +1,6 @@ -require "abstract_unit" -require "active_support/xml_mini" -require_relative "./common" - -class REXMLEngineTest < ActiveSupport::TestCase - include CommonXMLMiniAdapterTest +require_relative "xml_mini_engine_test" +class REXMLEngineTest < XMLMiniEngineTest def test_default_is_rexml assert_equal ActiveSupport::XmlMini_REXML, ActiveSupport::XmlMini.backend end diff --git a/activesupport/test/xml_mini/common.rb b/activesupport/test/xml_mini/xml_mini_engine_test.rb index c97bbf7e35..a7d4fe20ad 100644 --- a/activesupport/test/xml_mini/common.rb +++ b/activesupport/test/xml_mini/xml_mini_engine_test.rb @@ -1,4 +1,19 @@ -module CommonXMLMiniAdapterTest +require "abstract_unit" +require "active_support/xml_mini" +require "active_support/core_ext/hash/conversions" + +class XMLMiniEngineTest < ActiveSupport::TestCase + def self.run_with_gem(gem_name) + require gem_name + yield + rescue LoadError + # Skip tests unless gem is available + end + + def self.run_with_platform(platform_name) + yielf if RUBY_PLATFORM.include?(platform_name) + end + def setup @default_backend = ActiveSupport::XmlMini.backend ActiveSupport::XmlMini.backend = engine |