RailsTutorial 3.2 Ch 9 – “before {valid_signin(user)}”导致RSpec测试失败

我目前在RailsTutorial 3.2, 第9.3.1节用户索引中 。

代码清单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 } 

相反,将使所有测试再次通过。 有没有关于valid_signin(user)行的语法关闭,或者这是否指向我的代码中的其他地方的错误?

(该应用程序的工作方式与预期完全相同,只是测试表明它没有。)

如果查看清单8.34,您将在spec / support / utilities.rb文件中看到valid_signin的def。

我发现很多“可选”工作对于随后的代码工作是必要的。 FYI