我正在编写第 8 章的 RoR 教程。我正在尝试完成第 8.2.4 节 - 更改布局链接并运行$ bundle exec rspec spec/
,但出现以下错误:
Failures:
1) Authentication signin with valid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007fef66b85fd0>
# ./app/controllers/sessions_controller.rb:9:in `create'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:35:in `block (4 levels) in <top (required)>'
2) Authentication signin with valid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007fef66b33eb0>
# ./app/controllers/sessions_controller.rb:9:in `create'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:35:in `block (4 levels) in <top (required)>'
3) Authentication signin with valid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007fef6698bba8>
# ./app/controllers/sessions_controller.rb:9:in `create'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:35:in `block (4 levels) in <top (required)>'
4) Authentication signin with valid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007fef68286130>
# ./app/controllers/sessions_controller.rb:9:in `create'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:35:in `block (4 levels) in <top (required)>'
Finished in 1.34 seconds
44 examples, 4 failures
Failed examples:
rspec ./spec/requests/authentication_pages_spec.rb:39 # Authentication signin with valid information
rspec ./spec/requests/authentication_pages_spec.rb:40 # Authentication signin with valid information
rspec ./spec/requests/authentication_pages_spec.rb:38 # Authentication signin with valid information
rspec ./spec/requests/authentication_pages_spec.rb:41 # Authentication signin with valid information
根据输出,我检查了spec/requests/authentication_pages_spec.rb
,但似乎找不到错误。这就是我所拥有的:
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
describe "signin" do
before { visit signin_path }
describe "with invalid information" do
before { click_button "Sign in" }
it { should have_selector('title', text: 'Sign in') }
it { should have_selector('div.alert.alert-error', text: 'Invalid') }
describe "after visiting antoher page" do
before { click_link "Home" }
it { should_not have_selector('div.alert.alert-error') }
end
end
describe "with valid information" do
let(:user) { FactoryGirl.create(:user) }
before do
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
end
it { should have_selector('title', text: user.name) }
it { should have_link('Profile', href: user_path(user)) }
it { should have_link('Sign out', href: signout_path) }
it { should_not have_link('Sign in', href: signin_path) }
end
end
end
我似乎找不到错误。根据错误输出,我应该在哪里查看任何建议?谢谢你。