Note that there are some explanatory texts on larger screens.

plurals
  1. POHartl Ruby-on-Rails Tutorial (3.2), Section 8.2.6 - Sign out link not returning anything
    text
    copied!<p>I'm getting the following error after completing the sign out part of the tutorial:</p> <pre><code>Failures: 1) User pages signup with valid information after saving the user Failure/Error: it { should have_link('Sign out') } expected link "Sign out" to return something # ./spec/requests/user_pages_spec.rb:49:in `block (5 levels) in &lt;top (required)&gt;' Finished in 1.15 seconds 48 examples, 1 failure Failed examples: rspec ./spec/requests/user_pages_spec.rb:49 # User pages signup with valid information after saving the user </code></pre> <p>I had more errors before, but I ended up rearranging the order of items in the authentication_pages_spec.rb. Is the order of items that important? What am I missing with this error?</p> <p><strong>authentication_pages_spec.rb</strong></p> <pre><code>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 another 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 describe "followed by signout" do before { click_link "Sign out" } it { should have_link('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 </code></pre> <p><strong>sessions_controller.rb</strong></p> <pre><code>class SessionsController &lt; ApplicationController def new end def create user = User.find_by_email(params[:session][:email]) if user &amp;&amp; user.authenticate(params[:session][:password]) sign_in user redirect_to user else flash.now[:error] = 'Invalid email/password combination' render 'new' end end def destroy sign_out redirect_to root_path end end </code></pre> <p><strong>sessions_helper.rb</strong></p> <pre><code>module SessionsHelper def sign_in(user) cookies.permanent[:remember_token] = user.remember_token current_user = user end def current_user=(user) @current_user = user end def current_user @current_user ||= user_from_remember_token end private def user_from_remember_token remember_token = cookies[:remember_token] User.find_by_remember_token(remember_token) unless remember_token.nil? end def signed_in? !current_user.nil? end def sign_out current_user = nil cookies.delete(:remember_token) end end </code></pre> <p><strong>user_pages_spec.rb</strong></p> <pre><code>require 'spec_helper' describe "User pages" do subject { page } describe "signup page" do before { visit signup_path } it { should have_selector('h1', text: 'Sign up') } it { should have_selector('title', text: full_title('Sign up')) } end 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 describe "after saving the user" do it { should have_link('Sign out') } end end end end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload