From 306b8f41ba73280379bc1c6c88c615097a4091ce Mon Sep 17 00:00:00 2001 From: benj Date: Sat, 12 Sep 2020 13:55:14 +0200 Subject: [PATCH] Fix #62: use Nokogiri::HTML::DocumentFragment for parent_scope --- lib/rspec-html-matchers/have_tag.rb | 2 +- spec/issues_spec.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 spec/issues_spec.rb diff --git a/lib/rspec-html-matchers/have_tag.rb b/lib/rspec-html-matchers/have_tag.rb index 476cfb4..1eb0d58 100644 --- a/lib/rspec-html-matchers/have_tag.rb +++ b/lib/rspec-html-matchers/have_tag.rb @@ -79,7 +79,7 @@ def matches? src, &block case src when String - parent_scope = Nokogiri::HTML(src) + parent_scope = Nokogiri::HTML::DocumentFragment.parse(src) @document = src else parent_scope = src.current_scope diff --git a/spec/issues_spec.rb b/spec/issues_spec.rb new file mode 100644 index 0000000..b94cd12 --- /dev/null +++ b/spec/issues_spec.rb @@ -0,0 +1,16 @@ +# encoding: utf-8 +# frozen_string_literal: true + +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('

My paragraph.

').not_to have_tag('html') + end + + it 'should not have body tag' do + expect('

My paragraph.

').not_to have_tag('body') + end + end +end