[ruby/yarp] Extract test listener to its own class

https://github.com/ruby/yarp/commit/c8caa997c0
This commit is contained in:
Kevin Newton 2023-09-15 18:29:31 -04:00 коммит произвёл git
Родитель 35960ce65e
Коммит b848700ccf
1 изменённых файлов: 15 добавлений и 16 удалений

Просмотреть файл

@ -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