我目前在RailsTutorial 3.2,Section 9.3.1 User Index中。RailsTutorial 3.2第9章 - “before {valid_signin(user)}”导致RSpec测试失败
清单9.27引导编辑到spec/requests/authentication_pages_spec.rb
代码如下:
require 'spec_helper'
describe "Authentication" do
.
.
.
describe "with valid information" do
let(:user) { FactoryGirl.create(:user) }
before { valid_signin(user) }
it { should have_selector('title', text: user.name) }
it { should have_link('Users', href: users_path) }
it { should have_link('Profile', href: user_path(user)) }
it { should have_link('Settings', href: edit_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
这样做后,测试的相应部分失败。我非常忠实地遵循了教程,所以我的代码和设置完全相同。
测试的几件事情出来后,我发现改变
before { valid_signin(user) }
行改为
before { sign_in user }
,而不是将所有的测试再次通过。是否有关于句法上关闭的行,还是这指向我的代码中的其他地方的错误?
(该应用程序的工作原理完全一样它应该,它只是说,它不测试)。
你从rspec得到什么错误?你的'sign_in(user)'和'valid_signin(user)'方法是什么样的? – James 2012-02-21 18:39:53
RSpec错误表示没有'valid_signin(user)'的方法,这是真的 - 据我所知,这在教程中从未定义过。我有点困惑,但认为它可能是内置的......那么肯定是遗漏了? – ellawren 2012-02-21 22:07:09