From: "J. B. Rainsberger" Date: 2006-11-28T11:44:49+09:00 Subject: Mocha and ActiveRecord Everyone: I've been using Mocha, which I rather love, to help me test-drive some Rails code. I've run up against something a little clunky, and I'm hoping one of you can help me out. Suppose I have an Order, which has_many OrderItems. Suppose I want to write a test that checks that when I ask the Order to do something, it asks its order items to do that something. I tried to do this like so: def test_delegates order_items = [] 3.times { item = mock("order item", :do_something => nil) order_items.push(item) } order = Order.new(:order_items => order_items) order.do_something end This works with normal objects, but it seems ActiveRecord objects don't like someone passing them Mocha::Mock objects in their constructors. They check that the order items, in this case, are OrderItem objects. Is there something in ActiveRecord I can override to relax this behavior? I don't like having to create an OrderItem just to add a single stub or expectation. Thanks for your help. -- J. B. (Joe) Rainsberger :: http://www.jbrains.ca Your guide to software craftsmanship JUnit Recipes: Practical Methods for Programmer Testing 2005 Gordon Pask Award for contribution Agile Software Practice