Module: SiteFuel::External::ExternalProgramTestCase

Defined in:
lib/sitefuel/external/ExternalProgramTestCase.rb

Constant Summary collapse

@@message_posted =
{}

Instance Method Summary collapse

Instance Method Details

#get_tested_classObject



30
31
32
33
34
35
36
37
38
# File 'lib/sitefuel/external/ExternalProgramTestCase.rb', line 30

def get_tested_class
  name = self.class.to_s.gsub(/^(.*?::)?Test(.*)$/, "\\2")
  
  # ensure the class exists
  cls = Kernel.const_get(name)
  
  return cls if cls != nil
  return nil
end

#initialize(*args) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/sitefuel/external/ExternalProgramTestCase.rb', line 40

def initialize(*args)
  cls = get_tested_class
  unless cls == nil
    if cls.program_found?
      # amusing pun.
      super(*args)
    else
      if not @@message_posted[self.class]
        puts "Ignoring #{cls} unit tests. Program #{cls.program_name} not found.".bold
        @@message_posted[self.class] = true
      end
      
      # fun part. Over-ride every method beginning with test* so they are nops
      methods = self.methods
      methods.each do |name|
        if name =~ /^test.*$/
          self.class.publicly_define_method(name) {}
        end
      end

      super(*args)
    end
  end
end