Skip to content
This repository has been archived by the owner on Feb 13, 2020. It is now read-only.

Features

epall edited this page Apr 29, 2011 · 5 revisions

Tests are organized by feature. The tests for a particular feature of application of your application should live in one source file under APP/test/right/features/. For example:

class ShoppingCartFeature < Test::Right::Feature
  def test_adding_item
    with LoginWidget do |w|
      w.login
    end

    with ItemWidget do |w|
      w.add_an_item
    end

    with CartWidget do |w|
      assert {
        w.number_of_items == 1
    end
  end
end

with

To perform actions on a Widget, use with, passing it the class of the widget you want to work with:

class ShoppingCartFeature < Test::Right::Feature
  def test_adding_item
    with LoginWidget do |w|
      w.login
    end
  end

The with method will automatically wait for the widget to appear and attach an object to the widget on the page for you to perform actions on. The object is passed to the the block as the only parameter.

You can also use named widgets in a with block:

class ShoppingCartFeature < Test::Right::Feature
  def test_adding_item
    with ItemWidget["shoes"] do |w|
      w.add_to_cart
    end
  end

This will attach w to the particular instance of the ItemWidget named by "shoes".

wait_for

If you just want to wait for a widget to become present on a page, you can use wait_for:

class ShoppingCartFeature < Test::Right::Feature
  def test_adding_item
    with ItemWidget["shoes"] do |w|
      w.add_to_cart
    end

    wait_for CartItemWidget["shoes"]
  end

data

Hard-coded literal strings in your tests are a recipe for data dependency and fragility. Use the Data Factory whenever you need a unique identifier to avoid clashes between tests.

class AdminFeature < Test::Right::Feature
  def test_creating_item
    item_name = data[:item]
    with ItemAdminWidget do |w|
      w.create_item(item_name)
    end

    wait_for ItemWidget[item_name]
  end
Clone this wiki locally