【问题标题】:RoR 3.1: Testing correct titles with rspecRoR 3.1:使用 rspec 测试正确的标题
【发布时间】:2011-10-30 22:47:00
【问题描述】:
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

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

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 rspec tdd


    【解决方案1】:

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 2011-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多