Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNelly Nelly
7,134 PointsFailure/Error: expect(page).to have_content..... Keep failing.....
Hello everybody...
I am stuck here, what am I doing wrong?
my terminal
Logging In
logs the user and goes to the todo list
displays the email address in the event of the failed login (FAILED - 1)
Failures:
1) Logging In displays the email address in the event of the failed login
Failure/Error: expect(page).to have_content("Please check your email and password!")
expected to find text "Please check your email and password!" in "Odot Todo Lists Sign Up Log In Email Address Password"
# ./spec/features/users/authentication_spec.rb:23:in `block (2 levels) in <top (required)>'
Finished in 0.50424 seconds (files took 1.45 seconds to load)
2 examples, 1 failure
Failed examples:
rspec ./spec/features/users/authentication_spec.rb:16 # Logging In displays the email address in the event of the failed login
authentication_spec.rb
require 'rails_helper'
require 'rspec/active_model/mocks'
describe "Logging In" do
it "logs the user and goes to the todo list" do
User.create(first_name: "Jason", last_name: "Seifer", email: "jason@teamtreehouse.com", password:"password12345", password_confirmation:"password12345")
visit new_user_session_path
fill_in "Email Address", with: "jason@teamtreehouse.com"
fill_in "Password", with: "password12345"
click_button "Log In"
expect(page).to have_content("Todo Lists")
expect(page).to have_content("Thanks for logging in!")
end
it "displays the email address in the event of the failed login" do
visit new_user_session_path
fill_in "Email Address", with: "jason@teamtreehouse.com"
fill_in "Password", with: "wrongpassword"
click_button "Log In"
expect(page).to have_field("Email Address", with: "jason@teamtreehouse.com")
expect(page).to have_content("Please check your email and password!")
end
end
user_sessions_controller.rb
class UserSessionsController < ApplicationController
def new
end
def create
user = User.find_by(email: params[:email])
if user && user.authenticate(params[:password])
session[:user_id] = user.id
flash[:success]= "Thanks for logging in!"
redirect_to todo_lists_path
else
render :new
flash[:error]= "Please check your email and password!"
end
end
end
Thanks for your help
1 Answer
Steve Hunter
57,712 PointsHI Nelly,
I think your test is fine; it is failing for good reason without syntax error.
The issue may be, therefore, in your controller code. I would try switching your two lines of code in the else
clause. Try flashing the error first, then rendering new
. And, I'd be tempted to put a space after the closing square bracket, before the equls sign. I don't think that causes a syntax issue but I've found spacing issues like that can have unexpected consequences at times!
Let me know how you get on.
Steve.
Nelly Nelly
7,134 PointsNelly Nelly
7,134 PointsOH MY !! That was it ! Many thanks !
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsWhoop! \o/
Nelly Nelly
7,134 PointsNelly Nelly
7,134 Pointsonly switched the two lines you mentionned :D