Saturday, July 28, 2007

rspec Just keeps getting better

Well it's not what I had in mind for my first post on this blog.

I've just been working on my rails project where I'm writing specs using rspec in a controller. What I'm trying to do is spec that under a set of circumstances a particular template is rendered.

This was my first attempt


it "should render with my_layout" do
controller.should_receive( :render ).with( :layout => "my_layout" )
do_get
end


This didn't work. It gave me an error that render was called without the arguments.

My hat goes off to David Chelimsky who seems to answer just about everyones questions on the rspec mailing list. Within 10 minutes of posting my issue to the mailing list David responded by recommending a new method in the trunk. expect_render

Since I'm using piston to manage my plugins, a quick

piston update vendor/plugins/rspec
piston update vendor/plugins/rspec_on_rails


brought me up to speed. I changed my spec to his suggestion:


it "should render with my_layout" do
controller.expect_render( :layout => "my_layout" )
do_get
end


Once I tried this it worked great.

I really like rspec. My testing has never been better since I started using it.