2011-08-28 127 views
0

我正在通过Michael Hartl's tutorial进行工作,并已完成第9课。我在使用rake spec时发生错误,但未进行自动测试。更新几个宝石后,我现在使用自动测试获得以下错误。将'webrat','0.7.1'添加到我的gem文件中并没有帮助。Ruby on Rails教程

失败:

1) LayoutLinks should have a Home page at '/' 
    Failure/Error: response.should have_selector('title', content=> "Home") 
    NameError: 
     undefined local variable or method `content' for #<RSpec::Core::ExampleGroup::Nested_5:0x007f8cf9bc5100> 
    # ./spec/requests/layout_links_spec.rb:7:in `block (2 levels) in <top (required)>' 

    2) LayoutLinks should have a Contact page at '/contact' 
    Failure/Error: response.should have_selector('title', content=> "Contact") 
    NameError: 
     undefined local variable or method `content' for #<RSpec::Core::ExampleGroup::Nested_5:0x007f8cf9af1ee0> 
    # ./spec/requests/layout_links_spec.rb:12:in `block (2 levels) in <top (required)>' 

    3) LayoutLinks should have a About page at '/about' 
    Failure/Error: response.should have_selector('title', content=> "About") 
    NameError: 
     undefined local variable or method `content' for #<RSpec::Core::ExampleGroup::Nested_5:0x007f8cf997eb80> 
    # ./spec/requests/layout_links_spec.rb:17:in `block (2 levels) in <top (required)>' 

    4) LayoutLinks should have a Help page at '/help' 
    Failure/Error: response.should have_selector('title', content=> "Help") 
    NameError: 
     undefined local variable or method `content' for #<RSpec::Core::ExampleGroup::Nested_5:0x007f8cf949b280> 
    # ./spec/requests/layout_links_spec.rb:22:in `block (2 levels) in <top (required)>' 

    5) LayoutLinks should have a signup page at '/signup' 
    Failure/Error: response.should have_selector('title', content=> "Sign up") 
    NameError: 
     undefined local variable or method `content' for #<RSpec::Core::ExampleGroup::Nested_5:0x007f8cf921cdb0> 
    # ./spec/requests/layout_links_spec.rb:27:in `block (2 levels) in <top (required)>' 

    6) LayoutLinks should have a signin page at '/signin' 
    Failure/Error: response.should have_selector('title', content=> "Sign in") 
    NameError: 
     undefined local variable or method `content' for #<RSpec::Core::ExampleGroup::Nested_5:0x007f8cfd95c2c0> 
    # ./spec/requests/layout_links_spec.rb:32:in `block (2 levels) in <top (required)>' 

    7) LayoutLinks when signed in should have a signout link 
    Failure/Error: visit signedin_path 
    NameError: 
     undefined local variable or method `signedin_path' for #<RSpec::Core::ExampleGroup::Nested_5::Nested_2:0x007f8cfd9fe160> 
    # ./spec/requests/layout_links_spec.rb:60:in `block (3 levels) in <top (required)>' 

    8) LayoutLinks when signed in should have a profile link 
    Failure/Error: visit signedin_path 
    NameError: 
     undefined local variable or method `signedin_path' for #<RSpec::Core::ExampleGroup::Nested_5::Nested_2:0x007f8cfd9e9da0> 
    # ./spec/requests/layout_links_spec.rb:60:in `block (3 levels) in <top (required)>' 

Finished in 1.93 seconds 
70 examples, 8 failures 

失败的例子:

rspec ./spec/requests/layout_links_spec.rb:5 # LayoutLinks should have a Home page at '/' 
rspec ./spec/requests/layout_links_spec.rb:10 # LayoutLinks should have a Contact page at '/contact' 
rspec ./spec/requests/layout_links_spec.rb:15 # LayoutLinks should have a About page at '/about' 
rspec ./spec/requests/layout_links_spec.rb:20 # LayoutLinks should have a Help page at '/help' 
rspec ./spec/requests/layout_links_spec.rb:25 # LayoutLinks should have a signup page at '/signup' 
rspec ./spec/requests/layout_links_spec.rb:30 # LayoutLinks should have a signin page at '/signin' 
rspec ./spec/requests/layout_links_spec.rb:66 # LayoutLinks when signed in should have a signout link 
rspec ./spec/requests/layout_links_spec.rb:71 # LayoutLinks when signed in should have a profile link 

,这里是我的Gemfile:

source 'http://rubygems.org' 

gem 'rails', '3.0.9' 
gem 'gravatar_image_tag', '1.0.0.pre2' 
gem 'will_paginate', '3.0.pre2' 
gem 'sqlite3', '1.3.3' 

group :development do 
    gem 'rspec-rails', '2.6.1' 
    gem 'annotate', '2.4.0' 
    gem 'faker', '0.3.1' 
end 

group :test do 
    gem 'rspec-rails', '2.6.1' 
    gem 'webrat', '0.7.1' 
    gem 'spork', '0.9.0.rc9' 
    gem 'factory_girl_rails', '1.0' 
end 

谁能帮助?

回答

0

在失败1-6,在您的测试,你有这样的:

response.should have_selector('title', content=> "Home") 

将其更改为

response.should have_selector('title', :content=> "Home") 

注意对content前面的:。正如现在写的,content被解释为一个你尚未定义的变量。当您将其更改为:content时,它会将其解释为符号而不是变量。

+0

谢谢。我在访问signined_pa​​th应该访问signin_path时也有一个错字。 –