Alex Rivera | Logout

What is the best way to start Unit and Functional testing of a Ruby Rails website?

Asked 2008-09-26T22:48:34.917
11

I am testing a Ruby Rails website and wanted to get started with Unit and Functional testing.

Edit
Report

2 Answers

6

Cucumber and RSpec are worth a look. They encourage testing in a behaviour-driven, example-based style.

RSpec is a library for unit-level testing:

describe "hello_world"
  it "should say hello to the world" do
    # RSpec comes with its own mock-object framework built in,
    # though it lets you use others if you prefer
    world = mock("World", :population => 6e9)
    world.should_receive(:hello)
    hello_world(world)
  end
end

It has special support for Rails (e.g. it can test models, views and controllers in isolation) and can replace the testing mechanisms built in to Rails.

Cucumber (formerly known as the RSpec Story Runner) lets you write high-level acceptance tests in (fairly) plain English that you could show to (and agree with) a customer, then run them:

Story: Commenting on articles

  As a visitor to the blog
  I want to post comments on articles
  So that I can have my 15 minutes of fame

  Scenario: Post a new comment

    Given I am viewing an article
    When I add a comment "Me too!"
    And I fill in the CAPTCHA correctly
    Then I should see a comment "Me too!"
answered 2008-09-26T23:58:37.010
1

You can also test out the web interface with a Firefox plug-in such as http://selenium.openqa.org/

It will record clicks and text entry and then plays back and will check the page for the correct display elements.

answered 2008-09-29T14:23:24.280

Your Answer