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 lines on how to feed it “for real”. and [...]
Entries Tagged as ‘Test Driven Development (TDD)’
December 6, 2006
Receiving Email with ActionMailer
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 along and [...]
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 [...]
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 [...]
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 temporarily change [...]