File tree Expand file tree Collapse file tree 3 files changed +27
-3
lines changed Expand file tree Collapse file tree 3 files changed +27
-3
lines changed Original file line number Diff line number Diff line change
1
+ Myapp = lambda { |env | [ 200 , { } , 'this is my app!' ] }
Original file line number Diff line number Diff line change @@ -161,8 +161,16 @@ def load_adapter
161
161
end
162
162
163
163
def load_rackup_config
164
- rackup_code = File . read ( @options [ :rackup ] )
165
- eval ( "Rack::Builder.new {( #{ rackup_code } \n )}.to_app" , TOPLEVEL_BINDING , @options [ :rackup ] )
164
+ case @options [ :rackup ]
165
+ when /\. rb$/
166
+ Kernel . load ( @options [ :rackup ] )
167
+ Object . const_get ( File . basename ( @options [ :rackup ] , '.rb' ) . capitalize . to_sym )
168
+ when /\. ru$/
169
+ rackup_code = File . read ( @options [ :rackup ] )
170
+ eval ( "Rack::Builder.new {( #{ rackup_code } \n )}.to_app" , TOPLEVEL_BINDING , @options [ :rackup ] )
171
+ else
172
+ raise "Invalid rackup file. please specify either a .ru or .rb file"
173
+ end
166
174
end
167
175
end
168
176
end
Original file line number Diff line number Diff line change 63
63
end
64
64
65
65
it "should load app from Rack config" do
66
- @controller . options [ :rackup ] = ' example/config.ru'
66
+ @controller . options [ :rackup ] = File . dirname ( __FILE__ ) + '/../../ example/config.ru'
67
67
@controller . start
68
68
69
69
@server . app . class . should == Proc
70
70
end
71
+
72
+ it "should load app from ruby file" do
73
+ @controller . options [ :rackup ] = filename = File . dirname ( __FILE__ ) + '/../../example/myapp.rb'
74
+ @controller . start
75
+
76
+ @server . app . should == Myapp
77
+ end
78
+
79
+ it "should throwup if rackup is not a .ru or .rb file" do
80
+ proc do
81
+ @controller . options [ :rackup ] = filename = File . dirname ( __FILE__ ) + '/../../example/myapp.foo'
82
+ @controller . start
83
+ end . should raise_error ( RuntimeError , /please/ )
84
+ end
71
85
72
86
it "should set server as threaded" do
73
87
@controller . options [ :threaded ] = true
74
88
@controller . start
75
89
76
90
@server . threaded . should be_true
77
91
end
92
+
78
93
end
79
94
80
95
describe Controller do
You can’t perform that action at this time.
0 commit comments