RSpec Expectations

Install

If you want to use rspec-expectations with rspec, just install the rspec gem
and RubyGems will also install rspec-expectations for you (along with
rspec-core and rspec-mocks):

gem install rspec

If you want to use rspec-expectations with another tool, like Test::Unit,
Minitest, or Cucumber, you can install it directly:

gem install rspec-expectations

Basic usage

Here's an example using rspec-core:

describe Order do
it "sums the prices of the items in its line items" do
order = Order.new
order.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
)
order.total.should eq(Money.new(5.55, :USD))
end
end

The describe and it methods come from rspec-core. The Order, LineItem,
and Item 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: