Sha256: 1e6d73fa35bcaa4f7b3e74874de616b8b861a5bbe7edee41e5001a13e121eac5

Contents?: true

Size: 1.53 KB

Versions: 4

Compression:

Stored size: 1.53 KB

Contents

require File.expand_path('../helper', __FILE__)

class TestErrorHandling < Test::Unit::TestCase
  should "handle missing function of object" do
    
    class TestClass
      sandboxed_methods :ok_to_call
      
      def ok_to_call
        "A"
      end
      
      def not_ok_to_call
        "B"
      end
    end
    
    str_template = "not_ok_to_call = <%=tc.not_ok_to_call.some_other_thingo.and_this %>"
    template = SandboxedErb::Template.new
    template.compile(str_template)
    assert_equal nil,template.run(nil, {:tc=>TestClass.new})

    assert_equal "Error on line 1: Unknown method 'not_ok_to_call' on object 'TestErrorHandling::TestClass'", template.get_error

  end
  
  should "handle missing functions" do
    

    str_template = "some method = <%=some_method_that_does_not_exist(1) %>"
    template = SandboxedErb::Template.new
    template.compile(str_template)
    assert_equal nil,template.run(nil, {:tc=>TestClass.new})
    
    assert_equal "Error on line 1: Unknown method: some_method_that_does_not_exist", template.get_error

  end
  

  should "report exceptions in mixins" do
    
    module MixinTest1
      def test_mixin_method1(val)
        raise "mixin exception"  
      end
    end

    
    str_template = "mixin = 
    <%= test_mixin_method1('A') %>"
    template = SandboxedErb::Template.new([MixinTest1])
    assert_equal true, template.compile(str_template)
    assert_equal nil, template.run(nil, {})
    
    assert_equal "Error on line 2: Error calling test_mixin_method1: mixin exception", template.get_error

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sandboxed_erb-0.4.8 test/test_error_handling.rb
sandboxed_erb-0.4.7 test/test_error_handling.rb
sandboxed_erb-0.4.6 test/test_error_handling.rb
sandboxed_erb-0.4.5 test/test_error_handling.rb