lib/inspec/runner.rb in inspec-0.9.7 vs lib/inspec/runner.rb in inspec-0.9.8
- old
+ new
@@ -6,10 +6,11 @@
require 'uri'
require 'inspec/backend'
require 'inspec/profile_context'
require 'inspec/targets'
+require 'inspec/metadata'
# spec requirements
require 'rspec'
require 'rspec/its'
require 'inspec/rspec_json_formatter'
@@ -44,25 +45,40 @@
def configure_transport
@backend = Inspec::Backend.create(@conf)
end
- def add_tests(tests)
+ def add_test_profile(test, ignore_supports = false)
+ assets = Inspec::Targets.resolve(test, @conf)
+ meta_assets = assets.find_all { |a| a[:type] == :metadata }
+ metas = meta_assets.map do |x|
+ Inspec::Metadata.from_ref(x[:ref], x[:content], @profile_id, @conf[:logger])
+ end
+ metas.each do |meta|
+ return [] unless ignore_supports || meta.supports_transport?(@backend)
+ end
+ assets
+ end
+
+ def add_tests(tests, options = {})
# retrieve the raw ruby code of all tests
items = tests.map do |test|
- Inspec::Targets.resolve(test)
+ add_test_profile(test, options[:ignore_supports])
end.flatten
tests = items.find_all { |i| i[:type] == :test }
libs = items.find_all { |i| i[:type] == :library }
# Ensure each test directory exists on the $LOAD_PATH. This
# will ensure traditional RSpec-isms like `require 'spec_helper'`
# continue to work.
tests.flatten.each do |test|
- test_directory = File.dirname(test[:ref])
- $LOAD_PATH.unshift test_directory unless $LOAD_PATH.include?(test_directory)
+ # do not load path for virtual files, eg. from zip
+ if !test[:ref].nil?
+ test_directory = File.dirname(test[:ref])
+ $LOAD_PATH.unshift test_directory unless $LOAD_PATH.include?(test_directory)
+ end
end
# add all tests (raw) to the runtime
tests.flatten.each do |test|
add_content(test, libs)
@@ -79,9 +95,10 @@
# load all libraries
ctx = create_context
libs.each do |lib|
ctx.load(lib[:content].to_s, lib[:ref], lib[:line] || 1)
+ ctx.reload_dsl
end
# evaluate the test content
ctx.load(content, test[:ref], test[:line] || 1)