Ruby on rails Ruby教程第8章-错误
有三名工程师正在努力解决这个问题,但没有成功。通过努力,似乎无法取得进展。如果你是一名绝地工程师,请根据新手的经验/知识填写完整答案。提前谢谢 错误Ruby on rails Ruby教程第8章-错误,ruby-on-rails,ruby,ruby-on-rails-3,railstutorial.org,Ruby On Rails,Ruby,Ruby On Rails 3,Railstutorial.org,有三名工程师正在努力解决这个问题,但没有成功。通过努力,似乎无法取得进展。如果你是一名绝地工程师,请根据新手的经验/知识填写完整答案。提前谢谢 错误 Failures: 1) when email format is invalid should be invalid Failure/Error: @user.email = invalid_address NoMethodError: undefined method `email=' for n
Failures:
1) when email format is invalid should be invalid
Failure/Error: @user.email = invalid_address
NoMethodError:
undefined method `email=' for nil:NilClass
# ./spec/models/user_spec.rb:33:in `block (3 levels) in <top (required)>'
# ./spec/models/user_spec.rb:32:in `each'
# ./spec/models/user_spec.rb:32:in `block (2 levels) in <top (required)>'
2) when email format is valid should be valid
Failure/Error: @user.email = valid_address
NoMethodError:
undefined method `email=' for nil:NilClass
# ./spec/models/user_spec.rb:43:in `block (3 levels) in <top (required)>'
# ./spec/models/user_spec.rb:42:in `each'
# ./spec/models/user_spec.rb:42:in `block (2 levels) in <top (required)>'
3) when email address is already taken
Failure/Error: user_with_same_email = @user.dup
TypeError:
can't dup NilClass
# ./spec/models/user_spec.rb:51:in `dup'
# ./spec/models/user_spec.rb:51:in `block (2 levels) in <top (required)>'
4) when password is not present
Failure/Error: before { @user.password = @user.password_confirmation = " " }
NoMethodError:
undefined method `password_confirmation=' for nil:NilClass
# ./spec/models/user_spec.rb:60:in `block (2 levels) in <top (required)>'
5) when password doesn't match confirmation
Failure/Error: before { @user.password_confirmation = "mismatch" }
NoMethodError:
undefined method `password_confirmation=' for nil:NilClass
# ./spec/models/user_spec.rb:65:in `block (2 levels) in <top (required)>'
6) when password confirmation is nil
Failure/Error: before { @user.password_confirmation = nil }
NoMethodError:
undefined method `password_confirmation=' for nil:NilClass
# ./spec/models/user_spec.rb:70:in `block (2 levels) in <top (required)>'
7) with a password that's too short
Failure/Error: before { @user.password = @user.password_confirmation = "a" * 5 }
NoMethodError:
undefined method `password_confirmation=' for nil:NilClass
# ./spec/models/user_spec.rb:76:in `block (2 levels) in <top (required)>'
8) return value of authenticate method with valid password
Failure/Error: before { @user.save }
NoMethodError:
undefined method `save' for nil:NilClass
# ./spec/models/user_spec.rb:81:in `block (2 levels) in <top (required)>'
9) return value of authenticate method with invalid password
Failure/Error: before { @user.save }
NoMethodError:
undefined method `save' for nil:NilClass
# ./spec/models/user_spec.rb:81:in `block (2 levels) in <top (required)>'
10) return value of authenticate method with invalid password
Failure/Error: before { @user.save }
NoMethodError:
undefined method `save' for nil:NilClass
# ./spec/models/user_spec.rb:81:in `block (2 levels) in <top (required)>'
11) Authentication signin page
Failure/Error: before { visit signin_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841ca913c8>:0x007f8419313cc0>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/authentication_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
12) Authentication signin page
Failure/Error: before { visit signin_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841ca913c8>:0x007f841bba0030>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/authentication_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
13) Static pages Home page
Failure/Error: before { visit root_path }
NameError:
undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_11::Nested_1:0x007f8419475898>
# ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
14) Static pages Home page
Failure/Error: before { visit root_path }
NameError:
undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_11::Nested_1:0x007f84195c97f8>
# ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
15) Static pages Home page
Failure/Error: before { visit root_path }
NameError:
undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_11::Nested_1:0x007f84196d96e8>
# ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
16) Static pages Help page
Failure/Error: before { visit help_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841b879528>:0x007f84196268b8>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/static_pages_spec.rb:16:in `block (3 levels) in <top (required)>'
17) Static pages Help page
Failure/Error: before { visit help_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841b879528>:0x007f841bd4b4e8>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/static_pages_spec.rb:16:in `block (3 levels) in <top (required)>'
18) Static pages About page
Failure/Error: before { visit about_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841b879528>:0x007f841bbab728>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/static_pages_spec.rb:23:in `block (3 levels) in <top (required)>'
19) Static pages About page
Failure/Error: before { visit about_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841b879528>:0x007f841a1f8c18>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/static_pages_spec.rb:23:in `block (3 levels) in <top (required)>'
20) Static pages Contact page
Failure/Error: before { visit contact_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841b879528>:0x007f841b8baf00>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/static_pages_spec.rb:30:in `block (3 levels) in <top (required)>'
21) Static pages Contact page
Failure/Error: before { visit contact_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841b879528>:0x007f841be450b0>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/static_pages_spec.rb:30:in `block (3 levels) in <top (required)>'
22) User pages profile page
Failure/Error: before { visit user_path(user) }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841bed35e0>:0x007f841bedc2d0>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/user_pages_spec.rb:9:in `block (3 levels) in <top (required)>'
23) User pages profile page
Failure/Error: before { visit user_path(user) }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841bed35e0>:0x007f841b8890e0>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/user_pages_spec.rb:9:in `block (3 levels) in <top (required)>'
24) User pages signup with invalid information should not create a user
Failure/Error: before { visit signup_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841bed35e0>:0x007f841bfd8940>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/user_pages_spec.rb:17:in `block (3 levels) in <top (required)>'
25) User pages signup with valid information should create a user
Failure/Error: before { visit signup_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841bed35e0>:0x007f841bd018c0>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/user_pages_spec.rb:17:in `block (3 levels) in <top (required)>'
Finished in 0.60263 seconds
33 examples, 25 failures
认证\u页面\u规范
require 'spec_helper'
describe "Authentication" do
subject { page }
describe "signin page" do
before { visit signin_path }
it { should have_selector('h1', text: 'Sign in') }
it { should have_selector('title', text: 'Sign in') }
end
end
require 'spec_helper'
describe "Static pages" do
subject { page }
describe "Home page" do
before { visit root_path }
it { should have_selector('h1', text: 'Sample App') }
it { should have_selector('title', text: full_title('')) }
it { should_not have_selector 'title', text: '| Home' }
end
describe "Help page" do
before { visit help_path }
it { should have_selector('h1', text: 'Help') }
it { should have_selector('title', text: full_title('Help')) }
end
describe "About page" do
before { visit about_path }
it { should have_selector('h1', text: 'About') }
it { should have_selector('title', text: full_title('About Us')) }
end
describe "Contact page" do
before { visit contact_path }
it { should have_selector('h1', text: 'Contact') }
it { should have_selector('title', text: full_title('Contact')) }
end
end
require 'spec_helper'
describe "User pages" do
subject { page }
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
before { visit user_path(user) }
it { should have_selector('h1', text: user.name) }
it { should have_selector('title', text: user.name) }
end
describe "signup" do
before { visit signup_path }
let(:submit) { "Create my account" }
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
end
describe "with valid information" do
before do
fill_in "Name", with: "Example User"
fill_in "Email", with: "user@example.com"
fill_in "Password", with: "foobar"
fill_in "Confirmation", with: "foobar"
end
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
end
end
end
静态页面规范
require 'spec_helper'
describe "Authentication" do
subject { page }
describe "signin page" do
before { visit signin_path }
it { should have_selector('h1', text: 'Sign in') }
it { should have_selector('title', text: 'Sign in') }
end
end
require 'spec_helper'
describe "Static pages" do
subject { page }
describe "Home page" do
before { visit root_path }
it { should have_selector('h1', text: 'Sample App') }
it { should have_selector('title', text: full_title('')) }
it { should_not have_selector 'title', text: '| Home' }
end
describe "Help page" do
before { visit help_path }
it { should have_selector('h1', text: 'Help') }
it { should have_selector('title', text: full_title('Help')) }
end
describe "About page" do
before { visit about_path }
it { should have_selector('h1', text: 'About') }
it { should have_selector('title', text: full_title('About Us')) }
end
describe "Contact page" do
before { visit contact_path }
it { should have_selector('h1', text: 'Contact') }
it { should have_selector('title', text: full_title('Contact')) }
end
end
require 'spec_helper'
describe "User pages" do
subject { page }
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
before { visit user_path(user) }
it { should have_selector('h1', text: user.name) }
it { should have_selector('title', text: user.name) }
end
describe "signup" do
before { visit signup_path }
let(:submit) { "Create my account" }
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
end
describe "with valid information" do
before do
fill_in "Name", with: "Example User"
fill_in "Email", with: "user@example.com"
fill_in "Password", with: "foobar"
fill_in "Confirmation", with: "foobar"
end
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
end
end
end
用户页面规范
require 'spec_helper'
describe "Authentication" do
subject { page }
describe "signin page" do
before { visit signin_path }
it { should have_selector('h1', text: 'Sign in') }
it { should have_selector('title', text: 'Sign in') }
end
end
require 'spec_helper'
describe "Static pages" do
subject { page }
describe "Home page" do
before { visit root_path }
it { should have_selector('h1', text: 'Sample App') }
it { should have_selector('title', text: full_title('')) }
it { should_not have_selector 'title', text: '| Home' }
end
describe "Help page" do
before { visit help_path }
it { should have_selector('h1', text: 'Help') }
it { should have_selector('title', text: full_title('Help')) }
end
describe "About page" do
before { visit about_path }
it { should have_selector('h1', text: 'About') }
it { should have_selector('title', text: full_title('About Us')) }
end
describe "Contact page" do
before { visit contact_path }
it { should have_selector('h1', text: 'Contact') }
it { should have_selector('title', text: full_title('Contact')) }
end
end
require 'spec_helper'
describe "User pages" do
subject { page }
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
before { visit user_path(user) }
it { should have_selector('h1', text: user.name) }
it { should have_selector('title', text: user.name) }
end
describe "signup" do
before { visit signup_path }
let(:submit) { "Create my account" }
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
end
describe "with valid information" do
before do
fill_in "Name", with: "Example User"
fill_in "Email", with: "user@example.com"
fill_in "Password", with: "foobar"
fill_in "Confirmation", with: "foobar"
end
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
end
end
end
gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.6'
gem 'bootstrap-sass', '2.0.0'
gem 'bcrypt-ruby', '3.0.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development, :test do
gem 'sqlite3', '1.3.5'
gem 'rspec-rails', '2.10.0'
end
gem 'annotate', '~> 2.4.1.beta', group: :development
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.2.4'
gem 'coffee-rails', '3.2.2'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '1.2.3'
end
gem 'jquery-rails', '2.0.0'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
group :test do
gem 'capybara', '1.1.2'
gem 'factory_girl_rails', '1.4.0'
end
group :production do
gem 'pg', '0.12.2'
end
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
提前感谢各位:)看起来您忘记准备测试数据库了。在命令行上运行此命令:
rake db:test:prepare
我绝对建议您在运行测试之前阅读以了解需要发生的事情。此外,如果开发数据库不是最新的,您可以先执行“rake db:migrate”来准备开发数据库。Andrew仍有33个示例,25failures@frostjohn失败消息必须是不同的-你能更新你的问题以包含新消息吗?只是猜测,因为我对RSpec不太了解,但可能在(:each)之前尝试一下。。。换句话说,include:每个都作为user_spec中before方法的参数