Sha256: 567ea8a198a93c4e6d42bcac1d99f7bd881620d246648bdd5ecf4ace4b3737ea

Contents?: true

Size: 1.99 KB

Versions: 29

Compression:

Stored size: 1.99 KB

Contents

require File.expand_path(File.join(*%w[ .. helper ]), File.dirname(__FILE__))

class RemailerInterpreterStateTest < Test::Unit::TestCase
  def test_defaults
    options = { }
    
    Remailer::Interpreter::StateProxy.new(options)

    assert_equal({ }, options)
  end
  
  def test_simple_configuration
    options = { }
    
    proxy = Remailer::Interpreter::StateProxy.new(options)

    expected = {
      :enter => [ lambda { } ],
      :default => [ lambda { } ],
      :leave => [ lambda { } ]
    }.freeze

    proxy.enter(&expected[:enter][0])
    proxy.default(&expected[:default][0])
    proxy.leave(&expected[:leave][0])
    
    assert_equal expected, options
  end

  def test_terminal_configuration
    options = { }

    expected = {
      :enter => [ lambda { } ],
      :terminate => [ lambda { } ],
      :leave => [ lambda { } ]
    }.freeze

    Remailer::Interpreter::StateProxy.new(options) do
      enter(&expected[:enter][0])
      terminate(&expected[:terminate][0])
      leave(&expected[:leave][0])
    end

    assert_equal expected, options
  end

  def test_interpreting_configuration
    options = { }
    
    expected = {
      :enter => [ lambda { } ],
      :interpret => [ [ 10, lambda { } ], [ 1, lambda { } ] ],
      :default => [ lambda { } ],
      :leave => [ lambda { } ]
    }.freeze

    Remailer::Interpreter::StateProxy.new(options) do
      enter(&expected[:enter][0])
      interpret(10, &expected[:interpret][0][1])
      interpret(1, &expected[:interpret][1][1])
      default(&expected[:default][0])
      leave(&expected[:leave][0])
    end

    assert_equal expected, options
  end

  def test_rebind
    options_a = { }
    options_b = { }
    
    proc = [ lambda { }, lambda { } ]
    
    proxy = Remailer::Interpreter::StateProxy.new(options_a) do
      enter(&proc[0])
    end
    
    proxy.send(:rebind, options_b)
    
    proxy.leave(&proc[1])
    
    assert_equal({ :enter => [ proc[0] ] }, options_a)
    assert_equal({ :leave => [ proc[1] ] }, options_b)
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
remailer-0.5.2 test/unit/remailer_interpreter_state_proxy_test.rb
remailer-0.5.1 test/unit/remailer_interpreter_state_proxy_test.rb
remailer-0.5.0 test/unit/remailer_interpreter_state_proxy_test.rb
remailer-0.4.21 test/unit/remailer_interpreter_state_proxy_test.rb
remailer-0.4.20 test/unit/remailer_interpreter_state_proxy_test.rb
remailer-0.4.19 test/unit/remailer_interpreter_state_proxy_test.rb
remailer-0.4.18 test/unit/remailer_interpreter_state_proxy_test.rb
remailer-0.4.17 test/unit/remailer_interpreter_state_proxy_test.rb
remailer-0.4.16 test/unit/remailer_interpreter_state_proxy_test.rb
remailer-0.4.15 test/unit/remailer_interpreter_state_proxy_test.rb
remailer-0.4.14 test/unit/remailer_interpreter_state_proxy_test.rb
remailer-0.4.13 test/unit/remailer_interpreter_state_proxy_test.rb
remailer-0.4.12 test/unit/remailer_interpreter_state_proxy_test.rb
remailer-0.4.11 test/unit/remailer_interpreter_state_proxy_test.rb
remailer-0.4.10 test/unit/remailer_interpreter_state_proxy_test.rb
remailer-0.4.8 test/unit/remailer_interpreter_state_proxy_test.rb
remailer-0.4.6 test/unit/remailer_interpreter_state_proxy_test.rb
remailer-0.4.5 test/unit/remailer_interpreter_state_proxy_test.rb
remailer-0.4.4 test/unit/remailer_interpreter_state_proxy_test.rb
remailer-0.4.3 test/unit/remailer_interpreter_state_proxy_test.rb