如何使用 Cucumber 和 Webrat 检查表单是否已预先填充值?
我正在使用 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 "[email protected]" 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
我确信我可以找出一些令人讨厌的正则表达式来实现评估这些步骤,但我觉得必须有一些已经存在的或更优雅的东西我能做到。您如何评估表单字段中预先填充的数据的表单?
I am learning Cucumber and Webrat with Rails and would like some advice on the best way to test an "edit" form. When I browse to a user's profile I am presented with an edit form with the user's information pre-populated in the form fields. I would like to be able to test that the fields do in fact contain the information I expect. Here's my scenario:
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 "[email protected]" in the "Email" field
And I should see a blank "Password" field
And I should see a blank "Password confirmation" field
Cucumber tells me, correctly, that I need to define the following custom steps:
Then /^I should see "([^\"]*)" in the "([^\"]*)" field$/ do |arg1, arg2|
pending
end
Then /^I should see a blank "([^\"]*)" field$/ do |arg1|
pending
end
I'm sure I can figure out some nasty regex to implement evaluating these steps, but I feel there must be something already existing or more elegant that I can do. How do you evaluate forms with data pre-populated in the form fields?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 features/step_definitions/webrat_steps.rb,以下步骤定义看起来像您正在寻找的内容:
Have a look at features/step_definitions/webrat_steps.rb, the following step definition looks like what you are looking for: