Skip to content

mdoel/cukesteps

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cukesteps

cukesteps is a gem containing general purpose step definitions for the Cucumber BDD framework.

Cucumber provides a single webrat_steps.rb file containing generic steps. This gem provides more.

The steps fall into three basic categories:

  • object creation steps

  • general debugging/development steps

  • content matching steps

Object creation step(s)

Right now, there’s just one and it is of the form:

Given the following foo(s) exist

This is expected to be used with a step table and allows for complex associations to be built up in concise language. Consider an application with models for restaurant, brand, employee, and location. Brand instances are pre-seeded into your database (e.g. for dropdown lists and other similar uses). You might want to create a test world like:

Scenario: Linked objects with parent object defined first
  Given the following restaurants exist
    | restaurant | Location   | Brand     |
    | mcd-miami  | Miami, fl  | McDonalds |
    | chip-cols  | Columbus   | Chipotle  |
  Given the following employees exist
    | name    | restaurant |
    | joe     | mcd-miami  |
    | sally   | chip-cols  |
    | william | chip-cols  |
  Then 2 restaurants should exist
  And 3 employees should exist
  And the "Chipotle" restaurant in "Columbus" has 2 employees

If you put the following in your features/support/env.rb file:

cuke_association_attributes(:brand => :name,
                            :location => :address)

then each Restaurant object gets created and associated with three other model objects:

  • Brand - via a find_by_name lookup inside the brands table

  • Location - via the return of the create_location(:address => address) factory method (e.g. from FixtureReplacemnt)

  • Employee - from the objects created in the previous step

For items passed to the cuke_association_attributes method, the basic logic used in finding the objects to use for the association is:

  • Try a find_by_attribute method. If that returns a non-nil value, it is used. Otherwise

  • Use a FixtureReplacement-like create_model factory method built from the attribute and value

General Debugging/Development steps

These steps are not typically ones you would leave inside your cucumber features file as they are primarily useful if you are trying to debug some issue rather than doing true acceptance testing.

Then I debug

Use this in the middle of a scenario to stop running the scenario and dump you into the ruby debugger at this point.

Then save_and_open_page

This uses webrats save_and_open_page method to capture the output of your scenario at some point and open it in your browser.

Then n foos should exist

Verifies that the count of Foo records is n

Then dump all foos to standard output

Dumps the output of inspect for all ActiveRecord instances of Foo

Content Matching Steps

These steps help encourage use of semantic IDs and Class Names in your markup. The use of the articles “a” and “the” represent a class and ID respectively. For example, “I should see a photo in the search results” ensures that the the page contains an element of class photo inside an element of ID search-results.

The steps available here are:

  • Then I should see the foo (e.g. Then I should see the search-results)

  • Then I should see a|an foo (e.g. Then I should see a listing)

  • Then I should see a foo in the bar (e.g. Then I should see a listing in the search-results)

  • Then I should see the foo in the bar (e.g. Then I should see the map in the search-results)

  • Then I should see n foos in the bar (e.g. Then I should see 4 listings in the search-results)

  • Then I should see n to m foos in the bar (e.g. Then I should see 3 to 5 listings in the search-results)

  • Then the baz in the bar should contain a foo (e.g. Then the map in the search-results should contain a resizer)

  • Then the page title should be “Login”

  • Then the page title should contain “Login”

  • Then flash should display “your update succeeded!” notice

The negation of each of the above is also available (e.g. Then I should not see a listing in the search-results)

Installation/Use

To install the gem, use:

gem sources add github.com   (only need to do this once)
gem install mdoel-cukesteps

To use it, add the following to your features/support/env.rb file:

require 'mdoel-cukesteps'
include CukeAssociationhelpers
cuke_association_attributes(:model1 => :attribute_1
                            :model2 => :attribute_2)

To Do

  • incorporate better testing (right now, testing is in a separate cukesteps-test project)

  • make this documentation better

Copyright © 2009 Mike Doel. See LICENSE for details.

About

General purpose step definitions for Cucumber

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages