Class: CustomMatcher

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

Overview

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected = nil) ⇒ CustomMatcher

Returns a new instance of CustomMatcher.



10
11
12
# File 'lib/rspec/custom_matcher.rb', line 10

def initialize(expected = nil)
  @expected = expected
end

Class Method Details

.create(class_name, &block) ⇒ Object



4
5
6
7
8
# File 'lib/rspec/custom_matcher.rb', line 4

def self.create(class_name, &block)
  klass = Class.new(CustomMatcher)
  klass.send(:define_method, :matcher, &block) if block_given?
  Object.const_set(build_class_name(class_name), klass)
end

Instance Method Details

#failure_messageObject



14
15
16
# File 'lib/rspec/custom_matcher.rb', line 14

def failure_message
  message
end

#matcher(target, expected) ⇒ Object



22
23
24
# File 'lib/rspec/custom_matcher.rb', line 22

def matcher(target, expected)
  target == expected
end

#matches?(target) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
# File 'lib/rspec/custom_matcher.rb', line 26

def matches?(target)
  @target = target
  if self.method(:matcher).arity == 2
    matcher(@target, @expected)
  else
    matcher(@target)
  end
end

#negative_failure_messageObject



18
19
20
# File 'lib/rspec/custom_matcher.rb', line 18

def negative_failure_message
  message(false)
end