[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

unit testing offline with mechanize

Adam Akhtar

9/13/2008 5:40:00 AM

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.
--
Posted via http://www.ruby-....

3 Answers

Phlip

9/13/2008 2:43:00 PM

0

Adam Akhtar 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?

--
Phlip

Adam Akhtar

9/14/2008 1:31:00 PM

0

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.

--
Posted via http://www.ruby-....

Lex Williams

9/14/2008 4:26:00 PM

0

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 .
--
Posted via http://www.ruby-....