Dan and Zach - Thanks. I will play around with your suggestions.
Here's more background on what's driving this.
Overall, I am trying to move away from one big test that has lots of
assertions to many tests that test (ideally) just one thing. So
certainly looking for "fail early and often" rather than "fail rarely
but spectacularly". This approach can give a near complete list of
failures which are not dependent on the pass/fail result of the
previous *iteration*. So in my example if the test failed on the
second page, I still want the test to run on the third and fourth page
-- which does not happen in the current approach of looping within a
should block.
Zach - You have already answered your question. I am trying to test
for presence/absence of page elements that should be conditionally
present on the page. For example,
* "New Messages" link in the header shows only when you have a new
message
- new message flag is derived from the logged in user, not
controller logic.
* "Home" Tab shows on all pages for all users
* "Admin" Tab is seen only by admins and no other user
I also use this approach to permute through allowable values of a
method argument when the situation demands. For example, if I have an
account type attribute with permissible values = [1, 2, 3] and a
method
def account_status(account_type)
...
end
then I like to write a test that goes through all valid values of
account_types and illegal values of [nil, ""] etc. to make sure the
method behaves as expected. These tests take the form
[1, 2, 3].each do |value|
define_method "test: account_status should correctly handle
account_type of #{value}. " do
... assertions ..
end
end
[nil, ""],each do |value|
define_method "test: account_status gracefully handles illegal value
#{value}" do
... assertions ...
end
end
Doing this for the core classes gives you the peace of mind that every
corner and edge case is covered.
There are a few idioms that have yielded great dividends in improving
code quality and I will extract and publish it as a plugin if there is
interest.
Would certainly welcome your comments if there is a better way to do
this.
/MW
> Zach Dennishttp://
www.continuousthinking.com(personal)
http://www.mutuallyhuman.com(hire me)
http://ideafoundry.info/behavior-driven-development(first rate BDD training)
> @zachdennis (twitter)