lib/assay.rb in assay-0.3.0 vs lib/assay.rb in assay-0.4.0

- old
+ new

@@ -1,44 +1,97 @@ +# Load Assay's assertion classes. +require_relative 'assay/assertion' +dir = File.dirname(__FILE__) + '/assay' +Dir.entries(dir).each do |file| + next if File.extname(file) != '.rb' + require_relative 'assay/' + file +end + module Assay - #VERSION="1.0.0" - # Returns a Hash table of failure classes indexed by - # asserton operator. - def self.failure_classes_by_operator - @_failure_classes_by_operator ||= ( - c = {} - ObjectSpace.each_object(Class) do |fc| - next unless fc < Assay::Assertion - if fc.respond_to?(:assertion_operator) - c[fc.assertion_operator.to_sym] = fc - end - end - c - ) - end - - # Lookup failure class by operator. - def self.lookup(operator) - failure_classes_by_operator[operator.to_sym] - end - + # # Returns Hash table of project metadata. - def self.meta + # + def self.metadata @spec ||= ( require 'yaml' YAML.load(File.new(File.dirname(__FILE__) + '/assay.yml')) ) end + # # Check metadata for missing constants. + # def self.const_missing(name) - meta[name.to_s.downcase] || super(name) + metadata[name.to_s.downcase] || super(name) end -end -# Load Assay's failure classes. -dir = File.dirname(__FILE__) -glob = File.join(dir, 'assay', 'assertions', '*.rb') -Dir[glob].each do |rb| - require 'assay/assertions/' + File.basename(rb) + # + # Returns a list of Assertion subclasses. + # + def self.assertions + Assertion.subclasses + end + + # + # Set ANSI color mode. Default is false, so set to `true` to get ANSI color + # in some error messages. + # + # @example + # Assay.color = true + # + def self.color=(boolean) + if boolean + require 'ansi/diff' + $ansi = true + else + $ansi = false + end + end + + # + # Lookup assay class by operator or name. + # + def self.lookup(symbol) + lookup_by_operator(symbol) || lookup_by_name(symbol) + end + + # + # If operator is not given, returns a hash table of assertion classes + # indexed by operator. + # + def self.lookup_by_operator(operator=nil) + Assertion.by_operator(operator) + end + + # + # If operator is not given, returns a hash table of assertion classes + # indexed by assertive name. + # + def self.lookup_by_name(name=nil) + Assertion.by_name(name) + end + + # This module serves as the primary container for traditonal style assertion + # methods, which can be mixed in to one's testing scope (e.g. World). + # + module Assertions + end + + # This module holds the subject matcher methods, which can be mixin + # to one's testing scope (e.g. World). + # + module Matchers + end + + # This module holds the assertion extension mehods, which are mixed into + # the Object class. + # + module Extensions + end + + #class ::Object + # include Assay::Extensions + #end + end