Skip to content

Commit

Permalink
rewrite method patch for ruby 1.9.3
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-rock committed Feb 29, 2016
1 parent c803082 commit f4a82dc
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions lib/kitchen/verifier/inspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,23 @@
require 'pathname'

module Kitchen
module DataMungerExtension
# overwrite the verifier_data_for to get access to the suite data
# monkey patch test-kitchen to get the suite information within this verifier,
# since test-kitchen does not allow a proper hook
class DataMunger
# save reference to olf method
alias_method :original_verifier_data_for, :verifier_data_for

def verifier_data_for(suite, platform)
# filter current suite and extract `inspec_tests` and move it to verifier
data.fetch(:suites, []).select { |f| f[:name] == suite }.each do |suite_data|
move_data_to!(:verifier, suite_data, :inspec_tests)
end

# call patched function
super
# run original behaviour
original_verifier_data_for(suite, platform)
end

# TODO: remove, once https://github.com/test-kitchen/test-kitchen/pull/955 is
# merged
# TODO: remove, once https://github.com/test-kitchen/test-kitchen/pull/955 is merged
def move_data_to!(to, root, key)
return unless root.key?(key)
pdata = root.fetch(to, {})
Expand All @@ -48,12 +51,6 @@ def move_data_to!(to, root, key)
end
end

# monkey patch test-kitchen to get the suite information within this verifier,
# since test-kitchen does not allow a proper hook
class DataMunger
prepend DataMungerExtension
end

module Verifier
# InSpec verifier for Kitchen.
#
Expand Down

0 comments on commit f4a82dc

Please sign in to comment.