On 24 Nov 2008, at 17:56, James Byrne wrote:
Matt Wynne wrote:
Make sense?
Matt
Yes. I am afraid that my original post is based upon a naive sense of
how things work in this environment. Clearly, whenever one is dealing
with human input then the possibility of incomplete, contradictory, or
simply wrong data must be accommodated as elegantly as is possible. I
was overmuch concerned with testing at that moment to give the other
issues their due.
I have since run across the construct shown below and have used it in
the functional test rather than changing the controller code for
testing.
# This code extends the subject controller to
# display errors raised in the controller code
# in the test results
require 'clients_controller'
class ClientsController; def rescue_action(e) raise e end; end
# back to our test
Careful. That looks to me like you're changing the controller code for
testing.
How come your controller doesn't raise these errors anyway?
I think you have a deeper problem here. The reason you asked this
question, IIRC, is because your test code created a model which was
not valid, and therefore when the controller tried to save it, you got
some behaviour you didn't expect. You might want to look at using a
more standardised mechanism for creating test objects, such as the
factory_girl plug-in from throughbot. That way, you can test that each
of the objects produced by the factory are valid, and you won't get
tripped up like this in the future.
At the very least, when you create your test object instance, just
quickly check that it's valid:
before(:each) do
@dog = Dog.new(:legs = 3)
@dog.should be_valid
end
cheers,
Matt
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users