Sha256: c41b81d6702c612f6ff905af23fea4c502b961f6cae9a2310bf0c2280873ca6e

Contents?: true

Size: 1.93 KB

Versions: 11

Compression:

Stored size: 1.93 KB

Contents

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

class RadiusContextTest < Test::Unit::TestCase
  include RadiusTestHelper
  
  class SuperContext < Radius::Context
    attr_accessor :name
    def initialize(name)
      self.name = name
      super
    end
  end
  
  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_initialize_with_arguments
    @context = SuperContext.new('arg') do |c|
      assert_kind_of Radius::Context, c
      c.define_tag('test') { 'just a test' }
    end
    assert_equal 'arg', @context.name
  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

11 entries across 10 versions & 3 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/radius-0.7.5/test/context_test.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/radius-0.7.5/test/context_test.rb
radius-0.7.5 test/context_test.rb
radius-0.7.4 test/context_test.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/radius-0.7.3/test/context_test.rb
radius-0.7.3 test/context_test.rb
radius-0.7.2 test/context_test.rb
radius-0.7.1 test/context_test.rb
radius-0.7.0 test/context_test.rb
radius-0.7.0.prerelease3 test/context_test.rb
radius-0.7.0.prerelease2 test/context_test.rb