mirror of
https://github.com/inspec/inspec
synced 2025-02-16 22:18:38 +00:00
Address and fix all our ruby 2.7 warnings & errors.
This does NOT include fixes for our dependencies that are also having 2.7 warnings (which cause our functional tests to fail because for some reason we expect stderr to be empty, which is brittle). I've got upstream PRs to fix all of those. My tests pass locally. I could push a commit that modifies the Gemfile to use my forks, but I'd like to see how this fares for now. Signed-off-by: Ryan Davis <zenspider@chef.io>
This commit is contained in:
parent
73e149611e
commit
f2e4fb549c
7 changed files with 28 additions and 12 deletions
|
@ -205,15 +205,21 @@ module Inspec::Fetcher
|
|||
@temp_archive_path = archive.path
|
||||
end
|
||||
|
||||
def open(target, opts) # overridden so we can control who we're talking to
|
||||
URI.open(target, opts)
|
||||
rescue NoMethodError # TODO: remove when we drop ruby 2.4
|
||||
super(target, opts) # Kernel#open
|
||||
end
|
||||
|
||||
def open_via_uri(target)
|
||||
opts = http_opts
|
||||
|
||||
if opts[:http_basic_authentication]
|
||||
# OpenURI does not support userinfo so we need to remove it
|
||||
open(target.sub("#{@target_uri.userinfo}@", ""), opts)
|
||||
else
|
||||
open(target, opts)
|
||||
end
|
||||
# OpenURI does not support userinfo so we need to remove it
|
||||
# https://ruby-doc.org/stdlib-2.5.0/libdoc/open-uri/rdoc/OpenURI/OpenRead.html#method-i-open
|
||||
target = target.sub("#{@target_uri.userinfo}@", "") if
|
||||
opts[:http_basic_authentication]
|
||||
|
||||
open(target, opts)
|
||||
end
|
||||
|
||||
def download_archive(path)
|
||||
|
|
|
@ -431,7 +431,13 @@ module Inspec::Plugin::V2
|
|||
end
|
||||
|
||||
# find all gem specification directories
|
||||
directories = [Gem::Specification.default_specifications_dir]
|
||||
|
||||
spec_dir = if Gem.respond_to? :default_specifications_dir
|
||||
Gem.default_specifications_dir
|
||||
else
|
||||
Gem::Specification.default_specifications_dir
|
||||
end
|
||||
directories = [spec_dir]
|
||||
unless defined?(::Bundler)
|
||||
# add in any others that do not start with the user directory
|
||||
directories += Gem::Specification.dirs.find_all do |path|
|
||||
|
|
|
@ -96,7 +96,7 @@ module Inspec::Resources
|
|||
|
||||
def parse_csv_result(cmd)
|
||||
require "csv"
|
||||
table = CSV.parse(cmd.stdout, { headers: true })
|
||||
table = CSV.parse(cmd.stdout, headers: true)
|
||||
|
||||
# remove first row, since it will be a seperator line
|
||||
table.delete(0)
|
||||
|
|
|
@ -254,7 +254,7 @@ RSpec::Matchers.define :cmp do |first_expected| # rubocop:disable Metrics/BlockL
|
|||
return actual.send(op, expected.to_i)
|
||||
elsif expected.is_a?(String) && boolean?(expected) && [true, false].include?(actual)
|
||||
return actual.send(op, to_boolean(expected))
|
||||
elsif expected.is_a?(Integer) && integer?(actual)
|
||||
elsif expected.is_a?(Integer) && actual.is_a?(String) && integer?(actual)
|
||||
return actual.to_i.send(op, expected)
|
||||
elsif expected.is_a?(Float) && float?(actual)
|
||||
return actual.to_f.send(op, expected)
|
||||
|
|
|
@ -56,9 +56,14 @@ require "minitest/autorun"
|
|||
|
||||
require "rspec/core/dsl"
|
||||
module RSpec::Core::DSL
|
||||
class << self
|
||||
alias expose_globally! expose_globally! # alias prevents duplicate warning
|
||||
end
|
||||
# rubocop:disable Lint/DuplicateMethods
|
||||
def self.expose_globally!
|
||||
# do nothing
|
||||
end
|
||||
# rubocop:enable Lint/DuplicateMethods
|
||||
end
|
||||
require "rspec"
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
require "helper"
|
||||
require "inspec/resource"
|
||||
require "inspec/resources/http"
|
||||
Faraday::Error::ClientError = ::Faraday::ClientError # TODO/HACK push upstream to faraday_middleware
|
||||
require "faraday_middleware/response/follow_redirects"
|
||||
|
||||
describe "Inspec::Resources::Http" do
|
||||
|
|
|
@ -115,7 +115,7 @@ describe "Inspec::Resources::JSON" do
|
|||
end
|
||||
|
||||
it "good stdout, empty stderr" do
|
||||
resource = run_json_cmd %(ruby -rjson -e "h={'result'=>true}; puts h.to_json")
|
||||
resource = run_json_cmd %(#{Gem.ruby} -rjson -e "h={'result'=>true}; puts h.to_json")
|
||||
|
||||
assert_equal %({"result":true}), resource.raw_content.chomp
|
||||
assert_equal({ "result" => true }, resource.params)
|
||||
|
@ -136,7 +136,7 @@ describe "Inspec::Resources::JSON" do
|
|||
end
|
||||
|
||||
it "empty stdout, empty stderr" do
|
||||
resource = run_json_cmd %{ruby -e "exit 1"}
|
||||
resource = run_json_cmd %{#{Gem.ruby} -e "exit 1"}
|
||||
|
||||
assert_resource_failed resource, "No JSON output, STDERR was empty"
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue