Skip to content

Stop catching Nokogiri::CSS::SyntaxError #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ Doms are compared via `assert_dom_equal` and `assert_dom_not_equal`.
Elements are asserted via `assert_select`, `assert_select_encoded`, `assert_select_email` and a subset of the dom can be selected with `css_select`.
The gem is developed for Rails 4.2 and above, and will not work on previous versions.

## Deprecation warnings when upgrading to Rails 4.2:
## Nokogiri::CSS::SyntaxError exceptions when upgrading to Rails 4.2:

Nokogiri is slightly more strict about the format of css selectors than the previous implementation. That's why you have warnings like:

```
DEPRECATION WARNING: The assertion was not run because of an invalid css selector.
```
Nokogiri is slightly stricter about the format of CSS selectors than the previous implementation.

Check the 4.2 release notes [section on `assert_select`](http://edgeguides.rubyonrails.org/4_2_release_notes.html#assert-select) for help.

Expand Down
6 changes: 0 additions & 6 deletions lib/rails/dom/testing/assertions/selector_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ def css_select(*args)
root = args.size == 1 ? document_root_element : args.shift

nodeset(root).css(args.first)
rescue Nokogiri::CSS::SyntaxError => e
ActiveSupport::Deprecation.warn("The assertion was not run because of an invalid css selector.\n#{e}", caller(2))
return
end

# An assertion that selects elements and makes one or more equality tests.
Expand Down Expand Up @@ -177,9 +174,6 @@ def assert_select(*args, &block)

nest_selection(matches, &block) if block_given? && !matches.empty?
end
rescue Nokogiri::CSS::SyntaxError => e
ActiveSupport::Deprecation.warn("The assertion was not run because of an invalid css selector.\n#{e}", caller(2))
return
end

# Extracts the content of an element, treats it as encoded HTML and runs
Expand Down
8 changes: 4 additions & 4 deletions test/selector_assertions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,15 @@ def test_nested_css_select
# testing invalid selectors
def test_assert_select_with_invalid_selector
render_html '<a href="http://example.com">hello</a>'
assert_deprecated do
assert_nil assert_select("[href=http://example.com]")
assert_raises Nokogiri::CSS::SyntaxError do
assert_select("[href=http://example.com]")
end
end

def test_css_select_with_invalid_selector
render_html '<a href="http://example.com">hello</a>'
assert_deprecated do
assert_nil css_select("[href=http://example.com]")
assert_raises Nokogiri::CSS::SyntaxError do
css_select("[href=http://example.com]")
end
end

Expand Down