我正在完成Michael Hartl's tutorial并完成第9课。我在使用rake规范时出错,但不是自动测试。更新几个宝石后,我现在使用自动测试得到以下错误。将'webrat','0.7.1'添加到我的gemfile中没有帮助。
故障:
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 :(得分:0)
在失败1-6中,在你的测试中你有类似的东西:
response.should have_selector('title', content=> "Home")
将其更改为
response.should have_selector('title', :content=> "Home")
请注意:
正面的content
。正如现在所写,content
被解释为一个你尚未定义的变量。当您将其更改为:content
时,它会将其解释为符号而不是变量。