RailsTutorial 3.2 Ch 9 - “before { valid_signin(user) }” causes RSpec test to fail

家住魔仙堡 提交于 2019-12-13 00:02:27

问题


I'm currently in RailsTutorial 3.2, Section 9.3.1 User Index.

Listing 9.27 directs an edit to the spec/requests/authentication_pages_spec.rb code as follows:

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

After doing this, the corresponding section of tests fails. I have been following the tutorial very faithfully, so my code and setup are otherwise pretty much identical.

After testing a few things out, I've found that changing the

before { valid_signin(user) } 

line to read

before { sign_in user }

instead will make all the tests pass again. Is there something about the valid_signin(user) line that is off syntactically, or does this point to an error elsewhere in my code?

(The app works exactly like it's supposed to, it's just the test that says it doesn't.)


回答1:


If you look at listing 8.34 you will see the def of valid_signin in the spec/support/utilities.rb file.




回答2:


I am finding that much of the "optional" work is necessary for the ensuing code to work. FYI



来源:https://stackoverflow.com/questions/9382995/railstutorial-3-2-ch-9-before-valid-signinuser-causes-rspec-test-to-fa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!