我正在嘗試爲inherited_resources控制器編寫規範。我決定使用rspec的mock_model模擬與數據庫的所有集成。不幸的是,我不能編寫創建和更新操作的規範,因爲我得到以下錯誤:https://gist.github.com/936947 有人可以幫我解決這個問題嗎?RSpec mock_model和inherited_resources
3
A
回答
4
我在使用flexmock時遇到同樣的問題。
原因是它沒有使用update_attributes
方法來做出路由決定。它檢查resource.errors
以查看它是否爲空。
所以爲了讓它正確響應,我們還需要剔除errors
方法。
下面是相關代碼@line 248的lib/inherited_resources/base_helpers.rb
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
0
失敗消息是關於無法從控制器內部訪問命名路由,所以我不確定這與mock_model有什麼關係。你是否用真實模型試過相同的例子?
+0
有了真正的機型它的工作沒有任何問題。 – luacassus 2011-04-22 19:47:43
相關問題
- 1. Rspec Mock_model
- 2. RSpec中stub_model和mock_model有什麼區別?
- 3. Rspec mock_model在instanced對象中不可用?
- 4. Rails mock_model返回TrueClass?
- 5. 未定義的方法`mock_model'
- 6. permitted_params - rails4和inherited_resources
- 7. 意外調用:運行rspec的規格包括mock_model時__mock_proxy()
- 8. rails rspec mock_model預期的對象,得到的字符串
- 9. 集成inherited_resources和權限
- 10. cancan和inherited_resources覆蓋集合
- 11. Rspec與inherited_resources重定向,而不是渲染失敗更新
- 12. 如何spec_helper使用mock_model器(用於Authlogic)
- 13. inherited_resources - 去父母
- 14. Ruby on Rails Inherited_resources multiple belongs_to
- 15. inherited_resources和多個belongs_to沒有嵌套
- 16. will_paginate和inherited_resources不能一起工作
- 17. 使用inherited_resources進行緩存
- 18. Inherited_resources自定義錯誤
- 19. 自定義動作爲inherited_resources
- 20. 是什麼在RSpec的
- 21. 使用mock_model測試控制器的問題
- 22. Rails3中發動機:寶石(回形針和inherited_resources)不加載
- 23. Inherited_resources建立資源作爲角色
- 24. 從inherited_resources隱藏屬性的方法
- 25. Rails 3 inherited_resources忽略'默認'設置
- 26. Minitest和Rspec
- 27. 黃瓜和Rspec
- 28. Rspec,CanCan和Devise
- 29. MIgrations和Rspec
- 30. Rspec和bundle exec
它解決了我的問題。非常感謝! ;) – luacassus 2011-04-29 06:41:21
用什麼來模擬出錯誤方法?我遇到了這個完全相同的問題...... – sevenseacat 2011-09-04 14:28:05
啊,對了,我用'team.stub_chain(:errors,:empty?)。和_return(false)'來使用stub_chain,並且它完美地工作。 – sevenseacat 2011-09-04 14:38:46