Skip to content

Commit

Permalink
test: remove rubocop security warnings from TestCase
Browse files Browse the repository at this point in the history
- change implicit Kernel.open to ::File.open
- replace `eval` with `define_method`
  • Loading branch information
flavorjones committed Jan 30, 2021
1 parent 63f8779 commit 5b30aed
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/mechanize/test_case.rb
Expand Up @@ -230,9 +230,9 @@ def request(req, *data, &block)
else
filename = "htdocs#{path.gsub(/[^\/\\.\w\s]/, '_')}"
unless PAGE_CACHE[filename]
open("#{Mechanize::TestCase::TEST_DIR}/#{filename}", 'rb') { |io|
::File.open("#{Mechanize::TestCase::TEST_DIR}/#{filename}", 'rb') do |io|
PAGE_CACHE[filename] = io.read
}
end
end

res.body = PAGE_CACHE[filename]
Expand Down
2 changes: 1 addition & 1 deletion lib/mechanize/test_case/gzip_servlet.rb
Expand Up @@ -13,7 +13,7 @@ def do_GET(req, res)
end

if name = req.query['file'] then
open "#{TEST_DIR}/htdocs/#{name}" do |io|
::File.open("#{TEST_DIR}/htdocs/#{name}") do |io|
string = String.new
zipped = StringIO.new string, 'w'
Zlib::GzipWriter.wrap zipped do |gz|
Expand Down
10 changes: 4 additions & 6 deletions lib/mechanize/test_case/verb_servlet.rb
@@ -1,11 +1,9 @@
class VerbServlet < WEBrick::HTTPServlet::AbstractServlet
%w[HEAD GET POST PUT DELETE].each do |verb|
eval <<-METHOD
def do_#{verb}(req, res)
res.header['X-Request-Method'] = #{verb.dump}
res.body = #{verb.dump}
end
METHOD
define_method "do_#{verb}" do |req, res|
res.header['X-Request-Method'] = verb
res.body = verb
end
end
end

0 comments on commit 5b30aed

Please sign in to comment.