将 HAML 与 RSPEC 集成

发布于 2024-11-01 11:08:39 字数 930 浏览 1 评论 0原文

我周六运行了大约 11 个 Rspec 测试,直到我将项目转换为 HAML。然后,当我运行测试时,我遇到了以下错误:

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_context.rb:81:in `find'

在发布原始问题 45 分钟后,我通过将以下几行添加到我的 /config/application.rb 文件中解决了自己的问题:

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

我从 半相关博客条目,但我想知道如何到底有人会知道这样做吗?据我所知,它没有记录在 HAML 中,所以这让我想知道我在安装它时是否只是做错了什么。我无法想象每个使用 HAML 的人都必须经历这一切......

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_context.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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

懒的傷心 2024-11-08 11:08:39

我不知道如何向原始问题添加评论(正如 RobZolkos 和 Dave 上面所做的那样),因此使用这个“答案”部分。

当我将空白 erb 重命名为 haml 并运行测试时,我遇到了同样的问题。然而,就我而言,问题是 Gemfile 中缺少“gem haml”。添加这一点,然后进行“捆绑安装”为我解决了这个问题。只是认为会发布在这里,因为它可能对某人有用。我不必像 Dave 那样添加“g.template_engine :haml”内容。

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.

内心荒芜 2024-11-08 11:08:39

我刚刚遇到了同样的问题,RSpec 找不到用 haml 编写的操作视图模板。然后我意识到测试环境没有考虑 haml 作为渲染引擎:


缺少模板页面/主页,其中包含 {:handlers=>[:erb, :rjs ...

因此,我通过将 haml-rails gem 添加到测试组来修复它。

因此,如果您遇到同样的问题,我建议:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文