Hanalei, Hawaii 9/2/2010
438 Posts and Counting

Webcast: Unit Testing With Rails

Wednesday, August 08, 2007 -

A lot people keep emailing me and letting me know how much they like the Rails webcasts I've been doing so I thought I'd continue today with a webcast all about their Unit Testing framework.

I mention this in the video, but it's worth writing here: I'm not trying to "convert" or sway people - my goal is to show what's out there. Rails has some very very cool stuff that goes into it, and it's built-in unit testing feature is quite cool. Maybe one day we can see something like this in the .NET stack that's part of the framework and not a function of the IDEĀ (no EULA comments please :):):).

This webcast is about 20 minutes long and I show you how to set up Unit Tests, and also some tips and tricks for generating test data using YML.

You can view it here!

Related


Gravatar
Ryan - Wednesday, August 08, 2007 - That's funny...early on SubSonic made me curious about Rails....and now I'm hooked. Thanks Rob!
Gravatar
Zack Owens - Thursday, August 09, 2007 - Hmmm.... I see a lot of similarities with Rails and ASP.NET. But very cool stuff.
Gravatar
Haacked - Thursday, August 09, 2007 - Great WebCast Rob! You're inspiring me to make my own. My first one will be entitled "How Rob is like Lindsay Lohan"
Gravatar
Haacked - Thursday, August 09, 2007 - Rob, how about a screencast where you demo common UI implementations the "Rails Way"?

For example, suppose I want to use a dropdown to call a controller action on select. How would I do that?
Gravatar
Rob Conery - Thursday, August 09, 2007 - @Phil - thanks :). I had a fun time making it...

In terms of the UI stuff - it's actually very easy. For most things, there's a Rails short cut - for instance, to setup a link to a different page you write:

<%=link_to "link text", :controller => "mycontroller", :action => "myaction"%>

In your case, you might want to wrap your dropdown in a form, and then post the results to a controller. That's pretty simple:

(the form code)
<% form_for :myobject, :url => { :action => :myobject_controller_action } do |form| %>

#now you have a form that is "dedicated" to a model and controller/action set. To create a drop down you can:

<%= collection_select(:myobject, :myobject_foreign_key ,LookupContoller.find(:all), :id, :name) %>

This will load up your dropdown for you.

One thing I needed to get used to was using more than one form - ASP only allows one per page - Rails uses them liberally :).
Gravatar
Rob Conery - Thursday, August 09, 2007 - @zack - you see similarities? The only thing similar I see is the <%=%> syntax.

Keep in mind here that the Unit Tests are actually testing your web site - NOT just code behind. It's all the same to the tests which is a Major Leap if you ask me.

Also, forcing the separation of model and functional testing is brilliant :).