【发布时间】:2011-10-28 19:44:28
【问题描述】:
我正在尝试编写一些规范,并希望删除对数据库的调用,因此我不依赖实际填充的数据库来运行测试。
现在我真的不知道如何使用 DataMapper 对关联之间的调用进行存根。
以下是两个示例模型:
class Foo
include DataMapper::Resource
property :id, Serial
has n, :bars
end
class Bar
include DataMapper::Resource
property :id, Serial
belongs_to :foo
end
现在我想将呼叫存根到 Foo.first('foobar') 和 Foo.first('foobar').bars
第一个使用Foo.stub(:first) { #etc } 没有问题,但我不知道如何存根对其关联的第二次调用。
Foo.stub(:bars) { #etc } 之类的东西不起作用。
有人知道怎么做吗?这种方法是否正确?
提前致谢。
【问题讨论】:
标签: ruby testing datamapper rspec2 stub