rails/rails-dom-testing

assert_select no longer works with regex

jonswar opened this issue · 5 comments

Unable to select an href url with a regex. This used to pass in Rails 4.1.8, fails with rails-dom-testing 1.0.7 with

  Expected at least 1 element matching "a[href="(?-mix:.)"]", found 0..
  Expected 0 to be >= 1.

Incidentally, if there is a way to call assert_select directly on a piece of HTML (without needing a controller) please let me know.

class TmpControllerTest < ActionController::TestCase
  test 'link' do
    get :link
    assert_success
    puts response.body                     # Outputs <a href="/work/1">Work</a>
    assert_select 'a[href="/work/1"]'      # Passes
    assert_select 'a[href=?]', "/work/1"   # Passes
    assert_select 'a[href=?]', %r{/work/1} # Fails
    assert_select 'a[href=?]', %r{.}       # Fails
  end
end

Oops sorry about that!

No problem. TL;DR you need to change the substitution API to match the nokogiri's API

Don't suppose there's any way to issue a better warning for the old syntax? Anyway, thanks for all your hard work. :)

Maybe, we need to investigate. I'll reopen this issue so we can work on
that.

On Mon, Aug 24, 2015, 17:14 Jonathan Swartz notifications@github.com
wrote:

Don't suppose there's any way to issue a better warning for the old
syntax? Anyway, thanks for all your hard work. :)


Reply to this email directly or view it on GitHub
#38 (comment)
.