我正在用Rails学习Cucumber和Webrat,我想就测试“编辑”表单的最佳方法提出一些建议。当我浏览到用户的配置文件时,会看到一个编辑表单,在表单字段中预先填充了用户的信息。我希望能够测试字段是否确实包含我期望的信息。以下是我的场景:
Scenario: View My Profile
Given I am logged in as "Mike" with password "secret"
When I go to my profile page
Then I should see "Mike" in the "Login" field
And I should see "mike@email.com" in the "Email" field
And I should see a blank "Password" field
And I should see a blank "Password confirmation" field
Cucumber正确地告诉我,我需要定义以下自定义步骤:
Then /^I should see "([^\"]*)" in the "([^\"]*)" field$/ do |arg1, arg2|
pending
end
Then /^I should see a blank "([^\"]*)" field$/ do |arg1|
pending
end
我确信我可以找到一些讨厌的regex来实现对这些步骤的评估,但是我觉得必须有一些已经存在的或者更优雅的东西我可以做。如何评估表单字段中预先填充了数据的表单?