Sha256: ed535f7bb0eb808be0476c786a22d1f0f7cba66f3b57f19a7f8bdc51bdd803fa

Contents?: true

Size: 1.71 KB

Versions: 6

Compression:

Stored size: 1.71 KB

Contents

require 'helper'

class TestEvaluator < Test::Unit::TestCase
  
  def test_does_nothing_without_handlers
    stack = le("Tracker4", le(le("enabled", "true")))
    e = Tickly::Evaluator.new
    e.evaluate(stack)
  end

  class ShouldNotBeInstantiated
    def initialize
      raise "You failed"
    end
  end
  
  def test_does_not_send_anything_when_the_expression_passed_does_not_match_pattern
    stack = e("ShouldNotBeInstantiated")
    e = Tickly::Evaluator.new
    e.add_node_handler_class(ShouldNotBeInstantiated)
    assert_nothing_raised { e.evaluate(stack) }
  end
  
  class SomeNode
    attr_reader :options
    def initialize(options_hash)
      @options = options_hash
    end
  end
  
  def test_instantiates_handler_class
    stack = e("SomeNode", le(e("foo", "bar"), e("baz", "bad")))
    e = Tickly::Evaluator.new
    e.add_node_handler_class(SomeNode)
    node = e.evaluate(stack)
    
    assert_kind_of SomeNode, node
    ref_o = {"foo" => "bar", "baz" => "bad"}
    assert_equal ref_o, node.options
  end
  
  class TargetError < RuntimeError
  end
  
  def test_yields_the_handler_instance
    stack = e("SomeNode", le(e("foo", "bar"), e("baz", "bad")))
    e = Tickly::Evaluator.new
    e.add_node_handler_class(SomeNode)
    ref_o = {"foo" => "bar", "baz" => "bad"}
    
    assert_raise(TargetError) do
      e.evaluate(stack) do | some_node |
        assert_kind_of SomeNode, some_node
        raise TargetError
      end
    end
  end
  
  def test_will_capture
    e = Tickly::Evaluator.new
    e.add_node_handler_class(SomeNode)
    
    valid = e("SomeNode", le(e("foo", "bar"), e("baz", "bad")))
    assert e.will_capture?(valid)
    assert !e.will_capture?([])
    assert !e.will_capture?(e("SomeNode"))
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
tickly-2.1.7 test/test_evaluator.rb
tickly-2.1.6 test/test_evaluator.rb
tickly-2.1.5 test/test_evaluator.rb
tickly-2.1.4 test/test_evaluator.rb
tickly-2.1.3 test/test_evaluator.rb
tickly-2.1.2 test/test_evaluator.rb