Courtesy of Twitter

Posts Tagged ‘testing’

Faking It

Monday, July 14th, 2008

Today I was doing the one thing I truly, truly love doing and that’s complaining about writing RSpec tests. I came across a doozy of a problem involving RSpec testing and faking subdomains. Here’s a stripped down version of what I did:

def login_as(user)
  session["user"] = users(user).id
  request.host = User.find(session["user"]).company.domain + ".example.com"
end

Just pop that into your spec/spec_helper.rb and then you can use login_as(:user) which will find the fixture with the name of “user” and then go from there to setting your faked host as being from, for example, blah.example.com.

Pretty simple, shame Google didn’t turn up any relevant results without me having to dig deeper than usual.

Testing: There Has To Be A Better Way

Friday, January 11th, 2008

I hate testing in Ruby on Rails. I hate writing tests, and I especially hate running them. At work, we have 618 examples and it takes 346 seconds to run. That’s 5 minutes and 46 seconds to run 6000 lines of code, it’s pathetic!

The reason for this is that we have a central object which a lot of other objects are related to, called booking. Now, without giving too much away I’ll say that, along with the bookings table, there are 8 other tables that are emptied and loaded with data during a large majority of the tests. All this emptying and refilling is taking time, time that could be better spent not waiting for the tests to finish!

This is why I propose a system that entirely relies on fixtures for its data supply, so it doesn’t have to empty & load the tables again and again, but instead reads directly from the fixture files every time. I have no idea how to go about making one, but if anyone reads this and wants to collaborate with me on something like it, by all means please do. I hate having to read my emails whilst waiting for the tests to finish, I run out of emails.