Sha256: dd1e1f337ffc2c79fbacae1be9cfd5eb440398012ae29ec73202b9e1cb5eaf83

Contents?: true

Size: 1.57 KB

Versions: 63

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

63 entries across 46 versions & 20 rubygems

Version Path
mdg-1.0.1 vendor/bundle/ruby/2.3.0/gems/builder-3.0.4/test/test_method_caching.rb
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/builder-3.0.4/test/test_method_caching.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/builder-3.0.4/test/test_method_caching.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/builder-3.0.4/test/test_method_caching.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/builder-3.0.4/test/test_method_caching.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/builder-3.0.4/test/test_method_caching.rb
apl-library-0.0.90 vendor/bundle/ruby/1.8/gems/builder-3.0.4/test/test_method_caching.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/builder-3.0.4/test/test_method_caching.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.8/gems/builder-3.0.4/test/test_method_caching.rb
challah-1.0.0 vendor/bundle/gems/builder-3.1.4/test/test_method_caching.rb
swipe-rails-0.0.5 vendor/bundle/gems/builder-3.0.4/test/test_method_caching.rb
active_mailer-0.0.9 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/builder-3.0.4/test/test_method_caching.rb
active_mailer-0.0.8 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/builder-3.0.4/test/test_method_caching.rb
active_mailer-0.0.7 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/builder-3.0.4/test/test_method_caching.rb
active_mailer-0.0.6 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/builder-3.0.4/test/test_method_caching.rb
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/builder-3.0.4/test/test_method_caching.rb
font-awesome-rails-3.1.1.2 vendor/ruby/2.0.0/gems/builder-3.0.4/test/test_method_caching.rb
font-awesome-rails-3.1.1.1 vendor/ruby/2.0.0/gems/builder-3.0.4/test/test_method_caching.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/builder-3.0.4/test/test_method_caching.rb
challah-1.0.0.beta3 vendor/bundle/gems/builder-3.0.4/test/test_method_caching.rb