Starkers
Starkers

Reputation: 10541

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?

Upvotes: 9

Views: 4200

Answers (2)

Gasol
Gasol

Reputation: 2519

As someone who is new to Ruby on Rails, I can confirm that the accepted answer is still valid for Rails 7. However, I would like to offer an alternative way of achieving the same result.

Instead of using the command rake test TESTOPTS="-v", you can use the shorthand option -v provided by the command rails test like this:

rails test -v

This command will produce the same verbose output as the previous command.

I hope this helps.

Upvotes: 0

jfvanderwalt
jfvanderwalt

Reputation: 343

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"

Upvotes: 11

Related Questions