我正在运行Rails 3.0.1和Rspec 2.0.1。我正在关注M. Hartl的Ruby on Rails教程,并且在第5课:填充布局时遇到了测试失败的问题。
当我运行自动测试时,不断收到此错误并且似乎无法弄清楚原因:
Failures:
1) UsersController GET 'new' should have the right title
Failure/Error: response.should have_selector('title', :content => "Sign Up")
expected following output to contain a <title>Sign Up</title> tag:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Ruby on Rails Tutorial Sample App | Sign up</title>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js""></script>
<![endif]--><link href="/stylesheets/blueprint/screen.css?1313951692" media="screen" rel="stylesheet" type="text/css">
<link href="/stylesheets/blueprint/print.css?1313951692" media="media" rel="stylesheet" type="text/css">
<!--[if lt IE 8]><link href="/stylesheets/blueprint/ie.css?1313951692" media="screen" rel="stylesheet" type="text/css" /><[endif]--><link href="/stylesheets/custom.css?1319319986" media="screen" rel="stylesheet" type="text/css">
</head>
<body>
<div class="container">
<nav class="round"><ul>
<li><a href="/">Home</a></li>
<li><a href="/help">Help</a></li>
<li><a href="#">Sign in</a></li>
</ul></nav></header><section class="round"><h1>Users#new</h1>
<p>Find me in app/views/users/new.html.erb</p>
</section><footer><nav class="round"><ul>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
<li><a href="http://news.railstutorial.org">News</a></li>
<li><a href="http://railstutorial.org">Rails Tutorial</a></li>
</ul></nav></footer>
</div>
</body>
</html>
# ./spec/controllers/users_controller_spec.rb:14:in `block (3 levels) in <top (required)>'
答案 0 :(得分:1)
您遇到的问题是您的测试中有
response.should have_selector('title', :content => "Sign Up")
但您的HTML代码是
<title>Ruby on Rails Tutorial Sample App | Sign up</title>
您的测试和HTML源代码不匹配。在源代码中大写“up”,你会很高兴。
答案 1 :(得分:0)
我认为这是一个案例问题。内容不必完全匹配,但案例确实如此。
是的......诺亚说的话。