开发者

Integrating HAML with RSPEC

开发者 https://www.devze.com 2023-02-24 01:28 出处:网络
I had 11 or so Rspec tests running sat, until I converted my project to HAML. Then when I ran my tests, I got errors such as:

I had 11 or so Rspec tests running sat, until I converted my project to HAML. Then when I ran my tests, I got errors such as:

ActionView::MissingTemplate: Missing template pages/home with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} in view paths "/Users/myhomedirectory/my_app/app/views"
/Users/myhomedirectory/.rvm/gems/ruby-1.9.2-p180@global/gems/actionpack-3.0.6/lib/action_view/paths.rb:15:in `find'
/Users/myhomedirectory/.rvm/gems/ruby-1.9.2-p180@global/gems/actionpack-3.0.6/lib/action_view/lookup_contex开发者_高级运维t.rb:81:in `find'

45 minutes after posting my original question, I solved my own problem by adding the following lines to my /config/application.rb file:

config.generators do |g|
  g.template_engine :haml
end

I cobbled that together from a semi-related blog entry, but I'm wondering how the heck anyone would know to do this? It's not documented in HAML as far as I can tell, so it leaves me wondering if I simply did something wrong when I installed it. I can't imagine everyone using HAML had to go thru all that...


I couldn't figure out to how to add a comment to the original question (as RobZolkos and Dave have done above) and so using this "answer" section.

I faced the same issue, when I renamed a blank erb to haml, and ran the tests. However, in my case, the issue was "gem haml" was missing in the Gemfile. Adding that, followed by a "bundle install" solved the issue for me. Just thought will post here since it might be useful for someone. I didn't had to add the "g.template_engine :haml" stuff, as Dave had to.


I just had the same issue where RSpec wouldn't find the action view templates written in haml. Then I realized that the test environment wasn't considering haml as rendering engine:

Missing template pages/home with {:handlers=>[:erb, :rjs ...

So, I fix it by adding the haml-rails gem to the test group.

Thus, if you have the same issue I recommend:

group :development, :test do
  gem 'rspec-rails'
  ...
  gem 'haml-rails'
end
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号