Sha256: 1efeb280ae8e04ab0382f3c50ca3ffa70b3461de9a7f483640b82b9d55905b3b

Contents?: true

Size: 1.05 KB

Versions: 8

Compression:

Stored size: 1.05 KB

Contents

require 'helper'

class TestTrigger < Test::Unit::TestCase
  context 'in a clean state' do
    setup do
      Subtrigger::Trigger.reset
    end

    should 'define a new trigger' do
      Subtrigger::Trigger.define(/foo/) { |m, r| raise 'bar' }
      assert_equal(1, Subtrigger::Trigger.triggers.size)
    end

    should 'apply all triggers' do
      i = 0
      Subtrigger::Trigger.define(/foo/) { |m,r| i += 1 }
      Subtrigger::Trigger.define(/o+/) { |m,r| i += 1 }
      Subtrigger::Trigger.run(stub(:message => 'foo bar'))
      assert_equal(2, i)
    end

    should 'ignore unmatching triggers' do
      i = 0
      Subtrigger::Trigger.define(/foo/) { |m,r| i += 1 }
      Subtrigger::Trigger.define(/x+/) { |m,r| i += 1 }
      Subtrigger::Trigger.run(stub(:message => 'foo bar'))
      assert_equal(1, i)
    end

    should 'empty list of triggers' do
      Subtrigger::Trigger.define(/foo/) { |m,r| }
      assert_equal(1, Subtrigger::Trigger.triggers.size)
      Subtrigger::Trigger.reset
      assert_equal(0, Subtrigger::Trigger.triggers.size)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
subtrigger-0.2.7 test/test_trigger.rb
subtrigger-0.2.6 test/test_trigger.rb
subtrigger-0.2.5 test/test_trigger.rb
subtrigger-0.2.4 test/test_trigger.rb
subtrigger-0.2.3 test/test_trigger.rb
subtrigger-0.2.2 test/test_trigger.rb
subtrigger-0.2.1 test/test_trigger.rb
subtrigger-0.2.0 test/test_trigger.rb