我有一個RSpec規格:如何在運行槽Spork時在ApplicationHelper Spec中包含路由?
require "spec_helper"
describe ApplicationHelper do
describe "#link_to_cart" do
it 'should be a link to the cart' do
helper.link_to_cart.should match /.*href="\/cart".*/
end
end
end
而且ApplicationHelper:
module ApplicationHelper
def link_to_cart
link_to "Cart", cart_path
end
end
訪問該網站時,此工作,但規格失敗,並拋出一個RuntimeError關於路由不是可供選擇:
RuntimeError:
In order to use #url_for, you must include routing helpers explicitly. For instance, `include Rails.application.routes.url_helpers
所以,我在我的規範中包含Rails.application.routes.url
,文件spec_helper
甚至ApplicationHelper
本身,t o無濟於事。
編輯:我正在通過spork運行測試,
也許與它有關
並導致此問題。
與Spork一起運行時,如何包含這些路線助手?
我已經試過了,它不會讓測試通過:失敗消息保持不變。 – berkes
@berkes,我已經在發佈答案之前在我的控制檯中驗證過。有用。在你的問題中,我只看到你提到包括它在測試中,但沒有ApplicationHelper模塊。這是不正確的。 –
它也不是'ApplicationController',但'ApplicationHelper' –