Module: WSOC::Specs

Included in:
CourseSpecs
Defined in:
lib/wsoc/specs.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/wsoc/specs.rb', line 23

def self.included(base)
  base.module_eval do
    def self.hash
      @@specs_hash ||= {}
    end

    def self.specs
      self.hash[:specs] ||= []
    end

    def self.
      self.hash[:metadata] ||= {}
    end

    def self.should(behavior,options)
      self.specs << {:behavior => behavior}.merge(options)
    end

    def self.map(host,port=nil)
      prefix = "http://#{host}"
      prefix << ":#{port}" if (port && port != 80)

      return {
        :metadata => self.,
        :specs => self.specs.map { |spec|
          unless spec[:url] =~ /^[a-zA-Z0-9]+:/
            spec.merge(:url => prefix + spec[:url])
          else
            spec
          end
        }
      }
    end

    protected

    def self.config(name,value)
      self.[name.to_sym] = value
    end

    def self.should_visit(url,message=nil)
      self.should(:visit,:url => url, :message => message)
    end

    def self.should_ignore(url,message=nil)
      self.should(:ignore,:url => url, :message => message)
    end

    def self.should_fail(url,message=nil)
      self.should(:fail,:url => url, :message => message)
    end
  end
end