From b848700ccfffc0d4c424daa10ca29e19106e8e3f Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Fri, 15 Sep 2023 18:29:31 -0400 Subject: [PATCH] [ruby/yarp] Extract test listener to its own class https://github.com/ruby/yarp/commit/c8caa997c0 --- test/yarp/dispatcher_test.rb | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/test/yarp/dispatcher_test.rb b/test/yarp/dispatcher_test.rb index 52be2ba32f..f27cf49e17 100644 --- a/test/yarp/dispatcher_test.rb +++ b/test/yarp/dispatcher_test.rb @@ -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