Forum: Ruby on Rails Checking errors in functional tests?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
rick (Guest)
on 2005-11-12 12:49
(Received via mailing list)
We're elbow deep in functional tests and we're trying to figure out how
to do some assertions about the state of the list of validation errors
on the request.  We'd like to be able to assert that there are no
validation errors on a successful create/update.  We'd like to be able
to assert that there are a specific number or matching set of errors on
a failing create/update.

I've done a lot of grovelling through the code and a lot of playing
around in the breakpointer inspecting the various objects at hand and
I'm not seeing how to get to this information.

Anyone got any ideas on how to do this?

Thanks!
Rick
jeremy (Guest)
on 2005-11-12 12:49
(Received via mailing list)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Nov 10, 2005, at 8:12 AM, Rick Bradley wrote:
> around in the breakpointer inspecting the various objects at hand and
> I'm not seeing how to get to this information.
>
> Anyone got any ideas on how to do this?

# @foo = Foo.create(invalid_params)
assert !assigns(:foo).valid?
assert_equal 3, assigns(:foo).errors.on('attribute')


jeremy
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (Darwin)

iD8DBQFDc6F9AQHALep9HFYRAvX2AKCYbjLt77FSBooT4KesjWTmMajKWgCeMu/5
YV9Pt8yX27UuxZa6R+Ln6Ak=
=Y10+
-----END PGP SIGNATURE-----
rick (Guest)
on 2005-11-12 12:49
(Received via mailing list)
* Jeremy Kemper (jeremy@bitsweat.net) [051110 14:40]:
> # @foo = Foo.create(invalid_params)
> assert !assigns(:foo).valid?
> assert_equal 3, assigns(:foo).errors.on('attribute')

Thanks, Jeremy!

Now that I've got the correct hook I see that I could also do something
like:

assertequal 1, assigns(:foo).errors.on_base.length

Rick
This topic is locked and can not be replied to.