Sha256: dbe75462803bbad63c7461ff9f34f3c937b57caaa0386a973a20de551844c22e

Contents?: true

Size: 1.57 KB

Versions: 36

Compression:

Stored size: 1.57 KB

Contents

#!/usr/bin/env ruby

#--
# 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 'test/unit'
require 'test/preload'
require 'builder'

class TestMethodCaching < Test::Unit::TestCase

  # 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

36 entries across 33 versions & 16 rubygems

Version Path
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/builder-3.2.2/test/test_method_caching.rb
abaci-0.3.0 vendor/bundle/gems/builder-3.2.2/test/test_method_caching.rb
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/gems/builder-3.2.2/test/test_method_caching.rb
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/gems/builder-3.2.2/test/test_method_caching.rb
vagrant-compose-yaml-0.1.1 vendor/bundle/ruby/2.2.0/gems/builder-3.2.2/test/test_method_caching.rb
vagrant-compose-yaml-0.1.0 vendor/bundle/ruby/2.2.0/gems/builder-3.2.2/test/test_method_caching.rb
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/builder-3.2.2/test/test_method_caching.rb
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/builder-3.2.2/test/test_method_caching.rb
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/builder-3.2.2/test/test_method_caching.rb
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/builder-3.2.2/test/test_method_caching.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/builder-3.2.2/test/test_method_caching.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/builder-3.2.2/test/test_method_caching.rb
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/builder-3.2.2/test/test_method_caching.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/builder-3.2.2/test/test_method_caching.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/builder-3.2.2/test/test_method_caching.rb
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/builder-3.2.2/test/test_method_caching.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/builder-3.2.2/test/test_method_caching.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/builder-3.2.2/test/test_method_caching.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/builder-3.2.2/test/test_method_caching.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/builder-3.2.2/test/test_method_caching.rb