Merge pull request #4648 from inspec/zenspider/resource-fixes

Fixed problem with accessing backend in TestDslLazyLoader#method_missing.
This commit is contained in:
Ryan Davis 2019-10-31 14:10:07 -07:00 committed by GitHub
commit 637e9cf0b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 17 deletions

View file

@ -50,8 +50,8 @@ module Inspec
def method_missing(method_name, *arguments, &block)
# see if it is a resource first
begin
inspec = inspec if respond_to?(:inspec) # backend not available??
resource = Inspec::DSL.method_missing_resource(inspec, method_name, *arguments)
backend = inspec if respond_to?(:inspec) # backend not available??
resource = Inspec::DSL.method_missing_resource(backend, method_name, *arguments)
return resource if resource
rescue LoadError
# pass through

View file

@ -34,6 +34,8 @@ module Inspec
attr_reader :backend, :rules
attr_accessor :target_profiles
attr_accessor :test_collector
def attributes
Inspec.deprecate(:rename_attributes_to_inputs, "Don't call runner.attributes, call runner.inputs")
inputs

View file

@ -151,6 +151,20 @@ class Minitest::Test
def skip_windows!
skip_until 2019, 12, 4, "These have never passed" if windows?
end
def unmock(&blk)
# eg: resource = unmock { group "staff" }
require "fetchers/mock"
require "inspec/runner"
# TODO: there is WAY too much magic going on in here
runner = Inspec::Runner.new
runner.add_target("inspec.yml" => "name: inspec-shell")
profile = runner.target_profiles.first
ctx = profile.runner_context
ctx.load blk
end
end
class InspecTest < Minitest::Test

View file

@ -36,22 +36,9 @@ describe "Inspec::Resources::Group" do
_(resource.gid).must_equal 0
end
def unmock(&blk)
require "fetchers/mock"
require "inspec/runner"
# TODO: there is WAY too much magic going on in here
runner = Inspec::Runner.new
runner.add_target("inspec.yml" => "name: inspec-shell")
profile = runner.target_profiles.first
ctx = profile.runner_context
ctx.load blk
end
if osx?
it "actually verifies group on mac" do
resource = unmock { group "staff" }
resource = quick_resource(:group, :osx104, "staff")
_(resource.exists?).must_equal true
_(resource.members).must_include "root"
_(resource.members).must_include ENV["LOGNAME"]

View file

@ -3,9 +3,40 @@
require "helper"
require "inspec/secrets"
require "inspec/runner"
require "fetchers/mock"
describe Inspec::Runner do
let(:runner) { Inspec::Runner.new({ command_runner: :generic }) }
let(:runner) { Inspec::Runner.new({ command_runner: :generic, reporter: [] }) }
it "bug #4524" do
file = <<-RUBY
describe "a thing" do
before(:all) { command("true") }
it("should pass") {}
end
RUBY
runner.add_target("bug4524.rb" => file)
runner.load
result = RSpec::Core::Runner.new(nil).run_specs(runner.test_collector.tests)
_(result).must_equal 0
end
it "bug #4587" do
file = <<-RUBY
describe "a thing" do
subject! { command("true") }
its("exit_status") { should eq 0 }
end
RUBY
runner.add_target("bug4587.rb" => file)
runner.load
result = RSpec::Core::Runner.new(nil).run_specs(runner.test_collector.tests)
_(result).must_equal 0
end
# =============================================================== #
# Reporter Options