I recently incorporated db-triggers with a Rails app to maintain some counts that were otherwise fairly expensive to retrieve. Rails wasn’t super-pumped about the idea (what with the “keep all the logic in the app” approach and all), but sometimes… you know… you know better than your framework. Some things I was aiming for: Set them [...]
Entries Tagged as ‘Test Driven Development (TDD)’
December 6, 2006
Receiving Email with ActionMailer
This really was a snap. A nice and simple testing recipe (#68) demonstrates how to read in an email from a fixture in just a few lines and pass them to your processing method (MailReceiver.receive in this case). def read_fixture(action) IO.readlines(“#{FIXTURES_PATH}/mail_receiver/#{action}”) end def test_something email = read_fixture(“junk_mail”).join MailReceiver.receive(email) # assertions end And then a few [...]
October 2, 2006
Be careful with assert_not_equal
As I discovered today, assert_not_equal has a pretty big problem: it does exactly what you ask it to do. I just need to make sure that a user has at least one record: assert_not_equal 0, UserPreference.find_by_user_id(user_id) As you may have just caught: that is always going to pass. Not a tough mistake when you’re motoring [...]
July 14, 2006
Adding tests to rake
We’ve developed a few batch applications that live in the same directory structure as the Rails app they’re intimate with. So, the lib/foo/test/ contains some tests for the ‘foo’ batch app. lib/bar/test has the ones for ‘bar’ etc. It was kind of annoying to have seperate rake files though – or worse to need to [...]
May 31, 2006
No help from the log
Upon synching up, a colleague noticed that I had a test failing… kinda odd since I've been (trying to be) pretty good about keeping things up to date. Running them myself, we noticed that I was actually experiencing a quiet error message that was preventing my unit tests from running at all. I had been [...]
April 27, 2006
Testing the controller
A couple things I found very handy today while setting up a functional test for a controller. First off, this controller relies on a user being logged in (but this isn't the controller that actually manages the login process). The easiest way I found to make sure that I was properly logged in was to [...]