Unit Testing

41 views
Skip to first unread message

lostcaggy

unread,
Jun 19, 2008, 6:01:18 PM6/19/08
to shoulda
Hi I've been looking at rails for a while now and have written a
couple of simple app, I'm now about to start a larger app and what to
start testing my code, I've saw a presentation on shoulda at scotland
on rails and was impressed by how simple it seems. I'm now trying to
impliment tests in my code but this is something I've never done
before I've looked at the Rails way and AWDWD but can't seem to get my
head around how to start. Does anyone know of any very basic tutorials
to get me started or would people suggest I looked at RSPEC instead.
Thanks in Advance

TJ Stankus

unread,
Jun 19, 2008, 6:18:09 PM6/19/08
to sho...@googlegroups.com
RSpec seems a little heavy to me, especially for beginners. (Seeing as
this is the shoulda mailing list, you're probably not surprised by
that opinion.) Have you checked out the official shoulda tutorials at
http://thoughtbot.com/projects/shoulda/tutorial? Are there specific
pain points you're having? Perhaps a good exercise would be to run
through the AWDWR sample app testing chapter and use shoulda instead
of Test::Unit.

-TJ

Cynthia Kiser

unread,
Jun 19, 2008, 6:46:37 PM6/19/08
to sho...@googlegroups.com
Quoting TJ Stankus <tjst...@gmail.com>:
> RSpec seems a little heavy to me, especially for beginners.

I had a brief flirtation with RSpec after the testing tutorial at
RailsConf2007. It's nice but at the level I used it, there wasn't a
compelling difference compared to Test::Unit. The main thing I liked
about RSpec was that you could get an Englishy list of the tests that
were being run. Shoulda's 'rake shoulda:list' gives me that - in
addition to all its convenience methods. Another thing I like about
shoulda is that it uses Test::Unit so you can easily mix the scaffold
generated functional tests with custom tests of your own.

> > Hi I've been looking at rails for a while now and have written a
> > couple of simple app, I'm now about to start a larger app and what to
> > start testing my code, I've saw a presentation on shoulda at scotland
> > on rails and was impressed by how simple it seems. I'm now trying to
> > impliment tests in my code but this is something I've never done
> > before I've looked at the Rails way and AWDWD but can't seem to get my
> > head around how to start. Does anyone know of any very basic tutorials
> > to get me started or would people suggest I looked at RSPEC instead.

As TJ pointed out, the Thoughtbot/shoulda site has some good walk
throughs. Eventually I want to work my way up to the sort of macros
described in this article about 'embracing your inner slacker':
http://technicalpickles.com/posts/shoulda-macros-allows-you-to-embrace-your-inner-slacker
But that might be a bit much for starting.

One of the better Rails books for debugging and testing tips is
"RailsSpace"
http://www.amazon.com/RailsSpace-Building-Networking-Addison-Wesley-Professional/dp/0321480791
It was written pre-Rails 2, but late enough that the last couple of
chapters do use restful conventions.

Not a tutorial, but some interesting ideas on how to (and how not to)
test are in the Rails Way article "Testing the Right Stuff"
http://www.therailsway.com/2007/8/20/testing-the-right-stuff

lostcaggy

unread,
Jun 21, 2008, 6:26:38 PM6/21/08
to shoulda
Thanks everyone for the links and advice I found a link to a
screencast from the railsspace book which was on testing and that has
helped alot, also the shoulda tutorials. I'm starting to get the hang
of it I think :) and have managed to test two restful controllers,
next is form field validation of the models. It certainly makes you
think about the app when you are writing the tests before the code.
I've decided to leave RSPEC alone and stick with shoulda for now.

On Jun 19, 11:46 pm, Cynthia Kiser <c...@caltech.edu> wrote:
> Quoting TJ Stankus <tjstan...@gmail.com>:
>
> > RSpec seems a little heavy to me, especially for beginners.
>
> I had a brief flirtation with RSpec after the testing tutorial at
> RailsConf2007. It's nice but at the level I used it, there wasn't a
> compelling difference compared to Test::Unit. The main thing I liked
> about RSpec was that you could get an Englishy list of the tests that
> were being run. Shoulda's 'rake shoulda:list' gives me that - in
> addition to all its convenience methods. Another thing I like about
> shoulda is that it uses Test::Unit so you can easily mix the scaffold
> generated functional tests with custom tests of your own.
>
> > > Hi I've been looking at rails for a while now and have written a
> > > couple of simple app, I'm now about to start a larger app and what to
> > > start testing my code, I've saw a presentation on shoulda at scotland
> > > on rails and was impressed by how simple it seems. I'm now trying to
> > > impliment tests in my code but this is something I've never done
> > > before I've looked at the Rails way and AWDWD but can't seem to get my
> > > head around how to start. Does anyone know of any very basic tutorials
> > > to get me started or would people suggest I looked at RSPEC instead.
>
> As TJ pointed out, the Thoughtbot/shoulda site has some good walk
> throughs. Eventually I want to work my way up to the sort of macros
> described in this article about 'embracing your inner slacker':http://technicalpickles.com/posts/shoulda-macros-allows-you-to-embrac...
> But that might be a bit much for starting.
>
> One of the better Rails books for debugging and testing tips is
> "RailsSpace"http://www.amazon.com/RailsSpace-Building-Networking-Addison-Wesley-P...
Reply all
Reply to author
Forward
0 new messages