Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8579013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:31:20+00:00 2026-06-11T20:31:20+00:00

I’am fighting with Rails tutoril. I’ve stucked on 6th chapter. Here is the problem

  • 0

I’am fighting with Rails tutoril. I’ve stucked on 6th chapter. Here is the problem
When I run test:

bundle exec rspec spec/models/user_spec.rb

I get few failures:

 Failures:

 1) User
 ←[31mFailure/Error:←[0m ←[31mit { should be_valid }←[0m
 ←[31mexpected valid? to return true, got false←[0m
 ←[36m     # ./spec/models/user_spec.rb:31:in `block (2 levels) in <top (required
 )>'←[0m

 2) User when email format is valid should be valid
 ←[31mFailure/Error:←[0m ←[31m@user.should be_valid←[0m
   ←[31mexpected valid? to return true, got false←[0m
 ←[36m     # ./spec/models/user_spec.rb:64:in `block (4 levels) in <top (required
 )>'←[0m
 ←[36m     # ./spec/models/user_spec.rb:62:in `each'←[0m
 ←[36m     # ./spec/models/user_spec.rb:62:in `block (3 levels) in <top (required
 )>'←[0m

 3) User return value of authenticate method with valid password
 ←[31mFailure/Error:←[0m ←[31mit { should == found_user.authenticate(@user.p
 assword) }←[0m
 ←[31mNoMethodError:←[0m
   ←[31mundefined method `authenticate' for nil:NilClass←[0m
 ←[36m     # ./spec/models/user_spec.rb:99:in `block (4 levels) in <top (required
 )>'←[0m

 4) User return value of authenticate method with invalid password
 ←[31mFailure/Error:←[0m ←[31mlet(:user_for_invalid_password) { found_user.a
 authenticate("invalid") }←[0m
 ←[31mNoMethodError:←[0m
   ←[31mundefined method `authenticate' for nil:NilClass←[0m
 ←[36m     # ./spec/models/user_spec.rb:103:in `block (4 levels) in <top (require
 d)>'←[0m
 ←[36m     # ./spec/models/user_spec.rb:105:in `block (4 levels) in <top (require
 d)>'←[0m

 5) User return value of authenticate method with invalid password
 ←[31mFailure/Error:←[0m ←[31mlet(:user_for_invalid_password) { found_user.a
 uthenticate("invalid") }←[0m
 ←[31mNoMethodError:←[0m
   ←[31mundefined method `authenticate' for nil:NilClass←[0m
 ←[36m     # ./spec/models/user_spec.rb:103:in `block (4 levels) in <top (require
 d)>'←[0m
 ←[36m     # ./spec/models/user_spec.rb:106:in `block (4 levels) in <top (require
 d)>'←[0m

 6) User return value of authenticate method with valid password
 ←[31mFailure/Error:←[0m ←[31mit { should == found_user.authenticate(@user.e
 mail) }←[0m
 ←[31mNoMethodError:←[0m
   ←[31mundefined method `authenticate' for nil:NilClass←[0m
 ←[36m     # ./spec/models/user_spec.rb:120:in `block (4 levels) in <top (require
 d)>'←[0m

 7) User return value of authenticate method with invalid password
 ←[31mFailure/Error:←[0m ←[31mlet(:user_for_invalid_password) { found_user.a
 uthenticate("invalid") }←[0m
 ←[31mNoMethodError:←[0m
   ←[31mundefined method `authenticate' for nil:NilClass←[0m
 ←[36m     # ./spec/models/user_spec.rb:124:in `block (4 levels) in <top (require
 d)>'←[0m
 ←[36m     # ./spec/models/user_spec.rb:126:in `block (4 levels) in <top (require
 d)>'←[0m

 8) User return value of authenticate method with invalid password
 ←[31mFailure/Error:←[0m ←[31mlet(:user_for_invalid_password) { found_user.a
 uthenticate("invalid") }←[0m
 ←[31mNoMethodError:←[0m
   ←[31mundefined method `authenticate' for nil:NilClass←[0m
 ←[36m     # ./spec/models/user_spec.rb:124:in `block (4 levels) in <top (require
 d)>'←[0m
 ←[36m     # ./spec/models/user_spec.rb:127:in `block (4 levels) in <top (require
 d)>'←[0m

 9) User with a password that's too short
 ←[31mFailure/Error:←[0m ←[31mit { should be_valid }←[0m
   ←[31mexpected valid? to return true, got false←[0m
 ←[36m     # ./spec/models/user_spec.rb:112:in `block (3 levels) in <top (require
 d)>'←[0m

 Finished in 8.5 seconds
 ←[31m23 examples, 9 failures←[0m

 Failed examples:

 ←[31mrspec ./spec/models/user_spec.rb:31←[0m ←[36m# User ←[0m
 ←[31mrspec ./spec/models/user_spec.rb:60←[0m ←[36m# User when email format is va
 lid should be valid←[0m
 ←[31mrspec ./spec/models/user_spec.rb:99←[0m ←[36m# User return value of authent
 icate method with valid password ←[0m
 ←[31mrspec ./spec/models/user_spec.rb:105←[0m ←[36m# User return value of authen
 ticate method with invalid password ←[0m
 ←[31mrspec ./spec/models/user_spec.rb:106←[0m ←[36m# User return value of authen
 ticate method with invalid password ←[0m
 ←[31mrspec ./spec/models/user_spec.rb:120←[0m ←[36m# User return value of authen
 ticate method with valid password ←[0m
 ←[31mrspec ./spec/models/user_spec.rb:126←[0m ←[36m# User return value of authen
 ticate method with invalid password ←[0m
 ←[31mrspec ./spec/models/user_spec.rb:127←[0m ←[36m# User return value of authen
 ticate method with invalid password ←[0m
 ←[31mrspec ./spec/models/user_spec.rb:112←[0m ←[36m# User with a password that's
 too short ←[0m

My User_spec.rb

require 'spec_helper'

describe User do

before  do
    @user = User.new(name: "Example User", email: "user@example.com",
                     password: "foobar", 
    password_confirmation: "foobar") 
end

subject { @user }

it { should respond_to(:name) }
it { should respond_to(:email) }
it { should respond_to(:password_digest) }
it { should respond_to(:password) }
it { should respond_to(:password_confirmation) }
it { should respond_to(:authenticate) }

it { should be_valid }

describe "When name is not present" do
    before { @user.name = " " }
    it { should_not be_valid }
end

describe "when email is not present" do
    before { @user.email = " " }
    it { should_not be_valid}
end

describe "when name is too long" do
    before { @user.name = "a" * 51 }
    it { should_not be_valid }
end

describe "when email format is invalid" do
    it "should be invalid" do
        addresses = %w[user@foo,com user_at_foo.org example.user@foo.   
                        foo@bar_baz.com foo@bar+baz.com]
        addresses.each do |invalid_address|
            @user.email = invalid_address
            @user.should_not be_valid
        end
    end
end

describe "when email format is valid" do
    it "should be valid" do
        addresses  = %w[user@foo.COM A_US-ER@f.b.org frst.lst@foo.jp 
 a+b@baz.cn]
        addresses.each do |valid_address|
            @user.email = valid_address
            @user.should be_valid
        end
    end
end

describe "when email addresses is already taken" do
    before do
        user_with_same_email = @user.dup
        user_with_same_email.email = @user.email.upcase
        user_with_same_email.save
    end

    it { should_not  be_valid }
end

describe "when password is not present" do
    before { @user.password = @user.password_confirmation = " "}
    it  { should_not be_valid }
end

describe "when password doesn't match confirmation" do
    before { @user.password_confirmation = "mismatch" }
    it { should_not be_valid }
end

describe "when password confirmation is nil" do 
    before { @user.password_confirmation = nil }
    it { should_not be_valid }
end

describe "return value of authenticate method" do
    before { @user.save } 
    let(:found_user) { User.find_by_email(@user.email) }

    describe "with valid password" do
        it { should == found_user.authenticate(@user.password) }
    end

    describe "with invalid password" do
        let(:user_for_invalid_password) { 
found_user.authenticate("invalid") }

        it { should_not == user_for_invalid_password }
        specify { user_for_invalid_password.should be_false }
    end
end

describe "with a password that's too short" do
    before { @user.password = @user.password_confirmation = "a" * 5 }
    it { should be_valid }
end

describe "return value of authenticate method" do
    before { @user.save }
    let(:found_user) { User.find_by_email(@user.email) }    

    describe "with valid password" do
        it { should == found_user.authenticate(@user.email) }
    end

    describe "with invalid password" do
        let(:user_for_invalid_password) { 
found_user.authenticate("invalid") }

        it { should_not == user_for_invalid_password }
        specify { user_for_invalid_password.should be_false }
    end
end
end

 My user.rb model:

   class User < ActiveRecord::Base
   attr_accessible :email, :name, :password, :password_confirmation
   has_secure_password

   before_save { |user| user.email = email.downcase }

   validates :name,  presence: true, length: { maximum: 50 }
   VALID_EMAIL_REGEX = /\A[w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
   validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: 
   { case_sensitive: false }
   validates :password, presence: true, length: { minimum: 6 }
   validates :password_confirmation, presence: true

  end

Please anyone help! I’ve stucked on this problem for about two weeks and still have no idea what to do.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:31:21+00:00Added an answer on June 11, 2026 at 8:31 pm

    I think its your VALID_EMAIL_REGEX area

    You’ve got:

    VALID_EMAIL_REGEX = /\A[w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
    

    Github has:

    VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
    

    https://github.com/railstutorial/sample_app_2nd_ed/blob/master/app/models/user.rb

    Edit from comment —
    If I was you I’d copy the relevant bits from github or at least compare on the ones with errors.

    From github:

    describe "with a password that's too short" do
      before { @user.password = @user.password_confirmation = "a" * 5 }
      it { should be_invalid }
    end
    

    From your app

    describe "with a password that's too short" do
      before { @user.password = @user.password_confirmation = "a" * 5 }
      it { should be_valid }
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've tracked down a weird MySQL problem to the two different ways I was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.