forked from richkilmer/hotcocoa
-
Notifications
You must be signed in to change notification settings - Fork 8
/
test_notification_listener.rb
48 lines (40 loc) · 1.31 KB
/
test_notification_listener.rb
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
# Integration tests
class TestNotificationListener < MiniTest::Unit::TestCase
include HotCocoa
def teardown
NotificationListener.registered_listeners.each &:stop_listening
end
def test_requires_a_block
assert_raises ArgumentError do
NotificationListener.new
end
end
def test_caches_listeners
listener = NotificationListener.new { |_| }
assert_includes NotificationListener.registered_listeners, listener
end
def test_executes_block_when_notif_is_received
got_callback = false
NotificationListener.new named: 'test' do |_|
got_callback = true
end
NSNotificationCenter.defaultCenter.postNotificationName 'test',
object: self
assert got_callback
end
def test_can_stop_listening
got_callback = false
listener = NotificationListener.new named: 'test2' do |_|
got_callback = true
end
listener.stop_listening
NSNotificationCenter.defaultCenter.postNotificationName 'test2',
object: self
refute_includes NotificationListener.registered_listeners, listener
refute got_callback
end
def test_on_notification_is_alias
listener = ::HotCocoa.on_notification { |_| }
assert_kind_of NotificationListener, listener
end
end