TDD with RSpec – Spec::Expectations and Expression Matchers

Spec::Expectations lets you set expectations on your object by adding 2 methods to Object. 

These are:
should(matcher=nil)
  should_not(matcher=nil)
E.g.

result.should == 42

result.should be_an_instance_of Book

Both methods take an optional Expression Matcher.
As well as defined Expression Matchers RSpec can create custom Matchers on the fly. A Ruby predicate is a method ending with a ?  and returns true or false. 

E.g.
[].should be_empty => [].empty? #passes
[].should_not be_empty => [].empty? #fails
As well as be_ you can also use “be_a_” and “be_an_”. E.g. 
  3.should be_an_instance_of(Fixnum) => 3.instance_of?(Fixnum) #passes
Note that as of 2.11 RSpec includes a new variant to this syntax.
i.e. the old syntax is:
foo.should eq(bar)
foo.should_not eq(bar)
and the new:
expect(foo).to eq(bar)
expect(foo).not_to eq(bar)
There’s a rather good post about this here: