Sha256: 4c3b2e5009c21565ad6fc4166cb8d4d4446d4c050efb73861df3f344fc650f71
Contents?: true
Size: 1.59 KB
Versions: 95
Compression:
Stored size: 1.59 KB
Contents
#!/usr/bin/env ruby # frozen_string_literal: true #-- # Portions copyright 2011 by Bart ten Brinke (info@retrosync.com). # All rights reserved. # Permission is granted for use, copying, modification, distribution, # and distribution of modified versions of this work as long as the # above copyright notice is included. #++ require 'helper' require 'preload' require 'builder' class TestMethodCaching < Builder::Test # We can directly ask if xml object responds to the cache_me or # do_not_cache_me methods because xml is derived from BasicObject # (and repond_to? is not defined in BasicObject). # # Instead we are going to stub out method_missing so that it throws # an error, and then make sure that error is either thrown or not # thrown as appropriate. def teardown super Builder::XmlBase.cache_method_calls = true end def test_caching_does_not_break_weird_symbols xml = Builder::XmlMarkup.new xml.__send__("work-order", 1) assert_equal "<work-order>1</work-order>", xml.target! end def test_method_call_caching xml = Builder::XmlMarkup.new xml.cache_me def xml.method_missing(*args) ::Kernel.fail StandardError, "SHOULD NOT BE CALLED" end assert_nothing_raised do xml.cache_me end end def test_method_call_caching_disabled Builder::XmlBase.cache_method_calls = false xml = Builder::XmlMarkup.new xml.do_not_cache_me def xml.method_missing(*args) ::Kernel.fail StandardError, "SHOULD BE CALLED" end assert_raise(StandardError, "SHOULD BE CALLED") do xml.do_not_cache_me end end end
Version data entries
95 entries across 57 versions & 18 rubygems