class Umami::Test::Integration
Attributes
test_root[R]
Public Class Methods
new(root_dir)
click to toggle source
Calls superclass method
Umami::Test::new
# File lib/chef-umami/test/integration.rb, line 26 def initialize(root_dir) super @test_root = File.join(self.root_dir, 'umami', 'integration') end
Public Instance Methods
framework()
click to toggle source
InSpec doesn't need a require statement to use its tests. We define framework
here for completeness.
# File lib/chef-umami/test/integration.rb, line 33 def framework 'inspec' end
generate(recipe_resources = {})
click to toggle source
# File lib/chef-umami/test/integration.rb, line 68 def generate(recipe_resources = {}) test_files_written = [] recipe_resources.each do |canonical_recipe, resources| (cookbook, recipe) = canonical_recipe.split('::') content = [preamble(cookbook, recipe)] resources.each do |resource| content << write_test(resource) end test_file_name = test_file_path(cookbook, recipe) test_file_content = content.join("\n") + "\n" write_file(test_file_name, test_file_content) test_files_written << test_file_name end enforce_styling(test_root) unless test_files_written.empty? puts 'Wrote the following integration tests:' test_files_written.each do |f| puts "\t#{f}" end end end
method_missing(meth, *args, &block)
click to toggle source
If the test framework's helper module doesn't provide support for a given test-related method, return a friendly message. Raise NoMethodError for any other failed calls.
# File lib/chef-umami/test/integration.rb, line 59 def method_missing(meth, *args, &block) case meth when /^test_/ "# #{meth} is not currently defined. Stay tuned for updates." else raise NoMethodError end end
preamble(cookbook = '', recipe = '')
click to toggle source
# File lib/chef-umami/test/integration.rb, line 41 def preamble(cookbook = '', recipe = '') "# #{test_file_path(cookbook, recipe)} - Originally written by Umami!" end
test_file_path(cookbook = '', recipe = '')
click to toggle source
# File lib/chef-umami/test/integration.rb, line 37 def test_file_path(cookbook = '', recipe = '') "#{test_root}/#{cookbook}_#{recipe}_spec.rb" end
write_test(resource = nil)
click to toggle source
Call on the apprpriate method from the Umami::Helper::InSpec
module to generate our test.
# File lib/chef-umami/test/integration.rb, line 47 def write_test(resource = nil) if resource.action.is_a? Array return if resource.action.include?(:delete) end return if resource.action == :delete "\n" + send("test_#{resource.declared_type}", resource) end