J
J. B. Rainsberger
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.neworder_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.
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.neworder_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.