I like RSpec, but I'm not a huge fan of it's built in mocking framework. So, when I have the choice, I swap it out for Mocha. However, I really miss mock_model. If you haven't used it, mock_model is an RSpec method where you pass in an ActiveRecord object and it stubs out a whole bunch AR magic so you don't have to. This is crazy useful when testing controllers because when you controller has a line like this:
redirect_to(@model)
I don't want to dig through a ton of Rails code to figure out what I need to stub on this model, I just want it to work. But I just found out that Mislav Marohnić has written a plugin that implements mock_model for Mocha -- so now I can get the best of both worlds. You can find it here:
http://github.com/mislav/rspec-rails-mocha
Thanks Mislav.
Subscribe to:
Post Comments (Atom)
About Me
Obtiva (current job)
ThoughtWorks (old job)
Object Mentor (apprentice)
Apprenticeship at Object Mentor Blog
ThoughtWorks (old job)
Object Mentor (apprentice)
Apprenticeship at Object Mentor Blog
Blog Archive
- July 2009 (12)
- June 2009 (19)
- May 2009 (12)
- April 2009 (12)
- March 2009 (4)
- January 2009 (1)
- December 2008 (1)
- November 2008 (12)
- October 2008 (2)
- September 2008 (10)
- August 2008 (5)
- June 2008 (3)
- May 2008 (3)
- April 2008 (2)
- March 2008 (3)
- February 2008 (2)
- January 2008 (5)
- November 2007 (1)
- October 2007 (1)
- September 2007 (1)
- August 2007 (6)
- July 2007 (3)
- June 2007 (4)
- May 2007 (5)
- April 2007 (4)
- March 2007 (10)
- February 2007 (13)
- January 2007 (7)
Categories-
- Code (61)
- Rails (48)
- Apprenticeship (33)
- Ruby (25)
- commentary (25)
- RSpec (20)
- Metrics (17)
- metric_fu (13)
- Flog (9)
- RailsConf2009 (8)
- complexity (8)
- RubyConf2008 (7)
- test_coverage (7)
- Bugs (6)
- Mocking (6)
- craftsman_swap (6)
- git (6)
- not_code (6)
- Amazon (5)
- refactoring (5)
- ActiveRecord (4)
- Linux (4)
- LoneStarRubyConf2008 (4)
- Saikuro (4)
- churn (4)
- design (4)
- Fixtures (3)
- JRuby (3)
- RailsConf2007 (3)
- Rake (3)
- Rcov (3)
- Svn (3)
- legacy_code (3)
- Flay (2)
- GLSEC (2)
- Math (2)
- Mingle (2)
- Obtiva (2)
- SQuiD (2)
- TextMate (2)
- Windows (2)
- WindyCityRails (2)
- XP (2)
- javascript (2)
- testing (2)
- Agile2009 (1)
- DUST (1)
- EVDO (1)
- IO (1)
- MacRuby (1)
- OSX (1)
- Routes (1)
- RubyWorks (1)
- Tomcat (1)
- attachment_fu (1)
- cache-fu (1)
- citcon (1)
- iPhone (1)
- mac (1)
- memcached (1)
- ord_sessions (1)
- pairing (1)
- restful_authentication (1)


2 comments:
Personally, I use mock_model of my own which just stubs #id method to return some integer (with ability to autogenerate it) and #new_record?.
That's it. And I use real model instance, so I can rely on logic that is already there.
U're welcome ;)
Post a Comment