Tuesday, August 04, 2009

Testing with Rails : Can I Test External / Outside Apps?

Most of our application is written in PHP, and not likely to be rewritten anytime soon (though that is a different topic).  However I’m well aware that this doesn’t have to stop the introduction of Ruby on Rails into the mix.  Our newest push for enhanced quality, testing and metrics gives me an idea:  Can I use the latest and greatest testing tools like Cucumber and RSpec to build up a test suite to run against our existing application?  I particularly like the idea of having a business language for test cases so I can write things like this:

Feature : Have a pleasant and useful homepage

In order to navigate around the site easily

As a Guest

I want to see useful links in the navigation menu

Scenario : Main Menu

Given I’m on the homepage

And I am not logged in

Then I should see a link called “Member Login”

And I should see a link called “Register”

And I should not see a link called “My Account”

That works for me.  I could write bunches and bunches of those.  (It may help that I’m an old natural language guy who’s always had a soft spot for such interfaces.)

However, the natural behavior of Cucumber if I’m doing it right is to assume that “homepage” is a route into the existing Rails app, and that’s not what I want.  I actually want it to map to my production site, complete with http://www.mysite.com syntax.

I found this link from Erik On Rails that talks about creating a new Mechanize session.  But when I do that, my next statement (“should see”) fails because it thinks I got nil content back from the visit to my url.

Is it supposed to be this hard?  I see a whole bunch of articles about using these tools to do what sounds like the same thing I want (i.e. testing something other than a native Rails app) but I can’t seem to find the answer to my question.  Can I hit an external, fully defined url, get back the content, and crawl/test that content?  How??

No comments: