Module Matchy::Expectations::TestCaseExtensions
In: lib/matchy/built_in/error_expectations.rb
lib/matchy/built_in/truth_expectations.rb
lib/matchy/built_in/change_expectations.rb
lib/matchy/built_in/enumerable_expectations.rb

Methods

External Aliases

method_missing -> old_missing

Public Instance methods

Simply checks if the receiver matches the expected object. TODO: Fill this out to implement much of the RSpec functionality (and then some)

Examples

  "hello".should be("hello")
  (13 < 20).should be(true)

Checks if the given object is within a given object and delta.

Examples

  (20.0 - 2.0).should be_close(18.0)
  (13.0 - 4.0).should be_close(9.0, 0.5)

Asks given for success?(). This is necessary because Rails Integration::Session overides method_missing without grace.

Examples

  @response.should be_success

Checks if the given block alters the value of the block attached to change

Examples

  lambda {var += 1}.should change {var}.by(1)
  lambda {var += 2}.should change {var}.by_at_least(1)
  lambda {var += 1}.should change {var}.by_at_most(1)
  lambda {var += 2}.should change {var}.from(1).to(3) if var = 1

Calls +eql?+ on the given object (i.e., are the objects the same value?)

Examples

   1.should_not eql(1.0)
   (12 / 6).should eql(6)

Calls +equal?+ on the given object (i.e., do the two objects have the same object_id?)

Examples

  x = [1,2,3]
  y = [1,2,3]

  # Different object_id's...
  x.should_not equal(y)

  # The same object_id
  x[0].should equal(y[0])

Expects the receiver to exclude the given object(s). You can provide multiple arguments to see if all of them are included.

Examples

  [1,2,3].should exclude(16)
  [7,8,8].should_not exclude(7)
  ['a', 'b', 'c'].should exclude('e', 'f', 'g')

Calls +exist?+ on the given object.

Examples

  # found_user.exist?
  found_user.should exist

Calls +include?+ on the receiver for any object. You can also provide multiple arguments to see if all of them are included.

Examples

  [1,2,3].should include(1)
  [7,8,8].should_not include(3)
  ['a', 'b', 'c'].should include('a', 'c')

be_*something(*args)

This method_missing acts as a matcher builder.

If a call to be_xyz() reaches this method_missing (say: obj.should be_xyz), a matcher with the name xyz will be built, whose defining property is that it returns the value of obj.xyz? for matches?.

Examples

  nil.should be_nil
  17.should be_kind_of(Fixnum)
  obj.something? #=> true
  obj.should be_something

Expects a lambda to raise an error. You can specify the error or leave it blank to encompass any error.

Examples

  lambda { raise "FAILURE." }.should raise_error
  lambda { puts i_dont_exist }.should raise_error(NameError)

Checks if the given object responds to the given method

Examples

  "foo".should respond_to(:length)
  {}.should respond_to(:has_key?)

A last ditch way to implement your testing logic. You probably shouldn‘t use this unless you have to.

Examples

  (13 - 4).should satisfy(lambda {|i| i < 20})
  "hello".should_not satisfy(lambda {|s| s =~ /hi/})

Expects a lambda to throw an error.

Examples

  lambda { throw :thing }.should throw_symbol(:thing)
  lambda { "not this time" }.should_not throw_symbol(:hello)

[Validate]