2012-04-11 102 views
2

我在我的應用程序助手中有一個方法,但由於某種原因,當我運行我的rspec測試時沒有找到它。這裏的錯誤:ActionView中的未定義方法(rspec)

Failure/Error: helper.chart_series(user).should =~ /y: 100/ 
    undefined method `ab_variant' for #<ActionView::Base:0x102b12d78> 
    # ./app/helpers/sidebar_helper.rb:17:in `chart_series' 
    # ./spec/helpers/sidebar_helper_spec.rb:35 

我如何確保ab_variant(在應用程序助手內)可以通過我的rspec測試找到?

回答

0

默認情況下,您在app/helpers中定義的幫助程序不會在rspec中加載。你必須重新創建它們。

因此,創建一個文件並將其命名爲您喜歡的名稱,例如。 「application_helper.rb」並將其放置在spec/support中。這將被自動包含在您的specs中spec/spec_helper.rb中:

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} 
相關問題