Skip to content

Commit 6563fa4

Browse files
committed
Add strict parameter to assert_dom
1 parent e4ba44a commit 6563fa4

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/rails/dom/testing/assertions/selector_assertions/html_selector.rb

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def initialize(values, previous_selection = nil, refute: false, &root_fallback)
1818
@values = values
1919
@root = extract_root(previous_selection, root_fallback)
2020
extract_selectors
21+
@strict = false
2122
@tests = extract_equality_tests(refute)
2223
@message = @values.shift
2324

@@ -59,6 +60,7 @@ def filter(matches)
5960

6061
content.strip! unless NO_STRIP.include?(match.name)
6162
content.delete_prefix!("\n") if text_matches && match.name == "textarea"
63+
collapse_html_whitespace!(content) unless NO_STRIP.include?(match.name) || @strict
6264

6365
next if regex_matching ? (content =~ match_with) : (content == match_with)
6466
content_mismatch ||= diff(match_with, content)
@@ -136,8 +138,14 @@ def extract_equality_tests(refute)
136138
raise ArgumentError, "Range begin or :minimum cannot be greater than Range end or :maximum"
137139
end
138140

141+
@strict = comparisons[:strict]
142+
139143
comparisons
140144
end
145+
146+
def collapse_html_whitespace!(text)
147+
text.gsub!(/\s+/, " ")
148+
end
141149
end
142150
end
143151
end

0 commit comments

Comments
 (0)