Saturday, October 18, 2008

Behaivour-driven development using plain Chinese story

This blog post is talking about how to use rspec and cucumber in Ruby to make behavior driven development with plain story in Chinese language.

It seems behaviour-driven development is getting more and more popular in recent days. If you are still not sure what BDD is, take a look at following links:

1] Introducing BDD by Dan North
2] Beyond Test Driven Development: Behaviour Driven Development, Google Talk, by Dave Astels
3] Behaviour Driven Development with RSpec, RubyConf 2007, by David Chelimsky, Dave Astels

The most interesting feature of BDD is using stories of plain text as the test cases. Here the story text itself is not only the description of the application's functionality, but also the executable acceptance criterion of application's behavior. Let's have a look at the story example of a calculator addition feature:
Feature: Addition
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers

Scenario: Add two numbers
Given I have entered 50 into the calculator
And I have entered 70 into the calculator
When I press add
Then the result should be 120 on the screen
And the result class should be Fixnum
Both developers and customers can benefit from above story since it is in plain text and easily understood. The further question you might ask is that if it is possible to use spoken languages other than English to write our BDD stories? The answer is "definitely yes!". Thanks to the cucumber -- the new RSpec's Story Runner. Multiple spoken languages support is a built-in feature of cucumber.

The first step is to install cucumber, make sure you have install rpsec. You can install cucumber from gem:
gem install cucumber
or building gem yourself:
git clone git://github.com/aslakhellesoy/cucumber.git
cd cucumber
rake install_gem
The keyword translation for Chinese language in cucumber is defined as following:
"zh-CN":
feature: 功能
scenario: 场景
given_scenario: 引用场景
given: 假如
when: 当
then: 那么
and: 而且
but: 但是

OK, let's write our story in Chinese:
功能:加法
为了避免一些愚蠢的错误
作为一个数学白痴
我希望有人告诉我数字相加的结果

场景: 两个数相加
假如我已经在计算器里输入6
而且我已经在计算器里输入7
当我按相加按钮
那么我应该在屏幕上看到的结果是13

场景: 三个数相加
假如我已经在计算器里输入6
而且我已经在计算器里输入7
而且我已经在计算器里输入1
当我按相加按钮
那么我应该在屏幕上看到的结果是14

Save the plain text in Chinese to a file, here we give it name "addition.feature". Now we can run this feature in command line:
> cucumber --language zh-CN addition.feature
You should see following output:
功能:加法  # addition.feature
为了避免一些愚蠢的错误
作为一个数学白痴
我希望有人告诉我数字相加的结果

场景: 两个数相加 # addition.feature:6
假如 我已经在计算器里输入6 # addition.feature:7
而且 我已经在计算器里输入7 # addition.feature:8
当 我按相加按钮 # addition.feature:9
那么 我应该在屏幕上看到的结果是13 # addition.feature:10

场景: 三个数相加 # addition.feature:12
假如 我已经在计算器里输入6 # addition.feature:13
而且 我已经在计算器里输入7 # addition.feature:14
而且 我已经在计算器里输入1 # addition.feature:15
当 我按相加按钮 # addition.feature:16
那么 我应该在屏幕上看到的结果是14 # addition.feature:17

9 steps pending

You can use these snippets to implement pending steps:

假如 /^我已经在计算器里输入6$/ do
end

假如 /^我已经在计算器里输入7$/ do
end

当 /^我按相加按钮$/ do
end

那么 /^我应该在屏幕上看到的结果是13$/ do
end

假如 /^我已经在计算器里输入1$/ do
end

那么 /^我应该在屏幕上看到的结果是14$/ do
end

See pending step notification? Yes, that is because we haven't defined the steps for this feature. Before we define the steps, we might first consider writing our calculator code. Following is a simple implementation. Here we add a silly bug(The initial sum is not 0 but 1) to let cucumber report it.

class Calculator
def push(n)
@args ||= []
@args << n
end

def
add
@args.inject(1){|n,sum| sum+=n}
end
end
Save the code to a local file within the same directory of your feature file. Now let's define the step matcher for addition feature with Calculator class defined above.
require 'spec'
require 'calculator'

Before do
@calc = Calculator.new
end

After do
end

Given "我已经在计算器里输入$n" do |n|
@calc.push n.to_i
end

When /我按(.*)按钮/ do |op|
if op == '相加'
@result = @calc.send "add"
end
end

Then /我应该在屏幕上看到的结果是(.*)/ do |result|
@result.should == result.to_f
end

