From: Phillip Gawlowski Date: 2007-04-11T15:23:52+09:00 Subject: Re: The unit test that won't. Daniel N wrote: > On 4/11/07, Phillip Gawlowski wrote: >> >> >> >> My tests look like this: >> >> #Works: >> def test_tags >> assert_equal("**bold**", ClothRed.new("bold").to_textile) >> end >> >> #Doesn't work: >> def test_textformatting >> FORMATTING_STRINGS.each do |html, textile| >> test_html = ClothRed.new(html) >> test_html.to_textile >> assert_equal(textile,test_html) >> end >> end > > > As Brian says, I'm not really sure what test_html.to_textile leaves > test_html as but why not go back to what works for you. It seems > simpler to > me also. > > def test_textformatting > FORMATTING_STRINGS.each do |html, textile| > assert_equal(textile, ClothRed.new(html).to_textile ) > end > end > > also a failing message wouldn't go astray. Something like > > def test_textformatting > FORMATTING_STRINGS.each do |html, textile| > transformed = ClothRed.new(html).to_textile > assert_equal(textile, transformed ), "\"#{html}\" should have > transformed to \"#{textile}\� but was \"#{transformed}\"" > end > end > > just my 0.02 > Thanks for the input guys, looks like the error *was* in my code after all. Here's the why: ClothRed#to_textile used Array#collect! to iterate over the string that was to be transformed, which let the first test complete successfully as it was only testing for *one* condition. As soon as I change #collect! to #each, the code behaved as the test expected. Although why this happens, I'm not sure (I guess the receiver of the block is the "count" for the block, and not the elements in the Array). Which leads to the discovery of another bug now, which is in my regex. -- Phillip "CynicalRyan" Gawlowski http://cynicalryan.110mb.com/ Eek! That was supposed to be My Special Law, _MY_ special law, I tell you! T/