Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails: more verbose tests

This test keeps failing and I don't know why:

  test "correctly formatted profile_name2" do
    user = User.new(first_name: 'Jim', last_name: 'Johnson', email: '[email protected]', password: 'awfawwf', profile_name: "jimmy")
    puts user.errors.inspect
    assert user.valid?
  end

I tried to find out by that puts user.errors.inspect statement, but I get back an array (I think) that simply lists database input rather than precisely what's failing.

For clarification:

<ActiveModel::Errors:0x00000103c8ad30 @base=#<User id: nil, first_name: "Jim", last_name: "Johnson", profile_name: "jimmy", email: "[email protected]", encrypted_password: "$2a$04$LTOb5O.gG0DEITsb/HDOb.fPLP83LaXzKlEerwCDE1og...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, confirmation_token: nil, confirmed_at: nil, confirmation_sent_at: nil, unconfirmed_email: nil, failed_attempts: 0, unlock_token: nil, locked_at: nil, authentication_token: nil, created_at: nil, updated_at: nil>, @messages={}>

In future tests, what statements are used in tests to print to screen explicitly what's going wrong?

like image 619
Starkers Avatar asked May 21 '13 13:05

Starkers


1 Answers

Instead of outputting more verbose information within your tests, it might also help to set the TESTOPTS argument to get verbose output when you run your tests.

For example you would set it like this:

rake test TESTOPTS="-v"
like image 88
jfvanderwalt Avatar answered Sep 23 '22 19:09

jfvanderwalt