黄瓜步骤中的正则表达式
Cucumber 生成一些简洁的 webrat 正则表达式步骤。 当我尝试这个时遇到了问题。
在功能中:
And I fill in "Telephone (Home)" with "61234567"
在 webrat 步骤中:
When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
fill_in(field, :with => value)
end
遇到的错误:
Could not find field: "Telephone (Home)" (Webrat::NotFoundError)
似乎“Home”之间的括号出现了问题。 如何调整正则表达式以考虑括号?
更新:
似乎正则表达式不是问题,因为“field”实例变量确实产生了“电话(家庭)”。 真正的问题是 webrat 的“fill_in”方法解析字段变量的方式。
Cucumber generates out some neat webrat regex steps. I encountered a problem when I tried the this.
In feature:
And I fill in "Telephone (Home)" with "61234567"
In webrat steps:
When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
fill_in(field, :with => value)
end
The error encountered:
Could not find field: "Telephone (Home)" (Webrat::NotFoundError)
It seems that the parenthesis between "Home" is giving problem. How do I tweak the regex to account for parenthesis?
UPDATE:
It seems that the regex wasn't the problem as the "field" instance variable did yield "Telephone (Home)". The real problem was the way webrat's "fill_in" method parses the field variable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您只想捕获“电话”,请尝试以下操作:
如果您要捕获“家庭”,请尝试以下操作:
If you only want to capture "Telephone" try this:
If it's "Home" you're after try this:
我也遇到了“(注销)”字段...
您可以调用 id 字段吗?
This encountered me too with the field "(log out)"...
You could call for the id field?
我在将标签与 webrat 中的字段匹配时遇到了类似的问题,我想出了这个代码片段,它放松了用于将标签与字段匹配的正则表达式。 也许它会对你有所帮助。
我的
features/support/env.rb
http://gist.github .com/169215
I had a similar problem with matching labels to fields in webrat, and I came up with this code snippet which loosens the regexp used to match a label to a field. Maybe it will help you out.
I have this in my
features/support/env.rb
http://gist.github.com/169215