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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:30:21+00:00 2026-06-15T07:30:21+00:00

Hi I’m trying to learn testing and TDD, so I started a new project

  • 0

Hi I’m trying to learn testing and TDD, so I started a new project and made a User model. I made a User model with: name, gender, age.

class User < ActiveRecord::Base
  attr_accessible :age, :gender, :name
end

I read that TDD is about making tests (that fail), fixing them, and then running the tests again to see them pass. So does that mean I want a failure first or error or do either work?

I’m asking because I just wrote a second test:

require 'test_helper'

class UserTest < ActiveSupport::TestCase
  test "user is created" do
    user = User.create(:name => "Edmund", :age => 3, :gender => "m")
    assert_equal user, User.find_by_name("Edmund")
    assert_equal 3, User.count
  end

  test "user has sent messages" do
    user = User.create(:name => "Edmund", :age => 3, :gender => "m")
    2.times do 
      user.sent_messages.create(:sender_id => user.id)
    end
    assert_equal 2, user.sent_messages.count
  end


end

for sent messages. I ran rake test:units, expecting it to be a failure since I don’t have any Message model nor any association with has_many :messages in my User model, however I got an error:

Edmunds-MacBook-Pro:langoexchange edmundmai$ rake test:units
NOTICE:  CREATE TABLE will create implicit sequence "users_id_seq" for serial column "users.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "users_pkey" for table "users"
Run options: 

# Running tests:

E.

Finished tests in 0.087926s, 22.7464 tests/s, 22.7464 assertions/s.

  1) Error:
test_user_has_sent_messages(UserTest):
NoMethodError: undefined method `sent_messages' for #<User:0x007fa73bbd68e0>
    /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/activemodel-3.2.8/lib/active_model/attribute_methods.rb:407:in `method_missing'
    /Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/activerecord-3.2.8/lib/active_record/attribute_methods.rb:149:in `method_missing'
    /Users/edmundmai/Desktop/Class/Ruby/langoexchange/test/unit/user_test.rb:13:in `block (2 levels) in <class:UserTest>'
    /Users/edmundmai/Desktop/Class/Ruby/langoexchange/test/unit/user_test.rb:12:in `times'
    /Users/edmundmai/Desktop/Class/Ruby/langoexchange/test/unit/user_test.rb:12:in `block in <class:UserTest>'

2 tests, 2 assertions, 0 failures, 1 errors, 0 skips
rake aborted!
Command failed with status (1): [ruby -I"lib:test" -I"/Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rake-10.0.2/lib" "/Users/edmundmai/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rake-10.0.2/lib/rake/rake_test_loader.rb" "test/unit/**/*_test.rb" ]
Tasks: TOP => test:units
(See full trace by running task with --trace)

Is this (error) the expected outcome of TDD or did I do something wrong or interpret the process of TDD incorrectly?

  • 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-15T07:30:22+00:00Added an answer on June 15, 2026 at 7:30 am

    Yes, this is the expected first step in TDD. Once you’ve written your first test(s), your next task is to get your code up to the point where you get actual failures as opposed to errors. A failure is different from an error because it means that your test was expecting something, and that expectation was not met. In the case of an error, the expectation never even gets a chance to be tested because something breaks in the code under test. (In your case, the spec never gets a chance to check whether user.sent_messages.count is equal to 2 because sent_messages is not even defined.)

    The TDD cycle typically focuses on getting from red (failure) to green (success + refactor) because this is the important part of the process, but implicit in this cycle is the process from errors (undefined variables/methods, etc.) to actual failures (expectations not met, etc.) Usually that first step from error to failure is a fairly trivial one (in this case, define a method called sent_messages with nothing in it to start, and run the test again), but it may not be depending on context.

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.