Ruby On Rails, Design, Simplicity, Web 2.0, Ajax, Mac and Tons of Pizza.

Jun 04

David Chelimsky: Integration Testing With Rspec's Story Runner

Posted by Annalisa Afeltra in Ruby on Rails - comments are closed digg this add to delicious

Most of you know RSpec’s, the Rails plugin used for generating Unit test intuitive and elegant, with Story Runner RSpec it makes its entrance triumphant in the world of Integration Test.

Introduction:

This is a tool that integrates with BDD (Behaviour-driven-development), which is programming describing what the program expects from us. Dan North wrote JBehave, which inspired Story Runner. the BDD take part of the second generation development of agile technology.

RSpec started from a post from Dan Astels and is programmed from Steven Baker. It has started two years ago and is passed to David Chelimsky.

The principle that it is based on is the Feature Injection (Christ Matts): extracting the story from the functionality of the application and dividing this story in the background.

How do they create this story? Using the methodology of why? Here is an example; let suppose that we want to create a Rails application that manages the registration of people to the RailsConf and we apply to this the why methodology process:

“I want the people to register” why? “I want to measure the influence at the conference.”

At this point it is necessary to create a story that describes in some way the extend of the second affirmation.

Some Definitions:

Integration Testing: Make it in a way that the components function well together (in reality David confirms that the are many diverse definitions of Integration Testing but this is the one that is accepted from the Rails Community)

BDD: Before the code exists: Write what you expect from the code when the code is written: checking that the expectations are respected.

RSpec StoryTelling:

RSpec Story Telling is in essence a way of describing the story that tells a particular flow on the inside of our application. similar stories are mapped through DSL to the blocks of code. Following similar blocks you can determine if the application is more or less coherent with the story described.

Here is an example:


Story: Project

    As a user 
    I want to create projects
    In order to start planning

    Scenario: Create the first project as Account Admin

        Given demo_account_admin as current_user with password xxx
        And with all the projects archived
        When click on /accountadmin/projects/new
        And choose the project context
        And set name as 'My first test project'
        And set vision as 'The magnificent creation of RSpec'
        And post to /accountadmin/projects
        Then flash must contain 'Project successfully created' as info


Each story is formated with: title, summary, and many scenarios that did not merit functionally but must follow a predefined structure (what is the objective? who is using the system? What is the action?

The scenario can use the following verbs: Give, When, Then that describe the initial conditions, actions and final conditions (anticipated).

The phrases formatted in the scenarios with these 3 verbs are then “linked” to blocks of code, some of the phrases can be imagined in a variable.

Some possible implementations:

Rails StoryTelling gives the possibility to access all the methods of Rails to all the methods of RSpec.

Webrat (Bryan Helmkamp), serves to manipulate the dom simulating the server-side navigation on the inside of the page.

In place of the Webrat you can use Selenium-RC, this option has its advantages (javascript support) and from confidence to the clients but pays its price in terms of slowness.

Annalisa

Comments

  • Ben

    Posted on June 13

    I like the article Annalisa. I also wrote an article on using RSpec stories, see the URL above. I hope you find it useful. Ben...

Post a comment

Categories:

Tags:

Powered by Mephisto, Valid XHTML 1.1, Valid CSS - Supported by Wave Factory