summaryrefslogtreecommitdiff
path: root/spec/support/shared/functional
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2021-12-17 08:57:33 -0800
committerTim Smith <tsmith84@gmail.com>2021-12-17 08:57:33 -0800
commit06c650886daa2a6eaf4c029cbf686ff401d44c48 (patch)
tree414a5bc2f8c7a5f07702a01c3fcb71b67026f189 /spec/support/shared/functional
parentdf9b3881518297274bebfac3c348d69f3de52197 (diff)
downloadchef-simplified_read.tar.gz
Simplify file readssimplified_read
This is a new RuboCop cop that moves things to file.read an file.binread vs. an open and then a read. Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'spec/support/shared/functional')
-rw-r--r--spec/support/shared/functional/file_resource.rb2
-rw-r--r--spec/support/shared/functional/http.rb18
2 files changed, 10 insertions, 10 deletions
diff --git a/spec/support/shared/functional/file_resource.rb b/spec/support/shared/functional/file_resource.rb
index 1385d3dc30..b31982a2d9 100644
--- a/spec/support/shared/functional/file_resource.rb
+++ b/spec/support/shared/functional/file_resource.rb
@@ -391,7 +391,7 @@ shared_examples_for "a configured file resource" do
end
def binread(file)
- content = File.open(file, "rb", &:read)
+ content = File.binread(file)
content.force_encoding(Encoding::BINARY) if "".respond_to?(:force_encoding)
content
end
diff --git a/spec/support/shared/functional/http.rb b/spec/support/shared/functional/http.rb
index ffe52e2148..d3d4531371 100644
--- a/spec/support/shared/functional/http.rb
+++ b/spec/support/shared/functional/http.rb
@@ -30,7 +30,7 @@ module ChefHTTPShared
end
def binread(file)
- content = File.open(file, "rb", &:read)
+ content = File.binread(file)
content.force_encoding(Encoding::BINARY) if "".respond_to?(:force_encoding)
content
end
@@ -51,19 +51,19 @@ module ChefHTTPShared
# just a normal file
# (expected_content should be uncompressed)
@api.get("/nyan_cat.png", 200) do
- File.open(nyan_uncompressed_filename, "rb", &:read)
+ File.binread(nyan_uncompressed_filename)
end
# this ends in .gz, we do not uncompress it and drop it on the filesystem as a .gz file (the internet often lies)
# (expected_content should be compressed)
@api.get("/nyan_cat.png.gz", 200, nil, { "Content-Type" => "application/gzip", "Content-Encoding" => "gzip" } ) do
- File.open(nyan_compressed_filename, "rb", &:read)
+ File.binread(nyan_compressed_filename)
end
# this is an uncompressed file that was compressed by some mod_gzip-ish webserver thingy, so we will expand it
# (expected_content should be uncompressed)
@api.get("/nyan_cat_compressed.png", 200, nil, { "Content-Type" => "application/gzip", "Content-Encoding" => "gzip" } ) do
- File.open(nyan_compressed_filename, "rb", &:read)
+ File.binread(nyan_compressed_filename)
end
#
@@ -75,7 +75,7 @@ module ChefHTTPShared
{
"Content-Length" => nyan_uncompressed_size.to_s,
}) do
- File.open(nyan_uncompressed_filename, "rb", &:read)
+ File.binread(nyan_uncompressed_filename)
end
# (expected_content should be uncompressed)
@@ -85,7 +85,7 @@ module ChefHTTPShared
"Content-Type" => "application/gzip",
"Content-Encoding" => "gzip",
}) do
- File.open(nyan_compressed_filename, "rb", &:read)
+ File.binread(nyan_compressed_filename)
end
#
@@ -97,7 +97,7 @@ module ChefHTTPShared
{
"Content-Length" => (nyan_uncompressed_size + 1).to_s,
}) do
- File.open(nyan_uncompressed_filename, "rb", &:read)
+ File.binread(nyan_uncompressed_filename)
end
# (expected_content should be uncompressed)
@@ -107,7 +107,7 @@ module ChefHTTPShared
"Content-Type" => "application/gzip",
"Content-Encoding" => "gzip",
}) do
- File.open(nyan_compressed_filename, "rb", &:read)
+ File.binread(nyan_compressed_filename)
end
#
@@ -120,7 +120,7 @@ module ChefHTTPShared
"Content-Length" => (nyan_uncompressed_size + 1).to_s,
"Transfer-Encoding" => "anything",
}) do
- File.open(nyan_uncompressed_filename, "rb", &:read)
+ File.binread(nyan_uncompressed_filename)
end
#