![]() |
Articles Feed |
Categories
Archives
- July 2010 (5)
- June 2010 (4)
- April 2010 (3)
- March 2010 (2)
- February 2010 (2)
- January 2010 (1)
- December 2009 (1)
- October 2009 (2)
- September 2009 (2)
- August 2009 (1)
- July 2009 (5)
- June 2009 (2)
- May 2009 (2)
- April 2009 (8)
- March 2009 (7)
- January 2009 (2)
- December 2008 (3)
- November 2008 (5)
- October 2008 (4)
- September 2008 (6)
- August 2008 (4)
- July 2008 (5)
- June 2008 (5)
- May 2008 (4)
- April 2008 (2)
- February 2008 (4)
- January 2008 (2)
- December 2007 (2)
- November 2007 (2)
- October 2007 (2)
- September 2007 (1)
- August 2007 (3)
- July 2007 (1)
- June 2007 (4)
- May 2007 (7)
- April 2007 (2)
- February 2007 (3)
- January 2007 (3)
- November 2006 (3)
- October 2006 (3)
- September 2006 (17)
- November 2004 (1)
Test Driving Module Methods - part two
by: eric | June 15th, 2007 |
Ever write an entire blog post, spend significant time on it, correct it, and eventually grow to love it - only to discover two months later you did things the hard way?
That’s what I’ve just discovered about my post Test Driving Module Methods. Turns out I’d been missing an important feature of RSpec, the and_yield command. Whereas previously I had written static methods and monkey patched the SFTP, I simply could have written:
@mock_session.should_receive(:close_handle)
Net::SFTP.start.should_receive(:start).with("test_server", "user", "password").and_yield(@mock_session)
That lets me test that the session I’m passing in is getting the right parameters like any normal code, and is far cleaner. Frankly I should have added the feature to RSpec for my original solution - if it didn’t already exist that is. Too bad about my lovely blog post - I guess I’ll stick to push-ups.
