1

我有以下代码用于测试

require 'spec_helper'

describe PagesController do
render_views

describe "GET 'home'" do
 it "returns http success" do
  get 'home'
  response.should be_success
 end

 it "should have the right title" do 
  get 'home'
  response.should have_selector("title", :content => "Ruby on Rails Tutorial Sample App | Home")
 end
end

但是当我运行 rspec spec/ 时,我在验证页面标题时出错。我已将 home.html.erb 修改为此

<!DOCTYPE html>
<html>
<head>
    <title>Ruby on Rails Tutorial Sample App | Home</title>

</head>
<body>
    <h1>Sample App Home Page</h1>
    <p>Find me in app/views/pages/home.html.erb</p>
</body>
</html>

我有 rspec 版本 2.13.0 水豚版本 2.1.0

4

1 回答 1

0

尝试:

response.should have_content "Ruby on Rails Tutorial Sample App | Home"
于 2013-04-18T07:28:48.877 回答