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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:36:21+00:00 2026-05-29T03:36:21+00:00

I am writing unit tests for a simple user model in rails and just

  • 0

I am writing unit tests for a simple user model in rails and just started thinking about how I write tests.

There seems to be positive testing:

test "password should match the password_confirmation " do
    user = User.new(
    :email => "email@mail.com",
    :password => "password",
    :password_confirmation => "password")
    assert user.valid?, "did not save user even though password matches confimation"
  end

and negative testing:

test "password should not be valid with mismatching password_confirmation " do
    user = User.new(
    :email => "email@mail.com",
    :password => "password",
    :password_confirmation => "doesnotmatch")
    assert user.invalid?, "saved user with mismatching password_confirmation"
  end

Is it superfluous to include both tests in your test suite or is it a good practice?

  • 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-29T03:36:22+00:00Added an answer on May 29, 2026 at 3:36 am

    Have a look at TDD. When you can move on?, that explains when you are ready with your tests (and code) and can move on. In you example, that means:

    • You first write the positive test. The test fails.
    • You then write the necessary code so that the test succeeds.
    • After that, you need another test to prove that your implementation is not sufficient. When you have written e.g.

      class User
        def initialize(hash)
          @hash = hash
        end
        def valid?
          true
        end
      end
      

      you need another test case to prove that wrong.

    • Write the next test case, that shows that checking the password can fail.

    I see the following cases:

    • No password
    • Matching passwords (but too short)
    • Matching passwords (long and difficult enough)
    • Not matching password

    So you would need 4 test cases for that.

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

Sidebar

Related Questions

I'm working on writing simple unit tests for a Rails 3 project, but I'm
I have some pyunit unit tests for a simple command line programme I'm writing.
So I'm having trouble with unit testing CakePHP models. Simple stuff like writing tests
I am having an problem writing unit tests for an simple session wrapper. The
Yet another simple question about unit testing model objects that uses data access layer.
When writing unit tests, do you place your tests inside the assembly you wish
I am writing unit tests for some of my code and have run into
I have been writing unit tests using NUnit and Moq with my Silverlight code
I am writing unit tests with C#, NUnit and Rhino Mocks. Here are the
I’ve been writing unit tests in strongly typed languages and I have a fair

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.