File: test_trigger.rb

package info (click to toggle)
ruby-god 0.12.1-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 752 kB
  • sloc: ruby: 5,913; ansic: 217; makefile: 3
file content (59 lines) | stat: -rw-r--r-- 1,236 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require File.dirname(__FILE__) + '/helper'

class TestTrigger < Test::Unit::TestCase
  def setup
    Trigger.reset
  end

  # base case

  def test_should_have_empty_triggers
    assert_equal({}, Trigger.triggers)
  end

  # register

  def test_register_should_add_condition_to_triggers
    c = Condition.new
    c.watch = stub(:name => 'foo')
    Trigger.register(c)

    assert_equal({'foo' => [c]}, Trigger.triggers)
  end

  def test_register_should_add_condition_to_triggers_twice
    watch = stub(:name => 'foo')
    c = Condition.new
    c.watch = watch
    Trigger.register(c)

    c2 = Condition.new
    c2.watch = watch
    Trigger.register(c2)

    assert_equal({'foo' => [c, c2]}, Trigger.triggers)
  end

  # deregister

  def test_deregister_should_remove_condition_from_triggers
    c = Condition.new
    c.watch = stub(:name => 'foo')
    Trigger.register(c)
    Trigger.deregister(c)

    assert_equal({}, Trigger.triggers)
  end

  # broadcast

  def test_broadcast_should_call_process_on_each_condition
    c = Condition.new
    c.watch = stub(:name => 'foo')
    Trigger.register(c)

    c.expects(:process).with(:state_change, [:up, :start])

    Trigger.broadcast(c.watch, :state_change, [:up, :start])
  end
end