Skip to content

Changes to improve usability for testing? #6

@leehambley

Description

@leehambley

Hey, following positive and communicative feedback on the other issue I wanted to pitch an idea.

I've come to nokogiri-diff for testing pages (we have a ICAP proxy that we are trying to test). We need to verify that certain pages have been correctly modified, here's our workflow:

curl -is http://wwwexample.com > www_example_com.orig
cp www_example_com.{orig,mod}

Modify the modified version to meet our spec requirements, and then test it something like this:

it "should catch them all" do
  get "/proxy/http://www.example.com"
  html_diff(last_response.body, mod_body).should be_empty
end

The mocks are done with Webmock, and load as one spec with any spec fixture.

The HTML diff method I wrote had to screen out some whitespace differences (no semantic value):

  def html_diff(one, two)
    Nokogiri::HTML(one).diff(
      Nokogiri::HTML(two)
    ).select do |change, node|
      !change.strip.empty?
    end.collect do |change, node|
      puts "#{change} at #{node.to_s} #{node.path}"
    end.to_a
  end

I'm not too happy with the implementation, but it more or less works:- unfortunately this is client work into which I can't afford to invest a lot of time into testing infrastructure (“Just ship it!” :shipit:) - but I'd like to get your feedback on whether you can see the gem adding those features?

I noticed as well, probably for the best that text nodes don't register as changes, just the attributes and hierarchy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions