Robert Poor
2012-Aug-01 04:14 UTC
[Mechanize-users] preferred practice for comparing Mechanize::Page?
I''m writing rspec tests for a specialized subclass of Mechanize. I''d like to test the values returned by generic.get() against my_subclass.get(). I know that the following doesn''t work: it ''should produce the same result'' do a = generic.get("http://www.google.com/") b = my_subclass.get("http://www.google.com/") a.should == b end ...because (for among a few other problems) two equal() urls may not compare as ==: Diff: @@ -1,5 +1,5 @@ #<Mechanize::Page - {url #<URI::HTTP:0x00000107029948 URL:http://www.google.com/>} + {url #<URI::HTTP:0x000001047094c8 URL:http://www.google.com/>} This may be too general a question, but what would constitute a sensible equality test for two Mechanize::Page objects? TIA.
Eric Hodel
2012-Aug-01 04:52 UTC
[Mechanize-users] preferred practice for comparing Mechanize::Page?
On Jul 31, 2012, at 21:14, Robert Poor <rdpoor at gmail.com> wrote:> I''m writing rspec tests for a specialized subclass of Mechanize. I''d > like to test the values returned by generic.get() against > my_subclass.get(). I know that the following doesn''t work: > > it ''should produce the same result'' do > a = generic.get("http://www.google.com/") > b = my_subclass.get("http://www.google.com/") > a.should == b > end > > ...because (for among a few other problems) two equal() urls may not > compare as ==: > > Diff: > @@ -1,5 +1,5 @@ > #<Mechanize::Page > - {url #<URI::HTTP:0x00000107029948 URL:http://www.google.com/>} > + {url #<URI::HTTP:0x000001047094c8 URL:http://www.google.com/>}Red herring: $ ruby -ruri -e ''p URI("http://google.com") == URI("http://google.com")'' true (Apparently rspec is missing the super-useful object_id suppression that unit_diff has had since its first release. unit_diff, The Original Result Diffing Tool? unit_diff, Accept No Substitutes?, etc.) Neither Mechanize::Page nor Mechanize::File define #==, so two pages will never be equal in released versions.> This may be too general a question, but what would constitute a > sensible equality test for two Mechanize::Page objects?RFC 2616 section 13.3 appears to be where you want to look. At first glance this seems to include URI, Last-Modified header and Etag header.