我正在寫一個視圖規範,它使得包含行(HAML)一個觀點:如何在Rails中存根路徑生成方法?
=link_to new_post_path
但與規範失敗:
ActionController::RoutingError: No route matches {:action=>"new", :controller=>"post"}
我試圖存根new_post_path
方法,因爲它對於視圖規範並不重要,但沒有任何運氣。
我試過,我的規格內,下面的兩個變化沒有任何的運氣:
stub!(:new_post_path).and_return("this path isn't important")
controller.stub!(:new_post_path).and_return("this path isn't important")
謝謝,事實證明,我的錯誤實際上是在其他地方,你卻幫我找到了解如何存根。 – jefflunt
這隻適用於我,如果我在我的視圖中使用'Rails.application.routes.url_helpers.new_host_path'而不是正常的'new_host_path' p.s.我使用rspec 3.2語法'allow(Rails.application.routes.url_helpers).to receive(:new_host_path).and_return(「/」)' – ryan2johnson9
@ ryan2johnson9如果你知道了,你介意發佈你的解決方案嗎?我有同樣的問題。 –