[追記] 次に書いたScenario, stepのリンク集もどうぞ:
http://blo
Given, When and Thenの基本はわかったんだけど、なんとなくスマートに書けるようになるにはまだ足りない気がする。というので色々snippetとして集めてみました。
(文法的にはもう古い物もあるので注意)
Given, When and Then
基本はここで:
http://wik
Given -> When -> Then の順にしかこないのかと思ったら、下記にシナリオの途中にあらわれるThenもあった:
http://www
1 Scenario: A visitor successfully submits a new animal 2 Given no animal named 'Alligator' exists 3 When visitor goes to /animals/new 4 Then visitor should see the Animal submission form 5 When visitor submits an animal with name: 'Alligator', phylum: 'Chordata', animal class: 'Sauropsida ', order: 'Crocodilia ', family: 'Alligatori dae', genus: 'Alligator', and lay eggs: 'true' 6 Then an animal named 'Alligator' should exist
Thenの後にWhenがくるのもありなのかも。
Stepの入れ子
http://wik
1 Given /^(.*) is logged in$/ do |name| 2 Given "the user #{name} exists" 3 Given "I log in as #{name}" 4 end
記事作成のfeature
http://rai
1 Scenario: Create Valid Article 2 Given I have no articles 3 And I am on the list of articles 4 When I follow "New Article" 5 And I fill in "Title" with "Spuds" 6 And I fill in "Content" with "Delicious potato wedges!" 7 And I press "Create" 8 Then I should see "New article created." 9 And I should see "Spuds" 10 And I should see "Delicious potato wedges!" 11 And I should have 1 article 12 13 #article_steps 14 Given /^I have no articles$/ do 15 Article.delete_all 16 end
Scenarioは完結に、Stepで細かく
Imperative
vs Declarativ e Scenarios
http://www.benmabey. com/2008/0 5/19/imper ative-vs-d eclarative -scenarios -in-user-s tories/
Scenarioを短くnarrativeに書いて、stepで細かいフォーム入力などを扱う感じに書かれていて一番しっくりきました。
Imperative
Declarativ
1 Story: Animal Submission2 As a Zoologist 3 I want to add a new animal to the site 4 So that I can share my animal knowledge with the community 5 6 Scenario: successful submission 7 Given I'm on the animal creation page 8 When I add a new animal 9 Then I should see the page for my newly created animal 10 And the notice 'Thank you for your animal submission !'
1 # animal_steps.rb 2 When "I add a new animal" do 3 fills_in 'Name', :with => 'Alligator' 4 selects 'Chordata', :from => 'Phylum' 5 fills_in 'Animal Class', :with => 'Sauropsida ' 6 fills_in 'Order', :with => 'Crocodilia ' 7 fills_in 'Family', :with => 'Alligatori dae' 8 fills_in 'Genus', :with => 'Alligator' 9 checks 'Lay Eggs' 10 clicks_but ton 'Create' 11 end