Ruby on rails 分步骤的正则表达式
Cucumber生成了一些整洁的webrat正则表达式步骤。我在尝试这个时遇到了一个问题 在功能中:Ruby on rails 分步骤的正则表达式,ruby-on-rails,ruby,regex,cucumber,webrat,Ruby On Rails,Ruby,Regex,Cucumber,Webrat,Cucumber生成了一些整洁的webrat正则表达式步骤。我在尝试这个时遇到了一个问题 在功能中: And I fill in "Telephone (Home)" with "61234567" When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value| fill_in(field, :with => value) end Could not find field: "Telephone (Home)" (W
And I fill in "Telephone (Home)" with "61234567"
When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
fill_in(field, :with => value)
end
Could not find field: "Telephone (Home)" (Webrat::NotFoundError)
在webrat步骤中:
And I fill in "Telephone (Home)" with "61234567"
When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
fill_in(field, :with => value)
end
Could not find field: "Telephone (Home)" (Webrat::NotFoundError)
遇到的错误:
And I fill in "Telephone (Home)" with "61234567"
When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
fill_in(field, :with => value)
end
Could not find field: "Telephone (Home)" (Webrat::NotFoundError)
似乎“家”之间的括号是给予问题。如何调整正则表达式以考虑括号
更新:
And I fill in "Telephone (Home)" with "61234567"
When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
fill_in(field, :with => value)
end
Could not find field: "Telephone (Home)" (Webrat::NotFoundError)
似乎正则表达式不是问题所在,因为“字段”实例变量确实产生了“Telephone(Home)”。真正的问题是webrat的“fill_in”方法解析字段变量的方式。如果您只想捕获“电话”,请尝试以下方法:
/^I fill in "(\w+).*?" with "([^\"]*)"$/
/^I fill in "(?:.*?\()?(.+?)\)?" with "([^\"]*)"$/;
如果你想要的是“家”,试试这个:
/^I fill in "(\w+).*?" with "([^\"]*)"$/
/^I fill in "(?:.*?\()?(.+?)\)?" with "([^\"]*)"$/;
这在字段“(注销)”中也遇到了我 你可以打电话找id字段吗
fill_in("user_telephone_home", :with => data)
在webrat中将标签与字段匹配时,我遇到了类似的问题,我提出了这个代码片段,它释放了用于将标签与字段匹配的regexp。也许它会帮你 我的
features/support/env.rb
module Webrat
module Locators
class FieldLabeledLocator < Locator
def matching_label_elements_with_numbering
label_elements.select do |label_element|
text(label_element) =~ /^.*#{Regexp.escape(@value.to_s)}.*$/i
end
end
alias_method_chain :matching_label_elements, :numbering
end
end
end
模块Webrat
模块定位器
类字段标签定位器<定位器
def匹配_标签_元素_与_编号
标记|元素。选择do |标记|元素|
text(label_元素)=~/^.*{Regexp.escape(@value.to_s)}.*$/i
结束
结束
别名\u方法\u链:匹配\u标签\u元素,:编号
结束
结束
结束
是的,我最终使用了字段的id,尽管在我的cucumber功能定义中,它像一个酸痛的拇指一样突出。谢谢