用 @wip (工作進行中)標簽標記你未完成的場景。這些場景不納入考慮,且不標記為測試失敗。當完成一個未完成場景且功能測試通過時,為了把此場景加至測試套件里,應(yīng)該移除 @wip 標簽。
配置你的缺省配置文件,排除掉標記為 @javascript 的場景。它們使用瀏覽器來測試,推薦停用它們來增加一般場景的執(zhí)行速度。
替標記著 @javascript 的場景配置另一個配置文件。
配置文件可在 cucumber.yml 文件里配置。
# 配置文件的定義:
profile_name: --tags @tag_name
帶指令運行一個配置文件:
若使用 fabrication 來替換假數(shù)據(jù) (fixtures),使用預(yù)定義的 fabrication steps。
不要使用舊版的 web_steps.rb 步驟定義!最新版 Cucumber 已移除 web steps,使用它們導(dǎo)致冗贅的場景,而且它并沒有正確地反映出應(yīng)用的領(lǐng)域。
當檢查一元素的可視文字時,檢查元素的文字而不是檢查 id。這樣可以查出 i18n 的問題。
給同種類對象創(chuàng)建不同的功能特色:
# 差
Feature: Articles
# ... 功能實作 ...
# 好
Feature: Article Editing
# ... 功能實作 ...
Feature: Article Publishing
# ... 功能實作 ...
Feature: Article Search
# ... 功能實作 ...
每一個功能有三個主要成分:
Title
Narrative - 簡短說明這個特色關(guān)于什么。
Acceptance criteria - 每個由獨立步驟組成的一套場景。
最常見的格式稱為 Connextra 格式。
In order to [benefit] ...
A [stakeholder]...
Wants to [feature] ...
這是最常見但不是要求的格式,敘述可以是依賴功能復(fù)雜度的任何文字。
自由地使用場景概述使你的場景備作它用 (keep your scenarios DRY)。
Scenario Outline: User cannot register with invalid e-mail
When I try to register with an email "email>"
Then I should see the error message "error>"
Examples:
|email |error |
| |The e-mail is required|
|invalid email |is not a valid e-mail |
場景的步驟放在 step_definitions 目錄下的 .rb 文件。步驟文件命名慣例為 [description]_steps.rb。步驟根據(jù)不同的標準放在不同的文件里。每一個功能可能有一個步驟文件 (home_page_steps.rb)
。也可能給每個特定對象的功能,建一個步驟文件 (articles_steps.rb)。
使用多行步驟參數(shù)來避免重復(fù)
場景:
User profile
Given I am logged in as a user "John Doe" with an e-mail "user@test.com"
When I go to my profile
Then I should see the following information:
|First name|John |
|Last name |Doe |
|E-mail |user@test.com|
# 步驟:
Then /^I should see the following information:$/ do |table|
table.raw.each do |field, value|
find_field(field).value.should =~ /#{value}/
end
end
使用復(fù)合步驟使場景備作它用 (Keep your scenarios DRY)
# ...
When I subscribe for news from the category "Technical News"
# ...
# 步驟:
When /^I subscribe for news from the category "([^"]*)"$/ do |category|
steps %Q{
When I go to the news categories page
And I select the category #{category}
And I click the button "Subscribe for this category"
And I confirm the subscription
}
end
總是使用 Capybara 否定匹配來取代正面情況搭配 should_not,它們會在給定的超時時重試匹配,允許你測試 ajax 動作。 見 Capybara 的 讀我文件獲得更多說明。
您可能感興趣的文章:- ruby on rails 代碼技巧
- 在阿里云 (aliyun) 服務(wù)器上搭建Ruby On Rails環(huán)境
- Windows下Ruby on Rails開發(fā)環(huán)境安裝配置圖文教程
- win7安裝ruby on rails開發(fā)環(huán)境
- 舉例理解Ruby on Rails的頁面緩存機制
- 在Docker中自動化部署Ruby on Rails的教程
- 對優(yōu)化Ruby on Rails性能的一些辦法的探究
- Ruby on Rails基礎(chǔ)之新建項目