RSpec is a Test Framework for Ruby! And RSpec is just awesome! It is the best Test Framework I know. Add this 2 lines to your Gemfile to the test group and the development group.

gem 'rspec-rails', '2.8.0'
gem 'webrat', '0.7.3'

Webrat is browser simulator. With RSpec and Webrat you can write integration tests and test the UI of your Web App!

Assume you have a simple class like that:

class Bowling
  def hit(pins)

  def score

Than your RSpec Code would look like that:

require 'bowling'

describe Bowling, "#score" do
  it "returns 0 for all gutter game" do
    bowling =
    20.times { bowling.hit(0) }
    bowling.score.should eq(0)

In RSpec you don’t write tests, you write specifications. You describe a class and how it should behave! The name of a “test method” / “specification” is a regular string. I t can be a whole sentence or two!

Published by Robert Reiz

CEO @ VersionEye. Passionated software developer since 1998.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: