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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:02:19+00:00 2026-06-15T17:02:19+00:00

I have written a unit test whose assertion fails – I would like to

  • 0

I have written a unit test whose assertion fails – I would like to find out why, without having to inspect every attribute of the model.

Here is my test:

test "a correct document should be saved" do
  document = documents(:one)
  document.pdf = File.new("test/files/document_test_file.pdf")
  assert document.save
end

And here is the fixture:

one:
  user_id: 1
  title: MyString
  published_on: 2012-12-06
  tags: MyText
  language: MyString

Apparently, something is missing and the document cannot be saved. But how do I find out what exactly is missing? Is there any advanced assertion method to do this?

And my model:

class Document < ActiveRecord::Base
  attr_accessible :language, :pdf, :pdf_file_name, :published_on, :tags, :title, :user_id

  # Validations
  validates_presence_of :language, :published_on, :tags, :title, :user
  validates_date :published_on, on_or_before: Date.current,
                                on_or_before_message: "must be today or earlier"
  validates :user_id, numericality: { only_integer: true, greater_than: 0 }
  validates :pdf, attachment_presence: true

  # Relations
  belongs_to :user

  # Paperclip
  has_attached_file :pdf
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-06-15T17:02:19+00:00Added an answer on June 15, 2026 at 5:02 pm

    An easy way to find out why save fails is to call save! instead. The exception will give you enough information.

    Another way is to call valid? and then puts errors.

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

Sidebar

Related Questions

I have different projects written in .NET 3.5 and some unit test projects to
I have some unit tests I've written to test my Django application. One test
I have written a small unit test for my django view .My project structure
Im writting unit test for a WCF service which i have written. The thing
I have written a unit test to comfirm the Dispose on my class does
I have written a unit test that writes a file to the file-system, given
I have written a unit test with MD 2.8.5 in a project that includes
I have these two lines in a unit test. If I comment out the
I have a whole bunch of unit tests written in MbUnit and I would
I am writing some unit tests for an extension method I have written on

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.