Class: Dommy::Rails::UrlMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/dommy/rails/url_matcher.rb

Overview

Adapts Rails URL normalization to the matcher protocol accepted by Dommy::Internal::ElementMatching.attribute_matches?, so ‘href:` / `action:` criteria absorb scheme/host, query-parameter order, HTML-escaped `&`, and trailing-slash differences.

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ UrlMatcher

Returns a new instance of UrlMatcher.



12
13
14
# File 'lib/dommy/rails/url_matcher.rb', line 12

def initialize(expected)
  @expected = expected
end

Instance Method Details

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
# File 'lib/dommy/rails/url_matcher.rb', line 16

def matches?(actual)
  case @expected
  when Regexp
    actual.to_s.match?(@expected)
  else
    UrlNormalizer.equal?(@expected, actual)
  end
end