Monday, November 10, 2008

Setting Up Merb+Cucumber+Webrat

(BACKGROUND: Even though i've very much like to write rspec stories for my previous project, due to time constraint, i have eventually rely on the traditional click-and-observe on my browser, which i must admit is very INEFFICIENT and FRUSTRATING, and it makes me hate myself for resorting to such non-programmer approach. I HATE SUCH MANUAL TESTING. This time round, i'm starting on a new merb project and i swear to myself, i'm going to automate all tests !!! No more click-and-observe in my browser !! And i'm just in time for the new kid in the block ... CUCUMBER !!)

How much different is cucumber from rspec's stories, i never know since i've never work with stories. But it should be better, given the fact that rspec is phasing out its stories in favour of it. Now, lets get our dev environment ready. By following this merb google group thread, these are the steps i've done to get things up and running:

#$ gem install merb

While writing this post, the above installs merb-1.0. Next, we are going to install cucumber, webrat and merb_cucumber from the following sources:

* git://github.com/brynary/webrat.git
* git://github.com/david/merb_cucumber.git
* git://github.com/aslakhellesoy/cucumber.git

To install:

#$ git-clone [project_src]
#$ cd [project_dir]
#$ rake install

At the point of this writing, the above installs cucumber-0.1.9, webrat-0.3.1 and merb_cucumber-0.3.

Just a quick check to ensure things are OK:

#$ merb-gen app playground
#$ cd playground
#$ merb-gen cucumber --session-type webrat
#$ rake features

And you should see something as followings (minus the difference in colors):

Feature: Login  # features/login.feature
To ensure the safety of the application
A regular user of the system
Must authenticate before using the app
Scenario: Failed Login # features/login.feature:6
Given I am not authenticated # features/steps/login_steps.rb:1
When I go to /login # features/steps/common_webrat.rb:4
And I fill in "login" with "i_dont_exist" # features/steps/common_webrat.rb:16
And I fill in "password" with "and_i_dont_have_a_password" # features/steps/common_webrat.rb:16
And I press "Log In" # features/steps/common_webrat.rb:8
Then the login request should fail # features/steps/common_result_steps.rb:13
Then I should see an error message # features/steps/common_result_steps.rb:9

7 steps passed

Finished in 0.042779 seconds

0 examples, 0 failures

Well, that's all for today. The next post will be Playing with Merb+Cucumber+Webrat (1).

No comments: