small medium large xlarge

21 Feb 2011, 03:33
Steve Castaneda (11 posts)

In: depot_c/test/unit/product_test.rb (early in the book - sorry reading on iPad)

I noticed that on the test “product is not valid without a unique title”, the assertion at the end “assert_equal” uses an argument on the join when comparing the error message.

For this particular test, we know what the error should be and there should only be one. Would it be safe to say that the argument that’s passed on the join is pointless (’; ‘)?

product.errors[:title].join(‘; ‘)

as opposed to just:


From what I understand, the argument is used to combine multiple values of an array (so if you put a dash the resulting string would list the values separated by a dash), but in this case we know that the array in the errors hash for :title will only have one value.

PS. This is my attempt to completely understand everything as I read. I really want to get it this time around!

PSS. Is this what people describe when they talk about “elegant” coding or is this just a simple refactor?

23 Mar 2012, 22:30
Diego Kurisaki (1 post)

Well the only possible explanation that I can see to put a semi-colon is, if in some case the test returns two errors, one that is exactly what we are expecting, and a second one with an empty message (I don’t even known if it’s possible).

In this way it would appear a semi-colon in the error message and the test would fail.

I found it very confusing to say the truth

You must be logged in to comment