RoR 3.1:使用 rspec 测试正确的标题

发布于 2024-12-12 10:37:59 字数 1520 浏览 0 评论 0原文

require 'spec_helper'
describe "LayoutLinks" do
  it "should have a Home page at '/'" do
   get '/'
   response.should have_selector('title', :content => "Home")
 end
end

规范来源: https://github.com/railstutorial/sample_app/ blob/master/spec/requests/layout_links_spec.rb (我正在读这本书)

我尝试放置integrate_views和render_views,但它返回了未定义的变量错误。

$ guard
Guard is now watching at '[project dir]'
Guard::RSpec is running, with RSpec 2!
Running all specs
F

Failures:

  1) LayoutLinks should have a Home page at '/'
     Failure/Error: response.should have_selector('title', :content => "Home")
       expected css "title" to return something
     # ./spec/requests/layout_links_spec.rb:5:in `block (2 levels) in <top (required)>'

Finished in 13.15 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/requests/layout_links_spec.rb:3 # LayoutLinks should have a Home page at '/'

我的 Gemfile 的一部分:

gem 'rails', '3.1.0'

group :development, :test do
  gem 'turn', :require => false
  gem 'sqlite3'
  gem "rspec-rails"
  gem "factory_girl_rails"
  gem "capybara"
  gem "guard-rspec"
end

用于设置我遵循的所有内容: http://railscasts.com/episodes/275-how-i-test ?view=asciicast

我的根目录的一部分:有标题标签并位于“站点名称 | 主页”内

require 'spec_helper'
describe "LayoutLinks" do
  it "should have a Home page at '/'" do
   get '/'
   response.should have_selector('title', :content => "Home")
 end
end

Spec source: https://github.com/railstutorial/sample_app/blob/master/spec/requests/layout_links_spec.rb
(I'm reading the book)

I tried putting integrate_views and render_views, but it returned an undefined variable error.

$ guard
Guard is now watching at '[project dir]'
Guard::RSpec is running, with RSpec 2!
Running all specs
F

Failures:

  1) LayoutLinks should have a Home page at '/'
     Failure/Error: response.should have_selector('title', :content => "Home")
       expected css "title" to return something
     # ./spec/requests/layout_links_spec.rb:5:in `block (2 levels) in <top (required)>'

Finished in 13.15 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/requests/layout_links_spec.rb:3 # LayoutLinks should have a Home page at '/'

Part of my Gemfile:

gem 'rails', '3.1.0'

group :development, :test do
  gem 'turn', :require => false
  gem 'sqlite3'
  gem "rspec-rails"
  gem "factory_girl_rails"
  gem "capybara"
  gem "guard-rspec"
end

For setting up everything I followed:
http://railscasts.com/episodes/275-how-i-test?view=asciicast

Part of my root directory: Has the title tag and inside "Name of Site | Home"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌无敌 2024-12-19 10:37:59

试试这个:

response.should have_xpath("//title", :text => "Name of Site | Home")

Try this:

response.should have_xpath("//title", :text => "Name of Site | Home")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文