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 !!)
(背景:虽然之前我一直想尝试 rspec stories,可是因为时间的紧迫,最终我还是使用了传统的‘鼠标点击/眼睛观察’方式,我必须承认,这是非常没有效率和让我气恼的方式,特别我是个程序员!!我最憎恨的就是这种耗时间,>耗人力的测试方式。这一会,我有机会使用 merb 来开发新的项目,而这一回,我告诉自己,我要全自动化的测试!!而正好,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:
其实到底 rspec stories 和 cucumber 有多大的差别,我不太晓得,毕竟我没用过前者。不过,cucumber 应该更好吧>,否则,rspec stories 也不会逐步让 cucumber 替代了。在我们开始玩 cucumber 前,让我们来准备一下我们的开发环境吧:

#$ 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:
在写这篇 blog 时,以上的指令将安装 merb-1.0。接下来,让我们安装 cucumber,webrat 和 merb_cucumber,这些的源代码可从以下 github 库中获取:

* 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.
在写这篇 blog 时
,以上将安装:cucumber-0.1.9, webrat-0.3.1 和 merb_cucumber-0.3。

Just a quick check to ensure things are OK:
让我们确保一切 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).
好啦,今天就到此为止。下一篇 blog 将为 Playing with Merb+Cucumber+Webrat (1)

No comments: