Saturday, February 14, 2009

BDD WxRuby applications with Cucumber and Nobbie

For a long time now, I've been wanting to write some Cucumber features to describe a WxRuby application I have. A couple of weeks ago, I found a library called wx-nobbie on Rubyforge that seems to be almost exactly what I was looking for.  It provides a simple, high level interface for driving WxRuby applications through commands like "click", "choose" and "type".  I had a little trouble getting the tests to pass to start with, but with a few minor tweaks I got there.  I contacted the original author and got his permission to take it forward.

I created a GitHub repository for Wx-Nobbie and have made a few updates over the last week.  Currently, I've got 4 feature scenarios with 10 steps:

C:\dev\wx-nobbie>rake features
(in C:/dev/wx-nobbie)
In order to test drive a WxRuby application  # features/acceptance_test.feature
As a developer
I want Nobbie to provide acceptance test access to the application
  Scenario: Choosing a radio button  # features/acceptance_test.feature:5
    Then "radio_button" is not chosen# features/step_definitions/acceptance_test_steps.rb:21
    When I choose "radio_button"     # features/step_definitions/acceptance_test_steps.rb:1
    Then "radio_button" is chosen    # features/step_definitions/acceptance_test_steps.rb:17

  Scenario: Choosing a check box  # features/acceptance_test.feature:10
    Then "check_box" is not chosen# features/step_definitions/acceptance_test_steps.rb:21
    When I choose "check_box"     # features/step_definitions/acceptance_test_steps.rb:1
    Then "check_box" is chosen    # features/step_definitions/acceptance_test_steps.rb:17

  Scenario: Type into a text control        # features/acceptance_test.feature:15
    When I type "123" into "text_ctrl"      # features/step_definitions/acceptance_test_steps.rb:5
    Then I should see "123" in "text_ctrl"  # features/step_definitions/acceptance_test_steps.rb:9

  Scenario: Type into a combo box           # features/acceptance_test.feature:19
    When I type "456" into "combo_box"      # features/step_definitions/acceptance_test_steps.rb:5
    Then I should see "456" in "combo_box"  # features/step_definitions/acceptance_test_steps.rb:9


4 scenarios
10 steps passed

With just these 4 scenarios, RCov tells me I have 62.9% coverage.

Hurrah!

No comments :

Post a Comment