主頁(yè) > 知識(shí)庫(kù) > 詳解Ruby on Rails中的Cucumber使用

詳解Ruby on Rails中的Cucumber使用

熱門標(biāo)簽:客戶服務(wù) 企業(yè)做大做強(qiáng) 百度AI接口 Win7旗艦版 電話運(yùn)營(yíng)中心 語(yǔ)音系統(tǒng) 呼叫中心市場(chǎng)需求 硅谷的囚徒呼叫中心


    用 @wip (工作進(jìn)行中)標(biāo)簽標(biāo)記你未完成的場(chǎng)景。這些場(chǎng)景不納入考慮,且不標(biāo)記為測(cè)試失敗。當(dāng)完成一個(gè)未完成場(chǎng)景且功能測(cè)試通過(guò)時(shí),為了把此場(chǎng)景加至測(cè)試套件里,應(yīng)該移除 @wip 標(biāo)簽。
    配置你的缺省配置文件,排除掉標(biāo)記為 @javascript 的場(chǎng)景。它們使用瀏覽器來(lái)測(cè)試,推薦停用它們來(lái)增加一般場(chǎng)景的執(zhí)行速度。

    替標(biāo)記著 @javascript 的場(chǎng)景配置另一個(gè)配置文件。

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

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

        帶指令運(yùn)行一個(gè)配置文件:

    cucumber -p profile_name

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

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

    當(dāng)檢查一元素的可視文字時(shí),檢查元素的文字而不是檢查 id。這樣可以查出 i18n 的問(wèn)題。

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

  # 差
  Feature: Articles
  # ... 功能實(shí)作 ...

  # 好
  Feature: Article Editing
  # ... 功能實(shí)作 ...

  Feature: Article Publishing
  # ... 功能實(shí)作 ...

  Feature: Article Search
  # ... 功能實(shí)作 ...

    每一個(gè)功能有三個(gè)主要成分:
        Title
        Narrative - 簡(jiǎn)短說(shuō)明這個(gè)特色關(guān)于什么。
        Acceptance criteria - 每個(gè)由獨(dú)立步驟組成的一套場(chǎng)景。

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

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

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

    自由地使用場(chǎng)景概述使你的場(chǎng)景備作它用 (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 |

    場(chǎng)景的步驟放在 step_definitions 目錄下的 .rb 文件。步驟文件命名慣例為 [description]_steps.rb。步驟根據(jù)不同的標(biāo)準(zhǔn)放在不同的文件里。每一個(gè)功能可能有一個(gè)步驟文件 (home_page_steps.rb)
    。也可能給每個(gè)特定對(duì)象的功能,建一個(gè)步驟文件 (articles_steps.rb)。

    使用多行步驟參數(shù)來(lái)避免重復(fù)

    場(chǎng)景: 

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ù)合步驟使場(chǎng)景備作它用 (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 否定匹配來(lái)取代正面情況搭配 should_not,它們會(huì)在給定的超時(shí)時(shí)重試匹配,允許你測(cè)試 ajax 動(dòng)作。 見 Capybara 的 讀我文件獲得更多說(shuō)明。

您可能感興趣的文章:
  • 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的頁(yè)面緩存機(jī)制
  • 在Docker中自動(dòng)化部署Ruby on Rails的教程
  • 對(duì)優(yōu)化Ruby on Rails性能的一些辦法的探究
  • Ruby on Rails基礎(chǔ)之新建項(xiàng)目

標(biāo)簽:濟(jì)南 崇左 喀什 山西 安康 海南 山西 長(zhǎng)沙

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《詳解Ruby on Rails中的Cucumber使用》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266