2012-07-27 29 views
2

這真的讓我無法防備。在安裝haml-rails gem後,stocks/index.html.haml在瀏覽器中呈現無問題。然而,當我試圖測試使用RSpec的/水豚haml rspec失蹤模板

describe "StockPages" do 
    describe "stocks/index.html.haml" do 
    before {visit stocks_path} 
    subject {page} 
    it { should have_selector('table#Result') } 
    end 
end 

我得到這個錯誤:

Failure/Error: before {visit stocks_path} 
    ActionView::MissingTemplate: 
     Missing template stocks/index, application/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. 

如何解決這個問題? 謝謝

+1

你是怎麼把'haml-rails' gem加到你的'Gemfile'中的,是不是隻在開發組中? – matt 2012-07-27 20:53:53

+0

我是多麼愚蠢!你是對的。那麼我也應該把它包含在測試組中呢?生產如何? – zsljulius 2012-07-27 21:10:06

回答

3

爲了渲染Haml模板,您需要加載haml gem。 haml-rails確實請撥require 'haml',但如果您只將haml-rails添加到您的Gemfile中的開發組,那麼haml也只會在開發中加載。

爲了解決這個問題,你需要或者移動haml-rails任何組,使其始終被加載(等haml也總是被載入),或添加gem 'haml'Gemfile(任何組之外)。第一個選項(將haml-rails移出開發組)可能是最簡單的,但您可能希望將其留在開發組中,並明確添加gem 'haml'以避免在生產中加載不需要的代碼。