# Author:: Nicolas Despres . # Copyright:: Copyright (c) 2004, 2005 Uttk team. All rights reserved. # License:: LGPL # $Id: /w/fey/uttk/trunk/lib/uttk/strategies/Test.rb 8778 2005-09-26T04:34:48.103938Z ertai $ require 'yaml' require 'diff' module Uttk module Strategies # A strategy to test them all. class Test < Proxy include Concrete #FIXME: add support to test filter def initialize(*a, &b) super @outfile = nil end protected def prologue super @outfile = TempPath.new create(@test) end protected def run_impl_test(test, log) test.reject :name, :status, :strategy # FIXME : Try to remove this if possible my_log = nil @outfile.open('w') do |io| my_log = Logger.new(Dumpers::Yaml.new(io)) @returned_status = super(test, my_log) my_log.close if my_log end @returned_status end protected def assertion returned_log = nil @outfile.open { |io| returned_log = YAML.load(io) } unless returned_log.is_a?(Hash) or returned_log.is_a?(Array) raise('the result must be either a hash or an array') end del_ignored_value(returned_log) del_ignored_value(@expected_log) diff = @expected_log.gen_diff(returned_log) {|a, b| a.to_s == b.to_s} if diff.no_diff? pass else @log[:differences] = diff fail('there is differences') end super end protected def epilogue @outfile.clean if @outfile super end protected def del_ignored_value(hash) hash.delete_if {|k, _| @ignored_value.include?(k.to_s)} end attribute :test, 'the test to test', :mandatory, :dont_expand attribute :expected_status, 'the expected status', :mandatory attribute :expected_log, 'the expected log result', :mandatory, :invisible attribute :ignored_value, 'the list of attributes for which the ' + 'value is not compared', [], :invisible do [] end end # class Test end # module Strategies end # module Uttk