【问题标题】:have_selector testing page title does not workhave_selector 测试页面标题不起作用
【发布时间】:2013-04-18 04:26:24
【问题描述】:

我有以下代码用于测试

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版

【问题讨论】:

标签: ruby-on-rails rspec title


【解决方案1】:

试试:

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

【讨论】:

  • 我仍然有以下错误:
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多