Sha256: 535cdf1f537eb23dfa59f8aca2118b4443007ae6d210d54a8136581a5e216c2d

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

module Matchy
  module Modals
    # Tests an expectation against the given object.
    #
    # ==== Examples
    # 
    #   "hello".should eql("hello")
    #   13.should equal(13)
    #   lambda { raise "u r doomed" }.should raise_error
    #
    def should(expectation = nil)
      if expectation
        match_expectation(expectation, true)
      else
        return Matchy::Expectations::OperatorExpectation.new(self, true)
      end
    end
    
    # Tests that an expectation doesn't match the given object.
    #
    # ==== Examples
    # 
    #   "hello".should_not eql("hi")
    #   41.should_not equal(13)
    #   lambda { "savd bai da bell" }.should_not raise_error
    #
    def should_not(expectation = nil)
      if expectation
        match_expectation(expectation, false)
      else
        return Matchy::Expectations::OperatorExpectation.new(self, false)
      end
    end
    
    protected
    def match_expectation(expectation, match)
      if expectation.matches?(self) != match
        expectation.fail!(match)
      else
        expectation.pass!(match)
      end
    end
  end
end

Object.send(:include, Matchy::Modals)

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
jeremymcanally-matchy-0.0.1 lib/matchy/modals.rb
lucashungaro-matchy-0.0.2 lib/matchy/modals.rb