Skip to content

Commit

Permalink
Restore the support for matching html and body
Browse files Browse the repository at this point in the history
This effectively reverts 306b8f4 and adds specs for matching `html` and `body` elements.

The issue reported in #62 isn't solvable using DOM assertions. DOM tree has to have a root element (`html`). Using `DocumentFragment` extracts a part of the tree, so it won't contain `html` or `body` elements, but that doesn't mean they weren't a part of the input.
  • Loading branch information
CvX committed Oct 2, 2020
1 parent df7124a commit 4746224
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/rspec-html-matchers/have_tag.rb
Expand Up @@ -79,7 +79,7 @@ def matches? src, &block

case src
when String
parent_scope = Nokogiri::HTML::DocumentFragment.parse(src)
parent_scope = Nokogiri::HTML(src)
@document = src
else
parent_scope = src.current_scope
Expand Down
5 changes: 5 additions & 0 deletions spec/fixtures/document.html
@@ -0,0 +1,5 @@
<html>
<body>
test
</body>
</html>
12 changes: 12 additions & 0 deletions spec/have_tag_spec.rb
Expand Up @@ -669,4 +669,16 @@
end
end
end

context 'html and body elements' do
asset 'document'

it 'should find the html element' do
expect(rendered).to have_tag('html')
end

it 'should find the body element' do
expect(rendered).to have_tag('body')
end
end
end
10 changes: 0 additions & 10 deletions spec/issues_spec.rb
Expand Up @@ -4,16 +4,6 @@
require 'spec_helper'

describe 'working on github issues' do
describe '#62' do # https://github.com/kucaahbe/rspec-html-matchers/issues/62
it 'should not have html tag' do
expect('<p>My paragraph.</p>').not_to have_tag('html')
end

it 'should not have body tag' do
expect('<p>My paragraph.</p>').not_to have_tag('body')
end
end

it '#73' do # https://github.com/kucaahbe/rspec-html-matchers/issues/73
rendered = <<HTML
<p>
Expand Down

0 comments on commit 4746224

Please sign in to comment.