Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add start and stop callbacks #1913

Merged
merged 10 commits into from
Jul 11, 2023
Prev Previous commit
Next Next commit
Add tests for callbacks
  • Loading branch information
jevin committed Jun 22, 2023
commit c5656c69b6e7316de10d0bbd7d054d760e6f1473
39 changes: 39 additions & 0 deletions test/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ def stop
register 'mock', 'Rack::Handler::Mock'
end

class EventHookTest
def self.start
end

def self.stop
end
end
dentarg marked this conversation as resolved.
Show resolved Hide resolved

class ServerTest < Minitest::Test
setup do
mock_app do
Expand All @@ -45,6 +53,37 @@ def teardown
@app.run!
end

context "event hooks" do
it "runs the provided code when the server starts" do
@app.on_start do
EventHookTest.start
end
mock = MiniTest::Mock.new
mock.expect(:call, nil)

EventHookTest.stub(:start, mock) do
@app.run!
end

assert_mock mock
end

it "runs the provided code when the server stops" do
@app.on_stop do
EventHookTest.stop
end
mock = MiniTest::Mock.new
mock.expect(:call, nil)

EventHookTest.stub(:stop, mock) do
@app.run!
@app.quit!
end

assert_mock mock
end
end

it "sets options on the app before running" do
@app.run! :sessions => true
assert @app.sessions?
Expand Down