Sha256: d7dceaff7903631600436b9d0e16ad0f2d41cba97ff451332cd067287fd35b05

Contents?: true

Size: 1.21 KB

Versions: 15

Compression:

Stored size: 1.21 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
    
    alias :will :should
    
    # 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
    
    alias :will_not :should_not
    alias :wont :should_not
    
    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

15 entries across 15 versions & 2 rubygems

Version Path
adva-0.3.2 test/matchy/lib/matchy/modals.rb
adva-0.3.1 test/matchy/lib/matchy/modals.rb
adva-0.3.0 test/matchy/lib/matchy/modals.rb
adva-0.2.4 test/matchy/lib/matchy/modals.rb
adva-0.2.3 test/matchy/lib/matchy/modals.rb
adva-0.2.2 test/matchy/lib/matchy/modals.rb
adva-0.2.1 test/matchy/lib/matchy/modals.rb
adva-0.2.0 test/matchy/lib/matchy/modals.rb
adva-0.1.4 test/matchy/lib/matchy/modals.rb
adva-0.1.3 test/matchy/lib/matchy/modals.rb
adva-0.1.2 test/matchy/lib/matchy/modals.rb
adva-0.1.1 test/matchy/lib/matchy/modals.rb
adva-0.1.0 test/matchy/lib/matchy/modals.rb
adva-0.0.1 test/matchy/lib/matchy/modals.rb
jeremymcanally-matchy-0.1.0 lib/matchy/modals.rb