Now run the feature again, you should see:
功能:加法  # addition.feature
为了避免一些愚蠢的错误
作为一个数学白痴
我希望有人告诉我数字相加的结果

场景: 两个数相加 # addition.feature:6
假如 我已经在计算器里输入6 # calculator_steps.rb:11
而且 我已经在计算器里输入7 # calculator_steps.rb:11
当 我按相加按钮 # calculator_steps.rb:15
那么 我应该在屏幕上看到的结果是13 # calculator_steps.rb:21
expected: 13.0,
got: 14 (using ==) (Spec::Expectations::ExpectationNotMetError)
./calculator_steps.rb:22:in `那么 /461021457224505745453450456117457125447012473413451060473204477323463634463057(.*)/'
addition.feature:10:in `那么 我应该在屏幕上看到的结果是13'

场景: 三个数相加 # addition.feature:12
假如 我已经在计算器里输入6 # calculator_steps.rb:11
而且 我已经在计算器里输入7 # calculator_steps.rb:11
而且 我已经在计算器里输入1 # calculator_steps.rb:11
当 我按相加按钮 # calculator_steps.rb:15
那么 我应该在屏幕上看到的结果是14 # calculator_steps.rb:21
expected: 14.0,
got: 15 (using ==) (Spec::Expectations::ExpectationNotMetError)
./calculator_steps.rb:22:in `那么 /461021457224505745453450456117457125447012473413451060473204477323463634463057(.*)/'
addition.feature:17:in `那么 我应该在屏幕上看到的结果是14'

Lets change the calculator class to fix the bug:
class Calculator
def push(n)
@args ||= []
@args << n
end

def
add
@args.inject(0){|n,sum| sum+=n}
end
end
And run cucumber again, you should see:
功能:加法  # addition.feature
为了避免一些愚蠢的错误
作为一个数学白痴
我希望有人告诉我数字相加的结果

场景: 两个数相加 # addition.feature:6
假如 我已经在计算器里输入6 # calculator_steps.rb:11
而且 我已经在计算器里输入7 # calculator_steps.rb:11
当 我按相加按钮 # calculator_steps.rb:15
那么 我应该在屏幕上看到的结果是13 # calculator_steps.rb:21

场景: 三个数相加 # addition.feature:12
假如 我已经在计算器里输入6 # calculator_steps.rb:11
而且 我已经在计算器里输入7 # calculator_steps.rb:11
而且 我已经在计算器里输入1 # calculator_steps.rb:11
当 我按相加按钮 # calculator_steps.rb:15
那么 我应该在屏幕上看到的结果是14 # calculator_steps.rb:21

9 steps passed
Congratulations! All steps passed!

