我正在尝试为inherited_resources控制器编写规范。我决定使用rspec的mock_model模拟所有与数据库的集成。不幸的是,我不能为创建和更新操作编写规范,因为我得到了以下错误:https://gist.github.com/936947,有人能帮我解决这个问题吗?
发布于 2011-04-29 05:02:26
我在使用flexmock时也遇到了同样的问题。
原因是它没有使用update_attributes方法进行路由决策。它检查resource.errors以查看它是否为空。
因此,为了让它正确响应,我们还需要模拟errors方法。
下面是相关的代码,代码位于lib/inherited_resources/base_helpers.rb中的第248行
def respond_with_dual_blocks(object, options, &block) #:nodoc:
args = (with_chain(object) << options)
case block.try(:arity)
when 2
respond_with(*args) do |responder|
blank_slate = InheritedResources::BlankSlate.new
if object.errors.empty?
block.call(responder, blank_slate)
else
block.call(blank_slate, responder)
end
end
when 1
respond_with(*args, &block)
else
options[:location] = block.call if block
respond_with(*args)
end
end发布于 2011-04-23 00:49:13
失败消息是关于无法从控制器内部访问命名路由,所以我不确定这与mock_model有什么关系。你用真实的模型试过同样的例子吗?
https://stackoverflow.com/questions/5757584
复制相似问题