зеркало из https://github.com/github/ruby.git
[ruby/yarp] Extract test listener to its own class
https://github.com/ruby/yarp/commit/c8caa997c0
This commit is contained in:
Родитель
35960ce65e
Коммит
b848700ccf
|
@ -4,27 +4,27 @@ require_relative "test_helper"
|
|||
|
||||
module YARP
|
||||
class DispatcherTest < TestCase
|
||||
def setup
|
||||
@listener = Class.new do
|
||||
attr_reader :events_received
|
||||
class TestListener
|
||||
attr_reader :events_received
|
||||
|
||||
def initialize
|
||||
@events_received = []
|
||||
end
|
||||
def initialize
|
||||
@events_received = []
|
||||
end
|
||||
|
||||
def call_node_enter(node)
|
||||
@events_received << :call_node_enter
|
||||
end
|
||||
def call_node_enter(node)
|
||||
events_received << :call_node_enter
|
||||
end
|
||||
|
||||
def call_node_leave(node)
|
||||
@events_received << :call_node_leave
|
||||
end
|
||||
end.new
|
||||
def call_node_leave(node)
|
||||
events_received << :call_node_leave
|
||||
end
|
||||
end
|
||||
|
||||
def test_dispatching_events
|
||||
listener = TestListener.new
|
||||
|
||||
dispatcher = Dispatcher.new
|
||||
dispatcher.register(@listener, :call_node_enter, :call_node_leave)
|
||||
dispatcher.register(listener, :call_node_enter, :call_node_leave)
|
||||
|
||||
root = YARP.parse(<<~RUBY).value
|
||||
def foo
|
||||
|
@ -33,8 +33,7 @@ module YARP
|
|||
RUBY
|
||||
|
||||
dispatcher.dispatch(root)
|
||||
|
||||
assert_equal([:call_node_enter, :call_node_leave], @listener.events_received)
|
||||
assert_equal([:call_node_enter, :call_node_leave], listener.events_received)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче