This really caught me unguarded. The stocks/index.html.haml renders without problem in browser after I installed the haml-rails gem. However, when I tried to test it using rspec/capybara
describe "StockPages" do
describe "stocks/index.html.haml" do
before {visit stocks_path}
subject {page}
it { should have_selector('table#Result') }
end
end
I got this error:
Failure/Error: before {visit stocks_path}
ActionView::MissingTemplate:
Missing template stocks/index, application/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}.
How do I solve this?
Thanks
In order to render Haml templates, you need the
hamlgem loaded.haml-railsdoes callrequire 'haml', but if you’ve only addedhaml-railsto the development group in yourGemfilethenhamlwill also only get loaded in development.In order to fix this, you need to either move
haml-railsout of any group so that it always gets loaded (and sohamlalso always gets loaded), or addgem 'haml'to yourGemfile(outside of any group). The first option (movehaml-railsout of the development group) is likely the easiest, but you might want to leave it in the development group and explicitly addgem 'haml'in order to avoid loading unneeded code in production.