国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Ruby > 正文

詳解Ruby on Rails中的Cucumber使用

2020-10-29 19:37:10
字體:
供稿:網(wǎng)友


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

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

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

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

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

    cucumber -p profile_name

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

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

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

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

  # 差  Feature: Articles  # ... 功能實(shí)作 ...  # 好  Feature: Article Editing  # ... 功能實(shí)作 ...  Feature: Article Publishing  # ... 功能實(shí)作 ...  Feature: Article Search  # ... 功能實(shí)作 ...

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

    最常見的格式稱為 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ù)不同的標(biāo)準(zhǔn)放在不同的文件里。每一個(gè)功能可能有一個(gè)步驟文件 (home_page_steps.rb)
    。也可能給每個(gè)特定對象的功能,建一個(gè)步驟文件 (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,它們會在給定的超時(shí)時(shí)重試匹配,允許你測試 ajax 動作。 見 Capybara 的 讀我文件獲得更多說明。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 平武县| 诸暨市| 潞城市| 调兵山市| 兴山县| 潍坊市| 彭水| 沭阳县| 扶风县| 嘉义县| 绥宁县| 五莲县| 百色市| 苏尼特右旗| 达拉特旗| 滁州市| 丹江口市| 鄂托克前旗| 丹阳市| 买车| 福州市| 夏河县| 台州市| 海原县| 都昌县| 灵宝市| 贵南县| 和龙市| 堆龙德庆县| 鄱阳县| 义马市| 阿鲁科尔沁旗| 抚顺市| 大理市| 临武县| 铁力市| 蓬安县| 元江| 和顺县| 灌南县| 松阳县|