have_selector测试页面标题不起作用

时间:2013-04-18 04:26:24

标签: ruby-on-rails rspec title

我有以下测试代码

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 capybara版本2.1.0

1 个答案:

答案 0 :(得分:0)

尝试:

response.should have_content "Ruby on Rails Tutorial Sample App | Home"