@@ -59,6 +59,12 @@ def response_object.to_response
5959 expect ( response . status ) . to be == 404
6060 end
6161
62+ it "rejects options for the default application" do
63+ expect do
64+ subject . default ( unexpected : true )
65+ end . to raise_exception ( ArgumentError )
66+ end
67+
6268 it "loads a top-level application constant" do
6369 Dir . mktmpdir do |directory |
6470 path = File . join ( directory , "application.rb" )
@@ -80,6 +86,42 @@ def response_object.to_response
8086 end
8187 end
8288
89+ it "passes options to application classes" do
90+ Dir . mktmpdir do |directory |
91+ path = File . join ( directory , "application.rb" )
92+
93+ File . write ( path , <<~RUBY )
94+ require "utopia/application"
95+
96+ class Application < Utopia::Application
97+ def initialize(message:)
98+ delegate = Protocol::HTTP::Middleware.for do |request|
99+ Utopia::Response.text(message)
100+ end
101+
102+ super(delegate)
103+ end
104+ end
105+ RUBY
106+
107+ application = subject . load ( path , message : "Hello" )
108+ response = application . call ( http_request )
109+
110+ expect ( response . status ) . to be == 200
111+ expect ( response . read ) . to be == "Hello"
112+ end
113+ end
114+
115+ it "uses the default application if the configuration file does not exist" do
116+ Dir . mktmpdir do |directory |
117+ path = File . join ( directory , "missing.rb" )
118+ application = subject . load ( path , ignored : true )
119+ response = application . call ( http_request )
120+
121+ expect ( response . status ) . to be == 404
122+ end
123+ end
124+
83125 it "uses the default application if no application constant is defined" do
84126 Dir . mktmpdir do |directory |
85127 path = File . join ( directory , "application.rb" )
@@ -88,7 +130,7 @@ def response_object.to_response
88130 require "utopia/application"
89131 RUBY
90132
91- application = subject . load ( path )
133+ application = subject . load ( path , ignored : true )
92134 response = application . call ( http_request )
93135
94136 expect ( response . status ) . to be == 404
0 commit comments