【问题标题】:Rspec 'should have title' tests failing with HamlRspec“应该有标题”测试失败,Haml
【发布时间】:2011-05-06 11:05:32
【问题描述】:

我已经完成了教程,现在正在重新使用 Haml。 RSpec pages_controller_spec.rb "should be successful" 测试所有工作。 "should have the right title" 测试不起作用。 (参考教程 3.3.2)在任何重复修复或折射之前......只是重复标题。该网站工作正常......只是标题测试失败。在 Rspec 和 Haml 的各种论坛上找不到任何问题?另外,RSpec 失败消息在 HTML 中而不是 Haml 中是否正常?

PagesController GET 'home' should have the right title
 Failure/Error: response.should have_selector("title",
   expected following output to contain a <title>Bartel Sample App | Home</title> tag:
   <!DOCTYPE html>
   <html>
   <head>
   <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
   <title>Bartel's Sample App | Home</title>
   </head>
   <body>
   <h1>Sample App</h1>
   <p>
   This is the home page for the
   <a href="http://growing-stream-430.heroku.com/">Bartel Sample Application.</a>
   </p>
   </body>
   </html>
 # ./spec/controllers/pages_controller_spec.rb:14:in `block (3 levels) in <top (required)>'

【问题讨论】:

  • 当我进入教程并添加 app/views/layouts/application.html.haml 并适当调整静态页面时,rspec 规范开始工作。仍然不明白为什么最初,Rspec 无法检查正确的标题,但现在使用 @title 和应用程序布局,它工作正常。
  • 那是因为您的 html 可能没有您要查找的标题。您正在寻找 Bartel Sample App,但生成的输出显示 Bartel's Sample App。

标签: haml


【解决方案1】:

认为这是你的问题:

看起来您的测试正在寻找名为“Bartel Sample App | Home”的标题,但您的实际标题是“Bartel's Sample App | Home”。去掉撇号-s(或将其添加到测试中),您应该是绿色的。

您应该在 HTML/ERB 中得到错误,而不是在 HAML 中,因为 Ruby 解释器不使用 HAML。这只是为了您的阅读乐趣。它在运行时由 HAML 解释器转换为 ERB/H​​TML。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    相关资源
    最近更新 更多