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

  • SEARCH
  • Home
  • 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 8643747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:07:39+00:00 2026-06-12T12:07:39+00:00

I am following the Ruby on Rails tutorial by Michael Hartl. My tests were

  • 0

I am following the Ruby on Rails tutorial by Michael Hartl. My tests were all passing till I migrated the database and added the last 2 test. Something got messed up since all the tests are failing now even if I remove the last 2 tests. I am not sure if I made some mistake with the migrate or something else.

This is what I used:

$ bundle exec rake db:migrate
$ bundle exec rake db:test:prepare
$ bundle exec rspec spec/

Here’s the user_spec file which fails completely:

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 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 address 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
end

And here is the migration file:

class AddPassswordDigestToUsers < ActiveRecord::Migration
  def change
    add_column :users, :password_digest, :string
  end
end

EDIT2 – I just removed password: "foobar", password_confirmation: "foobar" from the first line of the spec and now I only get 5 errors (which is right as those related to password should fail)

EDIT1 – Here are the failing tests

Running all specs
Running tests with args ["--drb", "-f", "progress", "-r", "/home/niranjan/.rvm/gems/ruby-1.9.3-p194/gems/guard-rspec-1.2.1/lib/guard/rspec/formatters/notification_rspec.rb", "-f", "Guard::RSpec::Formatter::NotificationRSpec", "--out", "/dev/null", "--failure-exit-code", "2", "spec"]...
..FFFFFFFFFFFFFFF.........

Failures:

  1) User 
     Failure/Error: @user = User.new(name: "Example User", email: "user@example.com", password: "foobar", password_confirmation: "foobar")
     ActiveRecord::UnknownAttributeError:
       unknown attribute: password
     # ./spec/models/user_spec.rb:16:in `new'
     # ./spec/models/user_spec.rb:16:in `block (2 levels) in <top (required)>'

  2) User 
     Failure/Error: @user = User.new(name: "Example User", email: "user@example.com", password: "foobar", password_confirmation: "foobar")
     ActiveRecord::UnknownAttributeError:
       unknown attribute: password
     # ./spec/models/user_spec.rb:16:in `new'
     # ./spec/models/user_spec.rb:16:in `block (2 levels) in <top (required)>'

  3) User 
     Failure/Error: @user = User.new(name: "Example User", email: "user@example.com", password: "foobar", password_confirmation: "foobar")
     ActiveRecord::UnknownAttributeError:
       unknown attribute: password
     # ./spec/models/user_spec.rb:16:in `new'
     # ./spec/models/user_spec.rb:16:in `block (2 levels) in <top (required)>'

  4) User 
     Failure/Error: @user = User.new(name: "Example User", email: "user@example.com", password: "foobar", password_confirmation: "foobar")
     ActiveRecord::UnknownAttributeError:
       unknown attribute: password
     # ./spec/models/user_spec.rb:16:in `new'
     # ./spec/models/user_spec.rb:16:in `block (2 levels) in <top (required)>'

…. and so on

  • 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-12T12:07:40+00:00Added an answer on June 12, 2026 at 12:07 pm

    From the book:

    Putting everything together gives the (failing) tests in Listing 6.28. We’ll get them to pass in Section 6.3.4.

    The tests should be failing. They will pass as soon as the password implementation is done, later on the tutorial.


    Now, to explain why they are failing:

    On the line where you create the user (your before block), you are passing the password attribute to the constructor, but that attribute doesn’t exist yet, so your model complains with the errors you are seeing. On the tutorial this attribute is created a little later.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am following the Ruby on Rails tutorial by Michael Hartl http://ruby.railstutorial.org/ I installed
New to Ruby on Rails and having a problem when following Michael Hartl's tutorial.I'm
I'm following Ruby on Rails Tutorial: Learn Rails by Example, by Michael Hartl. http://ruby.railstutorial.org/chapters/a-demo-app#sec:a_micropost_microtour
(ruby 1.9.2, rails 3.1) Following Michael Hartl's tutorial. Spent more than a day trying
I am following Michael Hartl's Rails Tutorial Here: http://ruby.railstutorial.org/chapters/modeling-and-viewing-users-one#top I use this command to
I am following the Ruby on Rails tutorial by Michael Hartl. In section 6.3.1
I am following along with Michael Hartl's Ruby on Rails Tutorial 2nd Edition and
i m following michael hartl's ruby on rails online tutorial book and finished chapter
I'm following the demo_app in Michael Hartl's book Ruby on Rails 3 Tutorail .
I just started reading Michael Hartl's Ruby on Rails 3 Tutorial. He recommends using

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.