Ruby on rails RubyonRails选择器标题

Ruby on rails RubyonRails选择器标题,ruby-on-rails,ruby,selector,Ruby On Rails,Ruby,Selector,我遵循railstutorials.org上的教程,但它有点旧,我对“have_选择器”有问题 我必须使用这个命令: it "doit avoir le bon titre" do get :home expect(response).to have_selector('title', :text => " | Acceuil") end 但是我在启动rspec

我遵循railstutorials.org上的教程,但它有点旧,我对“have_选择器”有问题

我必须使用这个命令:

it "doit avoir le bon titre" do
        get :home
        expect(response).to have_selector('title', 
                                           :text => " | Acceuil")
    end
但是我在启动rspec spec/时出现了这个错误:

1) PagesController GET home doit avoir le bon titre
     Failure/Error: expect(response).to have_selector('title',
       expected to find css "title" with text " | Acceuil" but there were no matches
     # ./spec/controllers/pages_controller_spec.rb:13:in `block (3 levels) in <top (required)>'
1)页面控制员回家做一件事
失败/错误:预期(响应)。要有_选择器('标题',
希望找到带有文本“|Acceuil”的css“title”,但没有匹配项
#./spec/controllers/pages\u controller\u spec.rb:13:in'block(3层)in'
以下是home.html.erb:

<!DOCTYPE html>
<html>
  <head>
    <title>Simple App du Tutoriel Ruby on Rails | Accueil</title>
  </head>
  <body>
    <h1>Simple App</h1>
    <p>
      Ceci est la page d'accueil de l'Application Exemple du
      <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>.
    </p>
  </body>
</html>

Ruby on Rails教程的简单应用程序| Accueil
简单应用程序

这是一个应用程序示例的页面
.

这是我的档案:

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0'
ruby '2.2.0'
# Gem utile pour le sample d'exemple
gem 'gravatar_image_tag', '1.2.0'
gem 'will_paginate', '3.0.7'
gem 'rails_12factor'

group :development do
  gem 'rspec-rails', '3.1.0'
  gem 'annotate', '2.6.5'
  gem 'faker', '1.4.3'
end

group :test do
  gem 'rspec', '3.1.0'
  gem 'capybara'
  gem 'webrat', '0.7.3'
  gem 'spork', '0.9.2'
  gem 'factory_girl_rails', '4.5.0'
end

group :production, :staging do
  gem "pg"
end

group :development, :test do
  gem "sqlite3"
end
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'

  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'

  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end
源代码'https://rubygems.org'
#捆绑边缘Rails:gem'Rails',github'Rails/Rails'
gem“rails”、“4.2.0”
ruby“2.2.0”
#示例
gem“gravatar_图像_标签”,“1.2.0”
gem“将分页”,“3.0.7”
gem“rails_12factor”
小组:发展怎么办
gem'rspec rails','3.1.0'
gem‘注释’、‘2.6.5’
宝石“赝品”,“1.4.3”
终止
组:测试do
gem“rspec”,“3.1.0”
宝石“水豚”
创业板“网络鼠”,“0.7.3”
宝石'spork','0.9.2'
gem“工厂女孩轨道”,“4.5.0”
终止
组:生产,:暂存do
宝石“pg”
终止
小组:开发,:测试
gem“sqlite3”
终止
#将SCS用于样式表
gem'sass-rails',“~>5.0”
#使用Uglifier作为JavaScript资产的压缩器
gem'uglifier','>=1.3.0'
#将CoffeeScript用于.coffee资产和视图
gem“咖啡轨”,“~>4.1.0”
#看https://github.com/sstephenson/execjs#readme 获取更多受支持的运行时
#宝石“therubyracer”,平台::ruby
#使用jquery作为JavaScript库
gem'jqueryrails'
#Turbolinks使web应用程序中的以下链接更快。阅读更多内容:https://github.com/rails/turbolinks
gem“涡轮链接”
#轻松构建JSON API。阅读更多信息:https://github.com/rails/jbuilder
gem'jbuilder',“~>2.0”
#bundle exec rake doc:rails在doc/API下生成API。
gem'sdoc','~>0.4.0',组::doc
#使用ActiveModel具有\u安全\u密码
#gem'bcrypt',“~>3.1.7”
#使用Unicorn作为应用程序服务器
#宝石“独角兽”
#使用Capistrano进行部署
#gem“capistrano rails”,集团::开发
小组:开发,:测试
#在代码中的任意位置调用“byebug”以停止执行并获得调试器控制台
宝石“比伯”
#在异常页面上或通过在视图中使用访问IRB控制台
gem“web控制台”,“~>2.0”
#Spring通过让您的应用程序在后台运行来加速开发。阅读更多:https://github.com/rails/spring
宝石“春天”
终止

提前非常感谢:)

我的感觉是,使用水豚的
has_title
has_title
方法,您会得到更好的服务。不管怎么说,使用
xxx\u title
似乎在语义上更有意义,因为这正是您想要的


expect(page)。为了有标题(“某些内容”)

我用页面更新了主要问题谢谢你的回答,我尝试了与have\u title不同的组合,但没有任何效果。。正确的配方是什么?如何使用?提前感谢我一点也没有使用过Rspec(去年年底改为Minitest),但我相信
expect(第页)。有标题(“你的文本”)
应该行得通。Bummer。当我运行一个检查页面标题(显示代码段)的规范时,它可以工作。注意:have_title与整个标题匹配。。。不仅仅是其中的一部分。因此,您需要有
expect(第页)。要有_title(“简单应用程序du tutorialruby on Rails | acueil”)
现在是错误…:失败/错误:预期(第页)。要有_标题(“简单应用程序du Tutoriel Ruby on Rails | acueil”)名称错误:未定义的局部变量或方法#我的道歉。。。我刚才在OP中看到一条评论,您正在从一个控制器规范运行它。我在功能(即集成)规范中运行类似的测试。