Skip to content

Commit

Permalink
Use anonymous class for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jevin committed Jun 21, 2023
1 parent c4d98ac commit d930f92
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions test/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ def stop
register 'mock', 'Rack::Handler::Mock'
end

class EventHookTest
def self.start
end

def self.stop
end
end

class ServerTest < Minitest::Test
setup do
mock_app do
Expand All @@ -54,14 +46,19 @@ def teardown
end

context "event hooks" do
dummy_class = Class.new do
def self.start_hook; end
def self.stop_hook; end
end

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

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

Expand All @@ -70,12 +67,12 @@ def teardown

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

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

0 comments on commit d930f92

Please sign in to comment.