kucaahbe / rspec-html-matchers

Old school have_tag, with_tag(and more) matchers for rspec 3 (Nokogiri powered)
http://rubygems.org/gems/rspec-html-matchers
MIT License
199 stars 90 forks source link

Allow using matchers on nokogiri xml documents #21

Closed mikz closed 11 years ago

mikz commented 11 years ago

Hi there!

I wanted to use these awesome helpers to match some generated XML documents, but unfortunately it was expecting just string or nesting. So I made a patch with tests to support calling these matchers on Nokogiri::XML::Document or any object implementing search.

kucaahbe commented 11 years ago

Thanks for PR, but that sounds like pretty edge case functionality, as far as I know nokogiri has #to_html method which converts nokogiri document to string, why don't you want just use it?

mikz commented 11 years ago

Because it is not HTML, but xml with all xmly stuff like namespaces, instruct, etc. HTML is parsed differently then XML.

kucaahbe commented 11 years ago

Yes, my fault, #to_xml not #to_html. In any case I meant that you always can convert your generated document into string and match what you need. In cases where you need specific xml matching this gem isn't coming for help, because of it's html matching purposes. But feel free to create your own fork with alternative functionality.

mikz commented 11 years ago

Also the string will be parsed as html instead of xml. And as added benefit you can use xpath instead of css. Because Nokogiri::Document::Html is direct subclass of xml document I don't see an issue here. I know it is meant for matching html but it works for xml too. In the end it is just about matching tags and their content.

    1. 2013 v 14:23, Dmitrij Mjakotnyi notifications@github.com:

Yes, my fault, #to_xml not #to_html. In any case I meant that you always can convert your generated document into string and match what you need. In cases where you need specific xml matching this gem isn't coming for help, because of it's html matching purposes. But feel free to create your own fork with alternative functionality.

— Reply to this email directly or view it on GitHub.

kucaahbe commented 11 years ago

I see, but there don't enough technical reasons to include and support such kind of functionality, sorry won't merge as I think this should go into separate project. In any case thanks a lot, I really appreciate your efforts!

HoneyryderChuck commented 11 years ago

Is this already in the latest version (0.4.3)? I get an error when i call it on Nokogiri document (doesn't have current_scope, something like that). It would be very good that this would work also for xml documents (for which it would probably have to change the name)