Unit testing offline with mechanize

Although mechanize is designed to navigate around web pages online, is
there a way to load up webpages saved to the harddrive for the purposes
of quick unit testing. Constantly accessing online sources slows down
the tests. I tried to simply type the file name instead of the url in
agent.get("…") but it complains. I tried get_file and that didnt work
either.

any help greatly appreciated.

Adam A. wrote:

Although mechanize is designed to navigate around web pages online, is
there a way to load up webpages saved to the harddrive for the purposes
of quick unit testing. Constantly accessing online sources slows down
the tests. I tried to simply type the file name instead of the url in
agent.get("…") but it complains. I tried get_file and that didnt work
either.

That sounds like the assumption you must serve a page through a web
server just
to unit test it.

Why not do what Rails tests do - call the same method a server would
call to
generate a page, then read it as a string and test it?

thanks philip for the reply. Im new to ruby and havnt experimented with
rails yet etc though i think i understand what you mean.

The reason why i want mechanize to fetch the offline page rather than
say reading it in as a string via IO.read(“offlinepage.htm”) is because
in teh past ive noticed that the html code in a page saved from firefox
is sligthly different from that say of open-uri due to the fact that
firefox cleans up dodgy html (to an extent). this is also true with
firebug - what it shows in its console may not actually be present in
the actual html downloaded with open-uri.
I dont know if this is the case with mechanize. As i said im new to ruby
and web programming so i really dont know how to work round these
differences apart from just using one tool to grab the pages and then
open them.

Am i wrong on this? Id really like to know how people get round this
problem.

a tip would be to save the page with mechanize , read it then locally
within a script , get your regexes ( or whatever you’re doing to parse
the data ) right , and then try them on the online version .