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 1058759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:04:17+00:00 2026-05-16T18:04:17+00:00

How would I write a test in rspec to ensure passwords are not stored

  • 0

How would I write a test in rspec to ensure passwords are not stored as plain text in my Ruby on Rails application?

I don’t really care about the implementation yet as I don’t know exactly what plugin or how I am going to write the password encryption (there are lots of examples).

I just want a failing test that’s independent of the implementation. Then, when I implement my code I can be confident I don’t have plain text passwords.

I’m thinking I need to save the user (with password) and then fetch the user again and check the password does not equal the plain text version somehow.

Am I even on the right track?

I have these empty tests:


describe "password encryption" do
it "should have an encrypted password attribute"
it "should set the encrypted password"
it "should encrypt the password"
end

  • 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-05-16T18:04:18+00:00Added an answer on May 16, 2026 at 6:04 pm

    As you said, the behaviour you’re describing is the password is non-recoverable in its plain form, so try and write a spec describing that, rather than the encryption, which is more an implementation detail.

    specify "a user's password should not be readable when they are loaded from the database" do
      my_password = 'foobar22'
      u = User.create :password => my_password, :password_confirmation => my_password
      u.reload
      u.password.should_not == my_password
    end
    

    which could be structured & worded better, but would give a failing spec if you just stored & read out clear text passwords for authentication.

    I don’t think you’ll get much out of speccing how the encryption works unless you’re implementing it yourself (which is generally inadvisable).

    If you opt to use a ready-made system (e.g. devise, clearance, …) you may find it’s more useful to write integration tests to check the way you’ve wired the system into your project works correctly, rather than testing the specifics of the authentication system (which the authors should have done already, otherwise find a different authentication system!).

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

Sidebar

Related Questions

I would like to write the unit test for a text parser class but
I am using Ruby on Rails 3.1.0 and the rspec-rails 2 gem. I would
Using ruby(1.8.7) , rails(2.3.8) , rspec(1.3.1) and rspec-rails(1.3.3) how do I test a method
After doing some work with Ruby, Rails, and RSpec last summer and I learned
I would like to write a test for my custom form helper. Following the
I would like to write a test that just ensures that all components registered
How would one write a test for the following function? bool IsAnInterger(int ignore) {
Possible Duplicate: .NET file system wrapper library I would like to write a test
This would write the output to a logfile: & $Env:WinDir\system32\inetsrv\appcmd.exe >test.log But what if
I'm trying to write test harness for part of my Android mapping application. I

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.