Class: Speccify::OperatorMatcherProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/speccify.rb

Class Method Summary collapse

Class Method Details

.create(given, loc, type = true) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/speccify.rb', line 105

def self.create given, loc, type = true
  body = lambda do |klass|
    define_method(:initialize) do |given|
      @given = given
    end

    ['==', '===', '=~', '>', '>=', '<', '<='].each do |operator|
      define_method(operator) do |actual|
        print_given  = (@given == nil) ? "nil" : @given
        print_actual = (type ? "" : "not ") + (actual.nil? ? "nil" : actual.to_s)
        msg = Speccify::Functions::message(print_actual, print_given, operator, loc) 
        $current_spec.assert(type == @given.send(operator,actual), msg)
      end
    end
  end

  return Class.new(&body).new(given)
end