mirror of
				https://gitea.invidious.io/iv-org/shard-kemal.git
				synced 2024-08-15 00:53:36 +00:00 
			
		
		
		
	Refactor class level DSL with macros to convert blocks to instance-scoped methods
This commit is contained in:
		
							parent
							
								
									53fa65f964
								
							
						
					
					
						commit
						ad91a22789
					
				
					 6 changed files with 179 additions and 51 deletions
				
			
		|  | @ -8,6 +8,10 @@ private class MyApp < Kemal::Application | |||
|   get "/route2" do |env| | ||||
|     "Route 2" | ||||
|   end | ||||
| 
 | ||||
|   get "/file" do |env| | ||||
|     send_file env, "Serdar".to_slice | ||||
|   end | ||||
| end | ||||
| 
 | ||||
| describe MyApp do | ||||
|  | @ -24,4 +28,23 @@ describe MyApp do | |||
|       end | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|   it "sends file with binary stream" do | ||||
|     request = HTTP::Request.new("GET", "/file") | ||||
|     response = call_request_on_app(MyApp.new, request) | ||||
|     response.status_code.should eq(200) | ||||
|     response.headers["Content-Type"].should eq("application/octet-stream") | ||||
|     response.headers["Content-Length"].should eq("6") | ||||
|   end | ||||
| 
 | ||||
|   it "responds to delayed route" do | ||||
|     app = MyApp.new | ||||
|     app.setup | ||||
|     app.get "/delayed" do |env| | ||||
|       "Happy addition!" | ||||
|     end | ||||
|     request = HTTP::Request.new("GET", "/delayed") | ||||
|     client_response = call_request_on_app(app, request) | ||||
|     client_response.body.should eq("Happy addition!") | ||||
|   end | ||||
| end | ||||
|  |  | |||
|  | @ -42,7 +42,7 @@ describe "Macros" do | |||
|       client_response.body.should eq("world") | ||||
| 
 | ||||
|       app.get "/breaking" do |env| | ||||
|         halt env, 404, "hello" | ||||
|         Kemal::Macros.halt env, 404, "hello" | ||||
|         "world" | ||||
|       end | ||||
|       request = HTTP::Request.new("GET", "/breaking") | ||||
|  | @ -54,7 +54,7 @@ describe "Macros" do | |||
|     it "can break block with halt macro using default values" do | ||||
|       app = Kemal::Base.new | ||||
|       app.get "/" do |env| | ||||
|         halt env | ||||
|         Kemal::Macros.halt env | ||||
|         "world" | ||||
|       end | ||||
|       request = HTTP::Request.new("GET", "/") | ||||
|  | @ -69,7 +69,7 @@ describe "Macros" do | |||
|       app = Kemal::Base.new | ||||
|       app.get "/headers" do |env| | ||||
|         env.response.headers.add "Content-Type", "image/png" | ||||
|         headers env, { | ||||
|         app.headers env, { | ||||
|           "Access-Control-Allow-Origin" => "*", | ||||
|           "Content-Type"                => "text/plain", | ||||
|         } | ||||
|  | @ -85,7 +85,7 @@ describe "Macros" do | |||
|     it "sends file with given path and default mime-type" do | ||||
|       app = Kemal::Base.new | ||||
|       app.get "/" do |env| | ||||
|         send_file env, "./spec/asset/hello.ecr" | ||||
|         app.send_file env, "./spec/asset/hello.ecr" | ||||
|       end | ||||
| 
 | ||||
|       request = HTTP::Request.new("GET", "/") | ||||
|  | @ -98,7 +98,7 @@ describe "Macros" do | |||
|     it "sends file with given path and given mime-type" do | ||||
|       app = Kemal::Base.new | ||||
|       app.get "/" do |env| | ||||
|         send_file env, "./spec/asset/hello.ecr", "image/jpeg" | ||||
|         app.send_file env, "./spec/asset/hello.ecr", "image/jpeg" | ||||
|       end | ||||
| 
 | ||||
|       request = HTTP::Request.new("GET", "/") | ||||
|  | @ -111,7 +111,7 @@ describe "Macros" do | |||
|     it "sends file with binary stream" do | ||||
|       app = Kemal::Base.new | ||||
|       app.get "/" do |env| | ||||
|         send_file env, "Serdar".to_slice | ||||
|         app.send_file env, "Serdar".to_slice | ||||
|       end | ||||
| 
 | ||||
|       request = HTTP::Request.new("GET", "/") | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue