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



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/speccify.rb', line 131

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