Skip to content

Commit

Permalink
Merge pull request #12 from chef/schisamo/helpers-support
Browse files Browse the repository at this point in the history
support test suite helpers
  • Loading branch information
chris-rock committed Dec 7, 2015
2 parents 7c52f03 + edc6d9f commit 209d9d9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
12 changes: 11 additions & 1 deletion lib/kitchen/verifier/inspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def call(state)
raise Kitchen::UserError, "Verifier #{name}",
" does not support the #{name} Transport"
end
tests = local_suite_files
tests = helper_files + local_suite_files

runner = ::Inspec::Runner.new(runner_options)
runner.add_tests(tests)
Expand All @@ -74,6 +74,16 @@ def load_needed_dependencies!
require "inspec"
end

# Returns an Array of common helper filenames currently residing on the
# local workstation.
#
# @return [Array<String>] array of helper files
# @api private
def helper_files
glob = File.join(config[:test_base_path], "helpers", "*/**/*")
Dir.glob(glob).reject { |f| File.directory?(f) }
end

# Returns an Array of test suite filenames for the related suite currently
# residing on the local workstation. Any special provisioner-specific
# directories (such as a Chef roles/ directory) are excluded.
Expand Down
39 changes: 32 additions & 7 deletions spec/kitchen/verifier/inspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,20 @@
end

let(:test_files) do
%w[base_spec.rb another_spec.rb supporting.rb other.json]
%w(
inspec/base_spec.rb
inspec/another_spec.rb
inspec/supporting.rb
inspec/other.json
)
end

let(:helper_files) do
%w(
inspec/spec_helper.rb
inspec/support/custom.rb
inspec/support/more_custom.rb
)
end

before do
Expand Down Expand Up @@ -153,10 +166,13 @@
it "adds *spec.rb test files to runner" do
create_test_files
allow(Inspec::Runner).to receive(:new).and_return(runner)
expect(runner).to receive(:add_tests).with([
File.join(config[:test_base_path], "germany", "another_spec.rb"),
File.join(config[:test_base_path], "germany", "base_spec.rb")
])
expect(runner).to receive(:add_tests).with(array_including([
File.join(config[:test_base_path], "germany", "inspec", "another_spec.rb"),
File.join(config[:test_base_path], "germany", "inspec", "base_spec.rb"),
File.join(config[:test_base_path], "helpers", "inspec", "spec_helper.rb"),
File.join(config[:test_base_path], "helpers", "inspec", "support", "custom.rb"),
File.join(config[:test_base_path], "helpers", "inspec", "support", "more_custom.rb")
]))

verifier.call(Hash.new)
end
Expand Down Expand Up @@ -220,12 +236,21 @@
end
end

def create_file(file, content)
FileUtils.mkdir_p(File.dirname(file))
File.open(file, "wb") { |f| f.write(content) }
end

def create_test_files
base = File.join(config[:test_base_path], "germany")
hbase = File.join(config[:test_base_path], "helpers")

test_files.map { |f| File.join(base, f) }.each do |file|
FileUtils.mkdir_p(File.dirname(file))
File.open(file, "wb") { |f| f.write("hello") }
create_file(file, 'hello')
end

helper_files.map { |f| File.join(hbase, f) }.each do |file|
create_file(file, 'hello')
end
end
end

0 comments on commit 209d9d9

Please sign in to comment.