【发布时间】:2010-11-01 23:45:17
【问题描述】:
使用资源路由,您可以执行 url_for(@apple) 之类的操作来获取特定资源“显示”方法的 url。但是,在测试中,使用 Mocha 来模拟我的对象时,我无法生成到资源的适当路径。
例如考虑这个 url_for 如何路由的例子:
@apple.id # => 4
url_for(@apple) #=> domain.com/apples/4
这相当于更详细的:
url_for(:controller => 'apples', :id => 4, :method => :show)
在尝试测试我的观点时,我使用 Mocha 来模拟我的对象。
Apple.stubs(:color => 'red') # returns a MochaExpectation, rather than an instance of Apple.
所以在我的测试中:
assigns[:apple] = @apple = Apple.stubs(:color => 'red')
url_for(@apple) #=> raises undefined method `mocha_expectation_path'
我怎样才能接近这个?似乎存根需要返回 Apple
【问题讨论】:
标签: ruby-on-rails testing mocha.js