欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解Ruby on Rails中的Cucumber使用

 更新時間:2015年08月04日 12:03:50   投稿:goldensun  
這篇文章主要介紹了詳解Ruby on Rails中的Cucumber使用,Cucumber是測試Rails應用的常用工具,需要的朋友可以參考下


    用 @wip (工作進行中)標簽標記你未完成的場景。這些場景不納入考慮,且不標記為測試失敗。當完成一個未完成場景且功能測試通過時,為了把此場景加至測試套件里,應該移除 @wip 標簽。
    配置你的缺省配置文件,排除掉標記為 @javascript 的場景。它們使用瀏覽器來測試,推薦停用它們來增加一般場景的執(zhí)行速度。

    替標記著 @javascript 的場景配置另一個配置文件。

        配置文件可在 cucumber.yml 文件里配置。

    # 配置文件的定義:
    profile_name: --tags @tag_name

        帶指令運行一個配置文件:

    cucumber -p profile_name

    若使用 fabrication 來替換假數(shù)據(jù) (fixtures),使用預定義的 fabrication steps。

    不要使用舊版的 web_steps.rb 步驟定義!最新版 Cucumber 已移除 web steps,使用它們導致冗贅的場景,而且它并沒有正確地反映出應用的領域。

    當檢查一元素的可視文字時,檢查元素的文字而不是檢查 id。這樣可以查出 i18n 的問題。

    給同種類對象創(chuàng)建不同的功能特色:

  # 差
  Feature: Articles
  # ... 功能實作 ...

  # 好
  Feature: Article Editing
  # ... 功能實作 ...

  Feature: Article Publishing
  # ... 功能實作 ...

  Feature: Article Search
  # ... 功能實作 ...

    每一個功能有三個主要成分:
        Title
        Narrative - 簡短說明這個特色關于什么。
        Acceptance criteria - 每個由獨立步驟組成的一套場景。

    最常見的格式稱為 Connextra 格式。

  In order to [benefit] ...
  A [stakeholder]...
  Wants to [feature] ...

這是最常見但不是要求的格式,敘述可以是依賴功能復雜度的任何文字。

    自由地使用場景概述使你的場景備作它用 (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ù)來避免重復

    場景: 

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

    使用復合步驟使場景備作它用 (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 的 讀我文件獲得更多說明。

相關文章

最新評論