Basic usage

Here's an example using rspec-core:

RSpec.describeOrderdoit"sums the prices of the items in its line items"doorder=Order.neworder.add_entry(LineItem.new(:item=>Item.new(:price=>Money.new(1.11,:USD))))order.add_entry(LineItem.new(:item=>Item.new(:price=>Money.new(2.22,:USD),:quantity=>2)))expect(order.total).toeq(Money.new(5.55,:USD))endend

The describe and it methods come from rspec-core. The Order, LineItem, Item and Money classes would be from your code. The last line of the example
expresses an expected outcome. If order.total == Money.new(5.55, :USD), then
the example passes. If not, it fails with a message like:

Predicate matchers

Ranges (Ruby >= 1.9 only)

expect(1..10).tocover(3)

Collection membership

expect(actual).toinclude(expected)expect(actual).tostart_with(expected)expect(actual).toend_with(expected)expect(actual).tocontain_exactly(individual,items)# ...which is the same as:
expect(actual).tomatch_array(expected_array)

Compound Matcher Expressions

Composing Matchers

Many of the built-in matchers are designed to take matchers as
arguments, to allow you to flexibly specify only the essential
aspects of an object or data structure. In addition, all of the
built-in matchers have one or more aliases that provide better
phrasing for when they are used as arguments to another matcher.