Sha256: f48cfaa842fbfce892fc072f1cc17ca3a2798fdec1fb410acfea7416ed862a49

Contents?: true

Size: 1.56 KB

Versions: 70

Compression:

Stored size: 1.56 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 '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

70 entries across 59 versions & 16 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/builder-3.2.3/test/test_method_caching.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/builder-3.2.3/test/test_method_caching.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/builder-3.2.3/test/test_method_caching.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/builder-3.2.3/test/test_method_caching.rb
vagrant-unbundled-2.2.6.2 vendor/bundle/ruby/2.6.0/gems/builder-3.2.3/test/test_method_caching.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/builder-3.2.3/test/test_method_caching.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/builder-3.2.3/test/test_method_caching.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/builder-3.2.3/test/test_method_caching.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/builder-3.2.3/test/test_method_caching.rb
vagrant-unbundled-2.2.6.1 vendor/bundle/ruby/2.6.0/gems/builder-3.2.3/test/test_method_caching.rb
vagrant-unbundled-2.2.6.0 vendor/bundle/ruby/2.6.0/gems/builder-3.2.3/test/test_method_caching.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/builder-3.2.3/test/test_method_caching.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/builder-3.2.3/test/test_method_caching.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/builder-3.2.3/test/test_method_caching.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/builder-3.2.3/test/test_method_caching.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/builder-3.2.3/test/test_method_caching.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/builder-3.2.3/test/test_method_caching.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/builder-3.2.3/test/test_method_caching.rb
spiral_form-0.1.1 vendor/bundle/gems/builder-3.2.3/test/test_method_caching.rb
spiral_form-0.1.0 vendor/bundle/gems/builder-3.2.3/test/test_method_caching.rb