logo
  • Jobs
  • About Me
  • Contact
  • Home
« Anti-social geeks
Just writing unit tests is not good enough »

IronRuby and RSpec

Posted March 3rd, 2008 by Matt Berther

For some time, I’ve wanted to learn more about RSpec and how it can be used to express desired behavior in your story tests as well as your unit tests. At the SDWest conference today, I took a session presented by Dave Astels which started with a high-level overview of RSpec. As Dave was really one of the instigators of RSpec, I really felt like I was getting it from the source.

Something that struck me about this session is that it seems that developers should be spending much more time writing tests around interactions and behaviors than tests around expectations and state. Tests that simply assert on a return value seem to be very brittle and do little to express the intent of the code that is under test. However, writing tests to specify the desired behavior of the code seems to have much more benefit, since the developer focuses on the result of the behavior instead of the implementation. Rather than focusing on on testing your code to make sure that it functions correctly, this is much more about defining what it means for your code to function correctly. As Robert Martin puts it, “Specification, not Verification”.

I had a side conversation with Dave about his thoughts on how IronRuby might support the RSpec framework for testing C# code. He mentioned that a stated goal for the IronRuby project was to run Ruby on Rails, and he felt that if that goal was met, then RSpec should certainly run on it. As it turns out, the IronRuby folks have already done some significant work to make this happen, but they are not quite there yet. I can only say that this is one project I’ll be keeping a careful eye on. Being able to describe my C# code using the elegance of Ruby would be simply amazing.

Ruby code (especially an RSpec example) is just dead sexy to read. I mean, is there *any* doubt as to what the following code is testing:

describe "A bowling game"
	before(:each) do
		@game = BowlingGame.new
	end
 
	it "should score 300 on a perfect game" do
		12.times { @game.roll(10) }
		@game.score.should == 300
	end
end
 

By the way, the above is a snippet of my implementation of Robert Martin’s Bowling Kata. I was excited enough by the RSpec discussion to try implementing this on my own. Very nice framework. Very nice.

No Comments

This entry was posted on Monday, March 3rd, 2008 at 5:40 pm and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
-->

flag
Favorite Charity
wounded warrior project
Search
Social
  • mattberther on twitter
  • mattberther on linkedin
Syndication
Archives
  • January 2010
  • September 2009
  • July 2009
  • June 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • September 2008
  • August 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007
  • February 2007
  • January 2007
  • December 2006
  • November 2006
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006
  • April 2006
  • March 2006
  • February 2006
  • January 2006
  • December 2005
  • November 2005
  • October 2005
  • September 2005
  • August 2005
  • July 2005
  • June 2005
  • May 2005
  • April 2005
  • March 2005
  • February 2005
  • January 2005
  • December 2004
  • November 2004
  • October 2004
  • September 2004
  • August 2004
  • July 2004
  • June 2004
  • May 2004
  • April 2004
  • March 2004
  • February 2004
  • January 2004
  • December 2003
  • November 2003
  • October 2003
  • September 2003
  • August 2003
  • July 2003
  • June 2003
  • May 2003
  • April 2003
  • March 2003
mattberther.com © 2003 - 2010