Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在RubyonRails上的断言选择器中使用regexp_Ruby On Rails_Ruby_Capybara_Ruby Test - Fatal编程技术网

Ruby on rails 如何在RubyonRails上的断言选择器中使用regexp

Ruby on rails 如何在RubyonRails上的断言选择器中使用regexp,ruby-on-rails,ruby,capybara,ruby-test,Ruby On Rails,Ruby,Capybara,Ruby Test,我有一个在页面上显示日期和时间的选择器,需要编写capybara测试来检查日期。如何在assert\u选择器中包含regexp assert_selector("div", text: /"#{DateTime.now.strftime('%a %b %d, %H:%M')}"*/i) 它不能作为正则表达式工作。使用ruby on rails中的assert_selector测试部分文本或子字符串的语法是什么?text选项接受正则表达式以匹配文本,但它也

我有一个在页面上显示日期和时间的选择器,需要编写capybara测试来检查日期。如何在assert\u选择器中包含regexp

assert_selector("div", text: /"#{DateTime.now.strftime('%a %b %d, %H:%M')}"*/i)

它不能作为正则表达式工作。使用ruby on rails中的assert_selector测试部分文本或子字符串的语法是什么?
text
选项接受正则表达式以匹配文本,但它也默认为部分匹配,因此通常不需要传递正则表达式

assert_selector("div", text: DateTime.now.strftime('%a %b %d, %H:%M'))
将对元素的文本进行部分匹配

如果你真的想使用正则表达式(假设你不是真的想检查周围的),那么你会想要

assert_selector("div", text: /#{Regexp.escape(DateTime.now.strftime('%a %b %d, %H:%M'))}/i)

你的日期和时间真的在你的页面上吗?是的,我正在headerOk上显示当前的日期和时间-但是你是否显示
datetime
“datetime”
-你的正则表达式实际上是在检查eg[(Mon-Jul 06,16:41:52 GMT-04:00)的“sI am显示本地和utc日期时间”不,它不做部分匹配,它看起来是精确的text@Veda您是否更改了文本匹配的Capybara默认值(即,您已将Capybara.exact_text=true)?如果更改,请执行
assert_选择器(“div”,文本:DateTime.now.strftime(“%a%b%d,%H:%M”),exact_text:false)
exact选项仅对使用XPath#is方法的查询有效。将其与查询“div”一起使用无效。我正在以这种格式显示本地和utc日期/时间((Mon Jul 06,16:41:52 GMT-04:00(local)。(Mon Jul 06,20:41:52(utc))测试这个字符串的regexp是什么?@veda它是
exact\u text
而不是
exact