Ruby on rails RSpec模拟_模型和继承的_资源
我正在尝试为继承的资源控制器编写规范。我决定使用rspec的mock_模型模拟与数据库的所有集成。很遗憾,我无法为创建和更新操作编写规范,因为我遇到以下错误:Ruby on rails RSpec模拟_模型和继承的_资源,ruby-on-rails,ruby,rspec,inherited-resources,Ruby On Rails,Ruby,Rspec,Inherited Resources,我正在尝试为继承的资源控制器编写规范。我决定使用rspec的mock_模型模拟与数据库的所有集成。很遗憾,我无法为创建和更新操作编写规范,因为我遇到以下错误: 有人能帮我解决这个问题吗?失败消息是关于无法从控制器内部访问命名路由,因此我不确定这是否与mock_模型有关。您是否尝试过使用真实模型的相同示例?我使用flexmock时遇到了相同的问题 原因是它没有使用update\u attributes方法来做出路由决策。它检查资源.errors以查看它是否为空 因此,为了让它正确响应,我们还需要模
有人能帮我解决这个问题吗?失败消息是关于无法从控制器内部访问命名路由,因此我不确定这是否与mock_模型有关。您是否尝试过使用真实模型的相同示例?我使用flexmock时遇到了相同的问题 原因是它没有使用
update\u attributes
方法来做出路由决策。它检查资源.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
def respond_与双_块(对象、选项和块)#:nodoc:
args=(with_chain(object)Mock out errors方法with what,确切地说?我遇到了完全相同的问题…啊,对了,我在team.stub_chain(:errors,:empty?)和\u return(false)
中使用了stub_chain,它工作得非常好。