Skip to content

Commit

Permalink
Add initialized event
Browse files Browse the repository at this point in the history
Co-authored-by: Yuki INOUE <[email protected]>
  • Loading branch information
mrkn and Yuki-Inoue committed May 24, 2021
1 parent 095acbd commit 911bb7b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/iruby/kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ class Kernel
RED = "\e[31m"
RESET = "\e[0m"

class<< self
@events = EventManager.new([:initialized])

class << self
attr_reader :events
attr_accessor :instance
end

Expand Down Expand Up @@ -33,6 +36,8 @@ def initialize(config_file, session_adapter_name=nil)
@execution_count = 0
@backend = create_backend
@running = true

self.class.events.trigger(:initialized, self)
end

attr_reader :events
Expand Down
19 changes: 19 additions & 0 deletions test/iruby/kernel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ def setup
@kernel = IRuby::Kernel.instance
end

sub_test_case("iruby_initialized event") do
def setup
super
@initialized_kernel = nil
@callback = IRuby::Kernel.events.register(:initialized) do |kernel|
@initialized_kernel = kernel
end
end

def teardown
IRuby::Kernel.events.unregister(:initialized, @callback)
end

def test_iruby_initialized_event
with_session_adapter("test")
assert_same(IRuby::Kernel.instance, @initialized_kernel)
end
end

def test_execute_request
obj = Object.new

Expand Down

0 comments on commit 911bb7b

Please sign in to comment.