Wednesday, June 3, 2009

Cucumber and Subdomains

So cucumber has become my new best buddy. How can you not like this for integration testing? A brain dead monkey could get simple tests going. And that must be true, because I got some working.

In case you missed em, there's some RailsCasts (yeah, Ryan Bates is my hero) on Cucumber and Webrat here, here and here

So there I am plugging along on some tests in my latest project and just giggling like a little school girl at the simplicity of it all. Then I needed to test my subdomain routing. Brick wall. So now instead of giggling, it was more like stuck-pig-squeal. Crap.

So Google to the rescue, right? Not so fast. The problem is that cucumber is, relatively speaking, rather new, so there's not a ton of stuff up on the web yet. The other little sticky-widget I ran into was the fact that I was using 0.3.1 (which had been released like the day before) and it had changed the way some things work. So the only post I was able to find about this that contained a solution no longer worked (not to mention the fact that it was way to complicated for my lazy butt).

After struggling with this for a couple of days, I finally ran across a post that pointed me in the right direction (sorry I can't remember the site to give credit where credit is due). So I worked the kinks out and ended up with a super-simple way to test subdomains in Cucumber. So far this has worked for everything I've thrown at it.

I'd love some feedback if anyone can think of ways to improve this or sees potential problems I haven't thought out.