详解Ruby on Rails中的Cucumber使用
替标记著 @javascript 的场景配置另一个配置文件。 配置文件可在 cucumber.yml 文件里配置。 # 配置文件的定义: profile_name: --tags @tag_name 带指令运行一个配置文件: cucumber -p profile_name 若使用 fabrication 来替换假数据 (fixtures),使用预定义的 fabrication steps。 不要使用旧版的 web_steps.rb 步骤定义!最新版 Cucumber 已移除 web steps,使用它们导致冗赘的场景,而且它并没有正确地反映出应用的领域。 当检查一元素的可视文字时,检查元素的文字而不是检查 id。这样可以查出 i18n 的问题。 给同种类对象创建不同的功能特色: # 差 Feature: Articles # ... 功能实作 ... # 好 Feature: Article Editing # ... 功能实作 ... Feature: Article Publishing # ... 功能实作 ... Feature: Article Search # ... 功能实作 ... 每一个功能有三个主要成分: 最常见的格式称为 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。步骤根据不同的标准放在不同的文件里。每一个功能可能有一个步骤文件 (home_page_steps.rb) 使用多行步骤参数来避免重复 场景: 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) # ... # 步骤: 总是使用 Capybara 否定匹配来取代正面情况搭配 should_not,它们会在给定的超时时重试匹配,允许你测试 ajax 动作。 见 Capybara 的 读我文件获得更多说明。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |