module RSpecial::Matchers

This module provides matchers for RSpec-compatiblity.

The set is not fully compataible, but provides most RSpec matchers. The most notable exlusion for the moment is the ‘have` matchers.

Compatability will improve with time. Feel obligated to submit a patch if you really need it. ;)

@see www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers

Public Instance Methods

be_a(cls)
Alias for: be_kind_of
be_a_kind_of(cls)
Alias for: be_kind_of
be_an(cls)
Alias for: be_kind_of
be_an_instance_of(cls)
Alias for: be_instance_of
be_close(delta, criterion) click to toggle source

Passes if expected and actual are nto equal within delta tolerance.

value.should be_close(delta, criterion)

@raise WithinAssay

# File lib/rspecial/matchers.rb, line 42
def be_close(delta, criterion)
  WithinAssay.assertor(criterion, delta)
end
be_empty() click to toggle source

Passes if object is empty.

object.should be_empty

@raise EmptyAssay

# File lib/rspecial/matchers.rb, line 52
def be_empty
  EmptyAssay.assertor
end
be_false() click to toggle source

Passed if object is false.

value.should be_false

@raise FalseAssay

# File lib/rspecial/matchers.rb, line 88
def be_false
  FalseAssay.assertor
end
be_identical_to(obj)
Alias for: equal
be_instance_of(cls) click to toggle source

Passes if object is an instance of class.

object.should be_instance_of(class)

@raise InstanceAssay

# File lib/rspecial/matchers.rb, line 123
def be_instance_of(cls)
  InstanceAssay.assertor(cls)
end
Also aliased as: be_an_instance_of
be_kind_of(cls) click to toggle source

Pass if object is a kind of class.

object.should be_kind_of(class)

@raise KindAssay

# File lib/rspecial/matchers.rb, line 136
def be_kind_of(cls)
  KindAssay.assertor(cls)
end
Also aliased as: be_a_kind_of, be_a, be_an
be_like(criterion) click to toggle source

Passes if the expected and actual are alike.

object.should be_like(criterion)

There is no equivalant for this in RSpec, we simply add it here to cover all Assays available.

@raise LikeAssay

# File lib/rspecial/matchers.rb, line 32
def be_like(criterion)
  LikeAssay.assertor(criterion)
end
be_nil() click to toggle source

Pass if object is nil.

value.should be_nil

@raise NilAssay

# File lib/rspecial/matchers.rb, line 162
def be_nil
  NilAssay.assertor
end
be_true() click to toggle source

Passed if object is true.

object.should be_true

@raise TrueAssay

# File lib/rspecial/matchers.rb, line 223
def be_true
  TrueAssay.assertor
end
eq(obj) click to toggle source

Passes if ‘actual == expected`.

object.should eq(object)

@raise EqualAssay

# File lib/rspecial/matchers.rb, line 112
def eq(obj)
  EqualAssay.assertor(obj)
end
eql(exp) click to toggle source

Pass if two objects are equal using ‘#eql?` method.

object1.should eql(object2)

@raise EqualityAssay

# File lib/rspecial/matchers.rb, line 198
def eql(exp)
  EqualityAssay.assertor(exp)
end
equal(obj) click to toggle source

Passes if actual is the same exact object as expected.

object.should be_identical_to(object)

@raise IdentityAssay

# File lib/rspecial/matchers.rb, line 99
def equal(obj)
  IdentityAssay.assertor(obj)
end
Also aliased as: be_identical_to
equate_to(exp) click to toggle source

Passes if expected == actual.

'MY STRING'.should equate_to('my string'.upcase)
'MY STRING'.should_not equate_to('another string')

This matcher is not supported by RSpec, but is added so that the EqualityAssay has an explict matcher available.

@raise EqualityAssay

# File lib/rspecial/matchers.rb, line 66
def equate_to(exp)
  EqualityAssay.assertor(exp)
end
expect(target) click to toggle source
# File lib/rspecial/matchers.rb, line 252
def expect(target)
  Expect.new(target)
end
have(n) click to toggle source
# File lib/rspecial/matchers.rb, line 230
def have(n)
  Have.new(n)
end
Also aliased as: have_exactly
have_at_least(n) click to toggle source
# File lib/rspecial/matchers.rb, line 239
def have_at_least(n)
  Have.new(n, :at_least)
end
have_at_most(n) click to toggle source
# File lib/rspecial/matchers.rb, line 246
def have_at_most(n)
  Have.new(n, :at_most)
end
have_exactly(n)
Alias for: have
match(regexp) click to toggle source

Pass if object matches pattern using ‘#=~` method.

object.should match(regexp)

@raise MatchAssay

# File lib/rspecial/matchers.rb, line 151
def match(regexp)
  MatchAssay.assertor(regexp)
end
raise_error(exception=Exception) click to toggle source

Pass if an exception is raised.

lambda { do_something_risky }.should raise_error
lambda { do_something_risky }.should raise_error(PoorRiskDecisionError)

@raise RaiseAssay

@todo Support for message matching ?

# File lib/rspecial/matchers.rb, line 176
def raise_error(exception=Exception)
  RaiseAssay.assertor(exception)
end
respond_to(method) click to toggle source

Pass if object responds to message.

object.should respond_to(:method_name)

@raise RespondAssay

# File lib/rspecial/matchers.rb, line 187
def respond_to(method)
  RespondAssay.assertor(method)
end
satisfy(&block) click to toggle source

Passes if block is satisfied given target object as argument.

5.should satisfy{ |n| n > 3}

@raise ExecutionAssay

# File lib/rspecial/matchers.rb, line 77
def satisfy(&block)
  ExecutionAssay.assertor(&block)
end
throw_symbol(sym=nil) click to toggle source

Pass if procedure throws a specified symbol.

lambda { do_something_risky }.should throw_symbol
lambda { do_something_risky }.should throw_symbol(:that_was_risky)

@raise ThrowAssay

@todo Support for throw argument. (Does RSpec even support this?)

# File lib/rspecial/matchers.rb, line 212
def throw_symbol(sym=nil) #, arg=nil)
  ThrowAssay.assertor(sym)
end