Sha256: 4d6cfb3b3cfcef1e02da1593ade070a7daf2c8ff28c756f35b6dc4d5b1ebfe6a

Contents?: true

Size: 1.58 KB

Versions: 33

Compression:

Stored size: 1.58 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/test_helper')

class RadiusContextTest < Test::Unit::TestCase
  include RadiusTestHelper
  
  def setup
    @context = new_context
  end
  
  def test_initialize
    @context = Radius::Context.new
  end
  
  def test_initialize_with_block
    @context = Radius::Context.new do |c|
      assert_kind_of Radius::Context, c
      c.define_tag('test') { 'just a test' }
    end
    assert_not_equal Hash.new, @context.definitions
  end
  
  def test_with
    got = @context.with do |c|
      assert_equal @context, c
    end
    assert_equal @context, got
  end
  
  def test_render_tag
    define_global_tag "hello" do |tag|
      "Hello #{tag.attr['name'] || 'World'}!"
    end
    assert_render_tag_output 'Hello World!', 'hello'
    assert_render_tag_output 'Hello John!', 'hello', 'name' => 'John'
  end
  
  def test_render_tag__undefined_tag
    e = assert_raises(Radius::UndefinedTagError) { @context.render_tag('undefined_tag') }
    assert_equal "undefined tag `undefined_tag'", e.message
  end
  
  def test_tag_missing
    class << @context
      def tag_missing(tag, attr, &block)
        "undefined tag `#{tag}' with attributes #{attr.inspect}"
      end
    end
    
    text = ''
    expected = %{undefined tag `undefined_tag' with attributes {"cool"=>"beans"}}
    assert_nothing_raised { text = @context.render_tag('undefined_tag', 'cool' => 'beans') }
    assert_equal expected, text
  end
  
  private
    
    def assert_render_tag_output(output, *render_tag_params)
      assert_equal output, @context.render_tag(*render_tag_params)
    end
  
end

Version data entries

33 entries across 33 versions & 3 rubygems

Version Path
depengine-0.0.31 etc/isolate/ruby-1.8/gems/radius-0.6.1/test/context_test.rb
depengine-0.0.30 etc/isolate/ruby-1.8/gems/radius-0.6.1/test/context_test.rb
depengine-0.0.29 etc/isolate/ruby-1.8/gems/radius-0.6.1/test/context_test.rb
depengine-0.0.28 etc/isolate/ruby-1.8/gems/radius-0.6.1/test/context_test.rb
depengine-0.0.27 etc/isolate/ruby-1.8/gems/radius-0.6.1/test/context_test.rb
depengine-0.0.26 etc/isolate/ruby-1.8/gems/radius-0.6.1/test/context_test.rb
depengine-0.0.25 etc/isolate/ruby-1.8/gems/radius-0.6.1/test/context_test.rb
depengine-0.0.24 etc/isolate/ruby-1.8/gems/radius-0.6.1/test/context_test.rb
depengine-0.0.23 etc/isolate/ruby-1.8/gems/radius-0.6.1/test/context_test.rb
depengine-0.0.22 etc/isolate/ruby-1.8/gems/radius-0.6.1/test/context_test.rb
depengine-0.0.21 etc/isolate/ruby-1.8/gems/radius-0.6.1/test/context_test.rb
depengine-0.0.20 etc/isolate/ruby-1.8/gems/radius-0.6.1/test/context_test.rb
depengine-0.0.19 etc/isolate/ruby-1.8/gems/radius-0.6.1/test/context_test.rb
depengine-0.0.18 etc/isolate/ruby-1.8/gems/radius-0.6.1/test/context_test.rb
depengine-0.0.17 etc/isolate/ruby-1.8/gems/radius-0.6.1/test/context_test.rb
depengine-0.0.16 etc/isolate/ruby-1.8/gems/radius-0.6.1/test/context_test.rb
depengine-0.0.15 etc/isolate/ruby-1.8/gems/radius-0.6.1/test/context_test.rb
depengine-0.0.14 etc/isolate/ruby-1.8/gems/radius-0.6.1/test/context_test.rb
depengine-0.0.13 etc/isolate/ruby-1.8/gems/radius-0.6.1/test/context_test.rb
depengine-0.0.12 etc/isolate/ruby-1.8/gems/radius-0.6.1/test/context_test.rb