The blog of Rahoul Baruah from 3hv Ltd

What's going on?

My name is Rahoul Baruah (aka Baz) and I'm a software developer in Leeds (England).

This is a log of things I've discovered while writing software in Ruby on Rails. In other words, geek stuff.

However, I've decided to put this blog on ice - I would ask you to check out my business blog here (or subscribe here).

10 July, 2007

Rails, Unit Tests and setup not working

No posts in a while ... there's a reason for that (very exciting for me, maybe not so much for you, dear reader) - I'll be telling you my news soon enough.

In the meantime, many thanks to the good folks at the North West Ruby User Group mailing list (I don't live in the North West but it certainly seems to be a hotbed of Rails action) for helping me out with this one.

It started simply enough. Another day, another controller another functional test.

fixtures :thingies, :wotsits

def setup
@thingy = thingies :my_thingy

def test_something
get :something
assert_response :success
assert_equal, assigns(:page_title)
assert_equal @thingy, assigns(:thingy)

Open Terminal, type ruby test/functional/thingy_controller_test.rb. Runs fine. All tests pass.

Happy developer.

A bit later, just before committing my changes, type rake test:functionals. Fails. No such method on nil. Nil? Nil? Where does nil come from?

Try running the test on its own? Works fine. Try it in rake? Fails.

I then edited it and added some puts statements in each test and in the setup method. Ran the test on its own - all my text appears as expected. Ran rake - all my text appears except the text from setup. So setup is not being called? But why?

Well, I never found out why but the NWRUG members pinpointed the problem. It was the call to super in setup - apparently there is no method in the super-class and under certain circumstances it never seems to return from this call to the non-existent method. Remove the super and everything runs fine.

Still no explanation as to why it works one way and not the other but at least it works.

No comments:

eXTReMe Tracker