Class: Minitest::MustWonted::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest/mustwonted/matcher.rb

Overview

The actual matcher engine

Class Method Summary collapse

Class Method Details

.add(name, klass) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/minitest/mustwonted/matcher.rb', line 22

def add(name, klass)
  Minitest::Spec.instance_eval do
    define_method name do |*args|
      klass.new *args
    end
  end

  if defined?(ActiveSupport)
    ActiveSupport::TestCase.instance_eval do
      define_method name do |*args|
        klass.new *args
      end
    end
  end
end

.must(subject, matcher = nil, flipped = false) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/minitest/mustwonted/matcher.rb', line 7

def must(subject, matcher=nil, flipped=false)
  if matcher == nil
    Minitest::MustWonted::Matcher::Awesome.new(subject, flipped)
  elsif matcher.respond_to?(:match?)
    matcher.match?(subject, flipped)
    subject # returning the reference to the subject in case of chained calls
  else
    raise "Your matcher supposed to have method called: 'match?'"
  end
end

.wont(subject, matcher = nil) ⇒ Object



18
19
20
# File 'lib/minitest/mustwonted/matcher.rb', line 18

def wont(subject, matcher=nil)
  must subject, matcher, true
end