module RubyQA require 'erb' class Test DEFAULT_OPTIONS={ :site => "", :cluster => false, :has_key => "", }.freeze attr_reader :name, :options, :proc def initialize (name, options ={}, &test_block) @tests = Hash.new @name = name @options = DEFAULT_OPTIONS.merge(options) @test = test_block @description = "" if options[:description] @description=options[:description] end end def valid_host(host) ## By default if options weren't changed, then ## we just assume it is to be tested against all ## provided hosts is_valid = 0 if @options == DEFAULT_OPTIONS return true end DEFAULT_OPTIONS.each do |key,value| if @options[key] != value and host[key] != @options[key] return false end end return true end def run (host) test_status = "N/A" if @test.call(host) test_status = "PASSED" else test_status = "FAILED" end @tests[host.name]=test_status end def report if @tests.count == 0 return end template = ERB.new < '-' ============================================== Test : "<%= @name %>" <% if not @description.empty? -%> Description : "<%= @description %> <% end -%> ============================================== <% @tests.each do |key,val| -%> <%= key %> : <%= val %> <% end -%> EOF template.result(binding) end end end