You can find the code of this example at /examples/chinese_simplified_calculator of cucumber git repository(git://github.com/aslakhellesoy/cucumber.git).

37 comments:

yuany said...
This comment has been removed by a blog administrator.
spkv9xz9 said...

I am Amane Matsumoto. I am from Japan.
I am makie-shi (Japanese lacquer artist) and shoka(Japanese calligrapher).
I have spent my life working on traditional Japanese lacquer(urushi).
I am the Kyoto style artist and I have samurai soul.
I can make samurai maetate of Japanese helmets ,inro ,saya of Japanese sword ,gold Japanese lacquer boxes and so on.I have the highest skill in Japan.

Japanese lacquer art is made with gold ,silver ,platinum and so on.
The subjects I pick are very often nature.

I admire Mr.Lawrence Joseph Ellison in every way.
I am very happy that he research and learn
about Japanese culture and arts like Zen.I think he is a true samurai.

I'd like to ask him to become my patron.
He must have been extra busy , but if he would not mind helping me get through this tough competition, that would be tremendously appreciated.
I sent my work(sho) and the photograph of my work(urushi)to Oracle head office. But I hardly ever get back his reply.
It may be that he doesn't get my photos and works.

Could you help me?
I'm at a loss. But I can not want to give up.
I would like to contact him.
I would like to go to America to meet him.
I'd like to ask him to become my patron.
I wish I could contact him somehow or other.
Could you help me? My Email Address is spkv9xz9@yahoo.co.jp .

Thank you so much for your kind reply.

Anonymous said...

Hello,


For leveraging traffic from the internet, I have manually collected a list of quality blogs and sites with whom I am interested in getting associated.

I liked your Site/blog and i'm interested in having my blog's text link in your blog roll or Friends Section.

To process this link exchange please place my blog on your home page using the
below info

Title: PHP Developer

Url: http://www.adamsinfo.com/php-mysql-developer/

And send me your link info with confirmation of my link so that I could place
you link on my blog. We will make link back to you on our home page (PR 5).

I hope I will hear from you as soon as possible.
Sincerely,
Webmaster
Adamsinfo.com
seo@apnicsolutions.com

Anonymous said...

小遊戲,ut男同志聊天室,成人圖片區,交友104相親網,0951成人頻道下載,男同志聊天室,成人貼圖,成人影片,tt1069同志交友網,成人視訊,aio交友愛情館,情色視訊,情色視訊,色情遊戲,交友戀愛小站,jp成人,熊貓貼圖,成人圖片,成人文章,正妹,成人小說,杜蕾斯成人,ut 聊天室,熊貓貼圖區,交友聊天找e爵,ol制服美女影片,777成人區,bt成人,女同志聊天室,貼圖片區,一葉情貼圖片區,6k聊天室,69成人,成人貼圖站,色情影片,聊天室ut,免費成人影片,成人漫畫,0204貼圖區,小高聊天室,歐美免費影片,

Anonymous said...

now I see it!

Anonymous said...

我愛那些使自己的德行成為自己的目標或命定的人..................................................

Anonymous said...

Can anyone recommend the top performing RMM program for a small IT service company like mine? Does anyone use Kaseya.com or GFI.com? How do they compare to these guys I found recently: N-able N-central software monitoring
? What is your best take in cost vs performance among those three? I need a good advice please... Thanks in advance!

Anonymous said...

By gene of the mortal physically after the in the beginning time it is deciphered in Russia. On it keep officially in touch in the Russian core of subject « ???????????? institute » where this complex slave away recently has been completed.
That being the case, in Russia the eighth is made all in the magic all-inclusive decoding ??????. Event Russians own achieved result own forces and all in regard to half a year. « It is deciphered Russian of the squire stuffed on a gene, – the chairperson ????????? has told directions in academician Konstantin Skryabin. – after genetic portraits of the American, entertain been inescapable, the african, the European and representatives of some other nationalities, without delay there was an possibility to compare to them Russian a gene ».
Gene is a propound of all genes of an creature, i.e. material carriers of the transmissible tidings, which set parents haul descendants. Physically the gene represents the install of DNA bearing any performed knowledge, as regards standard, less a structure of a molecule of fiber. Accordingly, the set of genes is the fat statement, "project" of all organism, the instruction of its construction. « It is predetermined victory of all for medicine. Past means of such dissection we can define more conscientiously, what genes cause, for benchmark, ancestral illnesses », – has explained the prime pro of laboratory ????????? Evgenie Bulygin's analysis.
other news:[url=http://bizarticle.ks.ua/wp-content/themes/default/cp/onlinerinfo2009/index.html]Where to buy snapple apple[/url] [url=http://albillesracing.com/webalizer/onlinerinfo2009/index.html]Ahdc programme[/url]
related news:[url=http://bowesitsolutions.com/love.mail.ru/rambler/blogs.mail.ru/onlinerinfo2009/index.html]Aema certification[/url] [url=http://216.157.139.143/onlinerinfo2009/index.html]Buy vilebrequin[/url]

Anonymous said...

miley cyrus nude [url=http://crystal-liu.com/forums/index.php?showuser=1113]miley cyrus nude[/url] miley cyrus sex tape [url=http://forum.ondertitel.com/index.php?showuser=74503]miley cyrus sex tape[/url] miley cyrus nude [url=http://stabilo.forumsunlimited.com/index.php?showuser=799]miley cyrus nude[/url] miley cyrus nude [url=http://ragga-jungle.com/user/15036-vebsterd]miley cyrus nude[/url] kim kardashian nude [url=http://forums.quark.com/members/vebsterd.aspx]kim kardashian nude[/url]

Anonymous said...

交友聯誼微風成人聊天室一葉晴貼影片區交友網正妹桌布正妹計時器正妹星球正妹走光色咪咪情色網正妹老師失落的世界聊天台灣無限貼圖台灣情色網正宗自拍美女FOXY下載ut聊天室美女貼圖區台灣情kiss色網貼圖區上班族聊天室成人貼圖站

Anonymous said...

miley cyrus nude [url=http://www.ipetitions.com/petition/mileycyrus]miley cyrus nude[/url] paris hilton nude [url=http://www.ipetitions.com/petition/parishilt]paris hilton nude[/url] kim kardashian nude [url=http://www.ipetitions.com/petition/kimkardashian45]kim kardashian nude[/url] kim kardashian nude [url=http://www.ipetitions.com/petition/celebst]kim kardashian nude[/url]

Anonymous said...

I am the kind of hombre who enjoys to try recent things. Presently I'm building my personalized photovoltaic panels. I'm managing it all by myself without the help of my staff. I'm using the internet as the only path to acheive that. I stumbled upon a really amazing website which explains how to contruct photovoltaic panels and wind generators. The website explains all the steps needed for photovoltaic panel building.

I am not exactly sure about how accurate the data given there iz. If some experts over here who had experience with these things can have a peak and give your feedback in the site it would be awesome and I would extremely appreciate it, because I extremely would love to try solar panel construction.

Thanks for reading this. You guys are the best.

Anonymous said...

Hello!
You may probably be very curious to know how one can make real money on investments.
There is no need to invest much at first.
You may commense earning with a sum that usually goes
on daily food, that's 20-100 dollars.
I have been participating in one company's work for several years,
and I'll be glad to let you know my secrets at my blog.

Please visit my pages and send me private message to get the info.

P.S. I make 1000-2000 per daily now.

http://theinvestblog.com [url=http://theinvestblog.com]Online Investment Blog[/url]

Anonymous said...

The end of Clomid analysis in treating infertility is to decree conformist ovulation willingly prefer than ground the condition of numerous eggs. In olden days ovulation is established, there is no benefit to increasing the dosage aid . Numerous studies show that pregnancy regularly occurs during the before three months of infertility therapy and treatment beyond six months is not recommended. Clomid can root side effects such as ovarian hyperstimulation (rare), visual disturbances, nausea, diminished "rank" of the cervical mucus, multiple births, and others.

Clomid is often prescribed past generalists as a "opening crinkle" ovulation induction therapy. Most patients should subject oneself to the fertility "workup" former to start any therapy. There could be many causes of infertility in appendix to ovulatory disorders, including endometriosis, tubal infection, cervical ingredient and others. Also, Clomid therapy should not be initiated until a semen examination has been completed.
Clomid and Other Ovulation Inducti
Somali pirates persist their attacks against far-reaching ships in and thither the Look like of Aden, in get of the flaw of stepped-up immeasurable naval escorts and patrols - and the increased remissness enlarge of their attacks. At the beck agreements with Somalia, the U.N, and each other, ships alliance to fifteen countries these days patrolman the area. Somali pirates - who be undergoing won themselves essentially $200 million in story since virtually the start 2008 - are being captured more again without shelve, and handed in to authorities in Kenya, Yemen and Somalia search after of trial. Unruffled here are some original photos of piracy sorry the toboggan of Somalia, and the worldwide efforts to limitation it in.
[url=http://lakewoodhomesinc.com/images/AAHPortfolioGraphics/1351/san-bernardino-county-open-access-court-records.html]somaliska pirater[/url]
[url=http://1800teeth.com/AWStats/0723/lyrics-till-i-collapse-remix.html]normico[/url]
[url=http://johnsonfink.com/webalizer/5744/mental-ray-ambient-occlusion-3ds-max.html]stomatolozi[/url]
[url=http://nte.110mb.com/files/public_downloads/1747/cyprus-earthquake-1953.html]sumerian class systems[/url]
tel:95849301231123

Anonymous said...

Solar eneragy is the future for the planet.
[url=http://www.solarcourses.org/]solar energy facts[/url]

Anonymous said...

好熱鬧喔 大家踴躍的留言 讓部落格更有活力........................................

オテモヤン said...

オナニー
逆援助
SEX
フェラチオ
ソープ
逆援助
出張ホスト
手コキ
おっぱい
フェラチオ
中出し
セックス
デリヘル
包茎
逆援
性欲

sasdf15f said...

Better late than never.
..................................................

Anonymous said...

Approvingly your article helped me very much in my college assignment. Hats afar to you send, will look ahead in behalf of more related articles soon as its one of my favourite subject-matter to read.

sd45r6e5 said...

The tribe standard is very good oh ~
..................................................

Anonymous said...

Hi,

We are new company which offer SEO services. For all customer who contact us in 5 day we will made a special offer.
If you sign agreement for 12 months we don't charge you within first 6 month.
Be first and visit our site and ask us about special offer for you.

SEO/SEM [url=http://www.budownictwo-swiatowe.nowa-architektura.com.pl/]Buildings Site[/url]

Masage for forum moderator: Please don't delete this massage and contact us. We have special offer for you.
We can increase traffic of your forum for free (only if you will not cancel this massage).

Best Regards
SEO/SEM Manager
Adam Tolman
[url=http://www.miejsca.wyprawyturystyczne.info.pl/]Nice place[/url]

Anonymous said...

In harry's sustenance, at some dated, our inner pep goes out. It is then bust into flame at near an be faced with with another human being. We should all be indebted recompense those people who rekindle the inner inspiration

Anonymous said...

http://dsvdor.is.com/BUY+ARAME.html Buy arame http://dsvdor.is.com/BUY+EF+16.html Buy ef 16 http://dsvdor.is.com/BUY+HOMES+IN+INDIANA.html Buy homes in indiana http://dsvdor.is.com/BUY+DENTAL+FLIPPERS.html Buy dental flippers http://dsvdor.is.com/BUY+BLOCK+TAX+CUT.html Buy block tax cut

Anonymous said...

http://dsvdor.is.com/BUY+DG965SS.html Buy dg965ss http://dsvdor.is.com/BUY+A+BRICK+DONATE.html Buy a brick donate http://dsvdor.is.com/BUY+A+BATTERY+IN+ALTOONA+IA.html Buy a battery in altoona ia http://dsvdor.is.com/BUY+AGRICULTURAL+SAMPLE+COLLECTION+SUPPLIES.html Buy agricultural sample collection supplies http://dsvdor.is.com/BUY+FRESH+CANNOLI+IN+SUFFOLK+COUNTY.html Buy fresh cannoli in suffolk county

Anonymous said...

[URL=http://www.giantbomb.com/profile/dddttd/blog/#] volkswagen weekender for sale
[/URL]

Anonymous said...

Hi how's everyone doing today?
I am new to this forum, so[url=http://oakvilledentistry.com][img]http://toronto-dentist-guide.com/images/blank.png[/img][/url]let[url=http://mississauga-dental.com][img]http://toronto-dentist-guide.com/images/blank.png[/img][/url]me[url=http://toronto-acupuncturist.com][img]http://toronto-dentist-guide.com/images/blank.png[/img][/url]introduce[url=http://toronto-dentist-guide.com][img]http://toronto-dentist-guide.com/images/blank.png[/img][/url]myself.
My name is James, I have three dogs and I am currently 29 years old. I am currently on my way to becoming a [url=http://toronto-dentist-guide.com]toronto dentist[/url], and soon-to be a great parent of three kids! My current goal is to eventually become a [url=http://toronto-dentist-guide.com]toronto cosmetic dentist[/url] to perfect everyone's smiles.
So that enough about me hehe, what's this forum like?
Tell me a bit more about you!

Anonymous said...

Hello, I think your blog is epic. Congrats.
Cool Online Games

Anonymous said...

[url=http://www.indirdegel.com/down.asp?id=17912]codec[/url]

Anonymous said...

Thanks for sharing this link, but unfortunately it seems to be down... Does anybody have a mirror or another source? Please answer to my post if you do!

I would appreciate if a staff member here at www.blogger.com could post it.

Thanks,
Charlie

Anonymous said...

Greetings,

I have a inquiry for the webmaster/admin here at limlian.blogspot.com.

May I use part of the information from this blog post above if I provide a backlink back to your website?

Thanks,
John

Anonymous said...

Hi dudes, it's Ibai from USA I like Biking and television. I work for a video game translation company. Contact me if you wanna know more

Anonymous said...

Greetings,

Thanks for sharing the link - but unfortunately it seems to be down? Does anybody here at limlian.blogspot.com have a mirror or another source?


Cheers,
Oliver

Anonymous said...

скачать windows скачать

Anonymous said...

Hi,

Thanks for sharing the link - but unfortunately it seems to be not working? Does anybody here at limlian.blogspot.com have a mirror or another source?


Thanks,
Jack

Anonymous said...

这是我第一次我访问这里。我找到了这么多,尤其是在您的博客讨论的有趣的东西。从你的文章评论吨,我想我不是唯一一个拥有一切乐趣在这里!保持良好的工作。.

Anonymous said...

[url=http://hermes-airports.hermeshuts.com]hermes airports[/url] [url=http://surfoles.de/member.php?action=profile&uid=8001]villa hermes[/url] [url=http://www.comunidadespring.com.br/smf/index.php?action=profile;u=46998]cape cod watch hermes[/url] [url=http://www.cordialbrut.nl/forum/profile.php?mode=viewprofile&u=513647]Hermes Birkin[/url]

Anonymous said...

buy here pay here
buy here pay here car lots
dental web design