【发布时间】: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