stefan.kanev at gmail.com
Thu Aug 11 09:27:48 EDT 2011
I agree with Lenny. I can give an example.
Lets say that parts of the application are restricted. Whenever they are
accessed by an unauthorized user, they trigger UnauthorizedAccessError.
Depending on the role the user has in the system, different actions should
be performed, e.g. unauthenticated users get redirected to the hope page,
admins see a special message with more details.
The example is a bit synthetic, but I'm sure you can see a similar, real
In the design I have in mind, the logic that handles the
UnauthorizedAccessError is handled in ApplicationController, while the error
is raised in some specific controller.
If you, in this error-raising path, assert that a non-authenticated user
gets redirected to the homepage, you're encoding that behavior in the test.
But this behavior is only accidental to the controller under test. This
makes the test harder to understand. Worse, if you have multiple actions
that raise this exception, you're encoding the knowledge in multiple tests.
Now you have duplication too.
I think it makes much more sense to assert that UnauthorizedAccessError is
raised and specify what happens elsewhere.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rspec-users