• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

[追記] 次に書いたScenario, stepのリンク集もどうぞ:
http://blog.s21g.com/articles/1441


Given, When and Thenの基本はわかったんだけど、なんとなくスマートに書けるようになるにはまだ足りない気がする。というので色々snippetとして集めてみました。
(文法的にはもう古い物もあるので注意)

###Given, When and Then
基本はここで:
http://wiki.github.com/aslakhellesoy/cucumber/given-when-then

Given -> When -> Then の順にしかこないのかと思ったら、下記にシナリオの途中にあらわれるThenもあった:
http://www.benmabey.com/2008/02/04/rspec-plain-text-stories-webrat-chunky-bacon/

rails>>
Scenario: A visitor successfully submits a new animal
Given no animal named 'Alligator' exists
When visitor goes to /animals/new
Then visitor should see the Animal submission form
When visitor submits an animal with name: 'Alligator', phylum: 'Chordata', animal class: 'Sauropsida', order: 'Crocodilia', family: 'Alligatoridae', genus: 'Alligator', and lay eggs: 'true'
Then an animal named 'Alligator' should exist
<<--

Thenの後にWhenがくるのもありなのかも。

###Stepの入れ子
http://wiki.github.com/aslakhellesoy/cucumber/calling-steps-from-step-definitions

rails>>
Given /^(.*) is logged in$/ do |name|
Given "the user #{name} exists"
Given "I log in as #{name}"
end
<<--

###記事作成のfeature
http://railscasts.com/episodes/155-beginning-with-cucumber

rails>>
Scenario: Create Valid Article
Given I have no articles
And I am on the list of articles
When I follow "New Article"
And I fill in "Title" with "Spuds"
And I fill in "Content" with "Delicious potato wedges!"
And I press "Create"
Then I should see "New article created."
And I should see "Spuds"
And I should see "Delicious potato wedges!"
And I should have 1 article

#article_steps
Given /^I have no articles$/ do
Article.delete_all
end
<<--

###Scenarioは完結に、Stepで細かく

Imperative vs Declarative Scenarios
http://www.benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories/

Scenarioを短くnarrativeに書いて、stepで細かいフォーム入力などを扱う感じに書かれていて一番しっくりきました。

Imperative 命令法/形の
Declarative => narrative 叙述の

rails>>
Story: Animal Submission
As a Zoologist
I want to add a new animal to the site
So that I can share my animal knowledge with the community

Scenario: successful submission
Given I'm on the animal creation page
When I add a new animal
Then I should see the page for my newly created animal
And the notice 'Thank you for your animal submission!'
<<--

rails>>

animal_steps.rb

When "I add a new animal" do
fills_in 'Name', :with => 'Alligator'
selects 'Chordata', :from => 'Phylum'
fills_in 'Animal Class', :with => 'Sauropsida'
fills_in 'Order', :with => 'Crocodilia'
fills_in 'Family', :with => 'Alligatoridae'
fills_in 'Genus', :with => 'Alligator'
checks 'Lay Eggs'
clicks_button 'Create'
end
<<--

posted by satoko satoko on Fri 17 Apr 2009 at 05:01 with 0 comments
Contents rssrss
NSAssertやNSLogを無効にする:-DNS_BLOCK_ASSERTIONS=1とNS_BLOCK_ASSERTIONS
GDBでview.frameを表示させる
Core Animationについてのリンク集
[iPhone] new BSDライセンスについてライセンス引用のメモ
Implementing a Container View Controller in UIViewController Class Reference
UITableView用のNSIndexPathの作り方
Xcodeのテンプレート、View-based ApplicationとWindow-based Applicationの違い
CopyOnSelectのLion対応
Xcode4のCode Snippetsを別のPCに移動する+gitで管理する
[iPhone] Singleton: iOS4以降はGCDのdispatch_onceを使う
Tags
iphone開発gitIBInterfaceBuilderiOSSIMBLSnippetsterminaltwitterxcodeXcode4
Comments rssrss
https://stosastudio.ru/catalog/kuhni-lounge/ https://stosastudio.ru/catalog/kuhni-lounge/: Фабрика Tessarolo https://stosastudio.ru/vybiraem-... 04/06 08:14
KingofSmack KingofSmack: Here also good reads for this mobile application d... 05/10 18:02
satoko satoko: stackoverflowでも同じエラーを挙げている人がいたので、1.3でアップロードしたよってコメ... 12/13 03:36
ujihisa ujihisa: :%s/blog/glob/g 07/28 16:41
satoko satoko: しゅが〜様 返事が遅くなって申し訳ありません。また、投稿百景ご購入ありがとうございます。 『po... 10/11 14:05
しゅが~ しゅが~: こんにちは。投稿百景を発売日翌日から利用しています。本当にいいAppを作っていただきました。罫線絵文... 10/08 00:38
satoko satoko: 情報ありがとうございます!コミットを再利用するの部分、文章が不明瞭ですね。ちょっと修正します。教えて... 09/25 14:32
ono ono: 後で確認したら、ファイルの除外はamendではできないですね、失礼しました。alias は、'-C ... 09/25 10:47