Skip to content

Commit 3ee6699

Browse files
committed
Refactor test specifications for improved readability and consistency
- Adjusted indentation in the Azu router and general test specifications to enhance clarity and maintainability. - Ensured consistent formatting across test cases, aligning with the project's focus on performance and type safety. These changes contribute to a more organized and readable test suite, facilitating easier maintenance and understanding of the test logic.
1 parent 90e0f95 commit 3ee6699

3 files changed

Lines changed: 25 additions & 26 deletions

File tree

spec/azu/router_spec.cr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ describe Azu::Router do
267267
response = HTTP::Server::Response.new(io)
268268
context = HTTP::Server::Context.new(request, response)
269269

270-
# First call should build and cache the path
270+
# First call should build and cache the path
271271
router.process(context)
272272
response.close
273273

@@ -277,7 +277,7 @@ describe Azu::Router do
277277
first_response = io.gets_to_end
278278
first_response.should contain("Hello, World!")
279279

280-
# Second call should use cached path
280+
# Second call should use cached path
281281
io2 = IO::Memory.new
282282
response2 = HTTP::Server::Response.new(io2)
283283
context2 = HTTP::Server::Context.new(HTTP::Request.new("GET", "/hello"), response2)
@@ -289,7 +289,7 @@ describe Azu::Router do
289289
second_response.should contain("Hello, World!")
290290
end
291291

292-
it "handles WebSocket upgrade paths correctly" do
292+
it "handles WebSocket upgrade paths correctly" do
293293
router = Azu::Router.new
294294

295295
# Register a WebSocket route for testing
@@ -330,7 +330,7 @@ describe Azu::Router do
330330
end
331331
end
332332

333-
it "handles path normalization correctly" do
333+
it "handles path normalization correctly" do
334334
router = Azu::Router.new
335335
endpoint = SimpleEndpoint.new
336336
router.get("/test", endpoint)
@@ -341,7 +341,7 @@ describe Azu::Router do
341341
response = HTTP::Server::Response.new(io)
342342
context = HTTP::Server::Context.new(request, response)
343343

344-
router.process(context)
344+
router.process(context)
345345
response.close
346346
io.rewind
347347
result = io.gets_to_end

spec/azu_spec.cr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
require "./spec_helper.cr"
22
require "http/client"
33

4-
54
process = Process.new("./bin/example_app")
65
# Wait for process to start
76
sleep 1.seconds

src/azu/router.cr

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ module Azu
206206

207207
# Create cache key for this specific request combination
208208
cache_key = if upgraded
209-
"ws:#{path_str}"
210-
else
211-
"#{method_str}:#{path_str}"
212-
end
209+
"ws:#{path_str}"
210+
else
211+
"#{method_str}:#{path_str}"
212+
end
213213

214214
# Check cache first
215215
if cached_path = @path_cache.get(cache_key)
@@ -218,22 +218,22 @@ module Azu
218218

219219
# Build path efficiently using pre-allocated capacity
220220
built_path = if upgraded
221-
# WebSocket path: "/ws" + normalized_path
222-
normalized_path = path_str.rstrip('/')
223-
String.build(capacity: 4 + normalized_path.bytesize) do |str|
224-
str << "/ws"
225-
str << normalized_path
226-
end
227-
else
228-
# HTTP path: "/" + method + normalized_path
229-
normalized_path = path_str.rstrip('/')
230-
method_lower = @method_cache[method_str]? || method_str.downcase
231-
String.build(capacity: 1 + method_lower.bytesize + normalized_path.bytesize) do |str|
232-
str << "/"
233-
str << method_lower
234-
str << normalized_path
235-
end
236-
end
221+
# WebSocket path: "/ws" + normalized_path
222+
normalized_path = path_str.rstrip('/')
223+
String.build(capacity: 4 + normalized_path.bytesize) do |str|
224+
str << "/ws"
225+
str << normalized_path
226+
end
227+
else
228+
# HTTP path: "/" + method + normalized_path
229+
normalized_path = path_str.rstrip('/')
230+
method_lower = @method_cache[method_str]? || method_str.downcase
231+
String.build(capacity: 1 + method_lower.bytesize + normalized_path.bytesize) do |str|
232+
str << "/"
233+
str << method_lower
234+
str << normalized_path
235+
end
236+
end
237237

238238
# Cache the result for future requests
239239
@path_cache.set(cache_key, built_path)

0 commit comments

Comments
 (0)