On Wed, 04 Feb 2009 22:55:46 +0000, Will Parsons wrote:

> I'm having trouble trying to figure out how to customize an assertion
> message when running unit tests.  In particular, I want to check the
> permissions on a file, so I have something like:
> 
> assert_equal(0755, File.stat(test_file).mode & 0777)
> 
> If it fails, I get a message like:
> 
> <493> expected but was
> <420>.
> 
> and of course I would like the expected and actual permissions to be
> displayed in octal rather than decimal.  How can I do that?

All of the standard test/unit assertions let you pass a message to be 
printed to explain the error, which will print in addition to the 
automatic message. So store the mode in a local variable so you can use 
it in both places.

acutalmode=File.stat(test_file).mode & 0777
assert_equal 0755, actualmode, "#{test_file} should have mode 755, but 
has mode %o instead." % [actualmode]

Or to supress the automatic message altogether and only print your custom 
message:

acutalmode=File.stat(test_file).mode & 0777
assert_block ("#{test_file} should have mode 755, 
but has mode %o instead." % [actualmode]) {0755 == actualmode}

--Ken

-- 
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/