2017-08-28 28 views
0

我想检查我的导航中包含的每个包含正则表达式的链接。在使用这样的代码之前,我已经检查了相同的导航链接:Rails:无法在assert_select块中使用正则表达式

assert_select "nav.active" do |nav| 
    assert_select nav, "a[href=?]", edit_post_path(post), count: 0 
end 

这很好。我无法使用正则表达式做类似的事情,如docs中所见。我一直在使用这些变化试过(两者在目的注释掉):

assert_select "nav.active" do |nav| 
    #assert_select "a[href=?]", /.+/ 
    #assert_select nav, "a[href=?]", /foo/, count: 1 
end 

哪些失败并输出:

Minitest::Assertion: Expected exactly 1 element matching "a[href=/.+/]", found 0.. 

Minitest::Assertion: Expected exactly 1 element matching "a[href=/foo/]", found 0.. 

我在做什么错?

回答

0

我今天遇到这个问题,同时寻找类似的答案。我刚刚在我的测试中成功地使用了这条线:

assert_select "input:match('value',?)", /Clear search:/, count: 0 

所以下面应该可以工作。

#assert_select "a[href=?]", /.+/ 
assert_select "a:match('href',?)", /.+/ 

#assert_select nav, "a[href=?]", /foo/, count: 1 
assert_select "a:match('href',?)", /foo/, count: 1 

Rails 5使用Nokogirl的assert_select实现。基于它的文档,我不认为你需要在循环中提到navhttps://github.com/kaspth/rails-dom-testing/blob/master/lib/rails/dom/testing/assertions/selector_assertions.rb

相关问题