开发者

Ruby on Rails Tutorial

I'm working through Michael Hartl's tutorial and completed though lesson 9. I was having errors using rake spec, but not autotest. After updating a few gems, I'm now getting the following errors using autotest. Adding 'webrat', '0.7.1' to my gemfile didn't help.

Failures:

  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>
     # ./sp开发者_JAVA百科ec/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

Failed examples:

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

Here's my 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

Can anyone help?


In failures 1-6, in your test where you have something like:

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

Change it to

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

Note the : on the front of content. As it's written now, content is being interpreted as a variable, which you haven't defined. When you change it to :content it interprets it as a symbol instead of a variable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