The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Extension to FlexMock

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
David Naseby

Posts: 40
Nickname: naseby
Registered: Jun, 2004

David Naseby is a coder from Sydney, who codes in Ruby far too much yet not nearly enough.
Extension to FlexMock Posted: Oct 22, 2004 10:36 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by David Naseby.
Original Post: Extension to FlexMock
Feed Title: naseby + ruby + stuff
Feed URL: http://homepages.ihug.com.au/~naseby/rss.xml
Feed Description: Random wanderings through Ruby.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by David Naseby
Latest Posts From naseby + ruby + stuff

Advertisement
I love \Jim Weirich’s blog\ – I believe it typifies what a blog should be, in that its not just a useless pointer at someone who points at someone else’s original content, but a content provider (for useless blogs such as this one to point at…). Rake also, I love. I’ve noted my love of his dependancy injection article. I’ve never met the man, but there is some small chance I love him as well. Yet another thing I’ve recently learnt to love is his quick and dirty \FlexMock\ test mock framework. Its a gem – try it out yourself with gem install -r FlexMock. \n\nBut one thing makes me uncomfortable with Mock frameworks: my innate, extreme stupidity. My unique ability to mock a method, then fail completely to implement it. To workaround my imbicilic nature, I’ve extended FlexMock to gently remind me to do some extra work. Here’s a bit of self-typed diff to show how its done:\n\n
\n\n#flexmock.rb, line 25-30\n-  def initialize\n+  def initialize mocked_class = nil\n     @handlers = Hash.new\n     @counts   = Hash.new(0)\n     @expected_counts = Hash.new\n+    @mocked_class = mocked_class\n   end\n#flexmock.rb, line 48-55\n  def mock_verify\n    @expected_counts.keys.each do |key|\n      assert_equal @expected_counts[key], @counts[key],\n\t\"Expected method #{key} to be called #{@expected_counts[key]} times, \"\n\t\"got #{@counts[key]}\"\n+     assert @mocked_class.respond_to?( key ), \n        \"Expected #{@mocked_class} to respond to method #{key}.\" unless @mocked_class.nil?\n    end\n  end\n\n
\n\nThis change allows me to use FlexMock in the old manner, uncaring about my stupidity (or blissfully assuming I’ll update the class later, as I bloody well should), or to use it to check my assumptions. I suspect it’d fall down if the class I was verifying was a proxy or used method_missing tricks, but then, I just wouldn’t verify that sort of class.

Read: Extension to FlexMock

Topic: Ruby CVS Commit Feed Previous Topic   Next Topic Topic: Some Borges Banter

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use