Class: Speccify::OperatorMatcherProxy

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

Overview

Functions

Class Method Summary collapse

Class Method Details

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

:nodoc:



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/speccify.rb', line 143

def self.create given, loc, type = true  # :nodoc:
  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) ? true : false), msg)
      end
    end
  end

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