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

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/builder-3.2.4/test/test_method_caching.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/builder-3.2.4/test/test_method_caching.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/builder-3.2.4/test/test_method_caching.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/builder-3.2.4/test/test_method_caching.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/builder-3.2.4/test/test_method_caching.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/builder-3.2.4/test/test_method_caching.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/builder-3.2.4/test/test_method_caching.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_method_caching.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_method_caching.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_method_caching.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_method_caching.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_method_caching.rb
ric-0.14.2 vendor/bundle/ruby/2.7.0/gems/builder-3.2.4/test/test_method_caching.rb
ric-0.14.1 vendor/bundle/ruby/2.7.0/gems/builder-3.2.4/test/test_method_caching.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/builder-3.2.4/test/test_method_caching.rb
ric-0.14.0 vendor/bundle/ruby/2.7.0/gems/builder-3.2.4/test/test_method_caching.rb
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/builder-3.2.4/test/test_method_caching.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/builder-3.2.4/test/test_method_caching.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/builder-3.2.4/test/test_method_caching.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/builder-3.2.4/test/test_method_caching.rb