Skip to content

Commit

Permalink
fix ameba warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mamantoha committed Jan 8, 2024
1 parent adf25a8 commit ca1fcf0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
16 changes: 8 additions & 8 deletions spec/integration/logger_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ require "../spec_helper"

describe Crest::Logger do
it "logs request and response" do
IO.pipe do |r, w|
IO.pipe do |reader, writer|
params = {:width => "100", :height => 100}
logger = Crest::CommonLogger.new(w)
logger = Crest::CommonLogger.new(writer)

Crest::Request.get("#{TEST_SERVER_URL}/get", params: params, logger: logger, logging: true)

data_time = "\\d{4}-\\d{2}-\\d{2} d{2}:\\d{2}:\\d{2}"
url = "#{TEST_SERVER_URL}/get?width=100&height=100"
response_body = "\"Width: 100, height: 100\""

r.gets.should match(Regex.new("crest | #{data_time} | .* GET.* | #{url}"))
r.gets.should match(Regex.new("crest | #{data_time} | .* 200.* | #{url} | #{response_body}"))
reader.gets.should match(Regex.new("crest | #{data_time} | .* GET.* | #{url}"))
reader.gets.should match(Regex.new("crest | #{data_time} | .* 200.* | #{url} | #{response_body}"))
end
end

describe "filters" do
it "filter logs by regex" do
IO.pipe do |r, w|
IO.pipe do |reader, writer|
params = {:width => "100", :height => 100, :api_key => "secret"}
logger = Crest::CommonLogger.new(w)
logger = Crest::CommonLogger.new(writer)
logger.filter(/(api_key=)(\w+)/, "\\1[REMOVED]")

Crest::Request.get("#{TEST_SERVER_URL}/get", params: params, logger: logger, logging: true)
Expand All @@ -30,8 +30,8 @@ describe Crest::Logger do
url = "#{TEST_SERVER_URL}/get?width=100&height=100&api_key=[REMOVED]"
response_body = "\"Width: 100, height: 100\""

r.gets.should match(Regex.new("crest | #{data_time} | .* GET.* | #{url}"))
r.gets.should match(Regex.new("crest | #{data_time} | .* 200.* | #{url} | #{response_body}"))
reader.gets.should match(Regex.new("crest | #{data_time} | .* GET.* | #{url}"))
reader.gets.should match(Regex.new("crest | #{data_time} | .* 200.* | #{url} | #{response_body}"))
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions spec/integration/redirection_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ describe Crest::Redirector do
end

it "should redirect with logger" do
IO.pipe do |r, w|
logger = Crest::CommonLogger.new(w)
IO.pipe do |reader, writer|
logger = Crest::CommonLogger.new(writer)

response = Crest.get("#{TEST_SERVER_URL}/redirect/1", logger: logger, logging: true)

r.gets.should match(/GET/)
r.gets.should match(/302/)
r.gets.should match(/GET/)
r.gets.should match(/200/)
reader.gets.should match(/GET/)
reader.gets.should match(/302/)
reader.gets.should match(/GET/)
reader.gets.should match(/200/)

(response.request.logging).should eq(true)
(response.request.logger).should be_a(Crest::Logger)
Expand Down
8 changes: 4 additions & 4 deletions spec/integration/resource_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,14 @@ describe Crest::Response do
end

it "do GET request with logging" do
IO.pipe do |r, w|
logger = Crest::CommonLogger.new(w)
IO.pipe do |reader, writer|
logger = Crest::CommonLogger.new(writer)

resource = Crest::Resource.new(TEST_SERVER_URL, logger: logger, logging: true)
resource["/get"].get

r.gets.should match(/GET/)
r.gets.should match(/200/)
reader.gets.should match(/GET/)
reader.gets.should match(/200/)
end
end

Expand Down
8 changes: 4 additions & 4 deletions spec/support/server.cr
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,16 @@ get("/redirect_to_secret", &.redirect("/secret"))
post "/upload" do |env|
request_content_type = env.request.headers["Content-Type"]

file =
uploaded_file =
if request_content_type.starts_with?("multipart/form-data")
env.params.files.values.first.tempfile
else
File.tempfile(suffix: MIME.extensions(request_content_type).first) do |f|
env.request.body.try { |body| IO.copy(body, f) }
File.tempfile(suffix: MIME.extensions(request_content_type).first) do |file|
env.request.body.try { |body| IO.copy(body, file) }
end
end

"Upload OK - #{file.path}"
"Upload OK - #{uploaded_file.path}"
end

post "/upload_nested" do |env|
Expand Down
6 changes: 3 additions & 3 deletions src/crest/logger.cr
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ module Crest
end

private def apply_filters(output : String) : String
@filters.each do |f|
pattern = f[0]
replacement = f[1]
@filters.each do |filter|
pattern = filter[0]
replacement = filter[1]

output = output.gsub(pattern, replacement)
end
Expand Down

0 comments on commit ca1fcf0

Please sign in to comment.