Aspiring to be a good programmer, I’m using Test::Unit for ClothRed,
writing the test before I write the code, even.
Which is all well and good, but I have a test, that produces an error
while it is executed and not in the error report:
test_textformatting(TestClothRedFormatting):
TypeError: can’t convert nil into String
…/test/…/lib/clothred.rb:22:in gsub!' ../test/../lib/clothred.rb:22:in
to_textile’
…/test/…/lib/clothred.rb:21:in collect!' ../test/../lib/clothred.rb:21:in
to_textile’
…/test/test_formatting.rb:43:in test_textformatting' ../test/test_formatting.rb:41:in
each’
…/test/test_formatting.rb:41:in `test_textformatting’
2 tests, 1 assertions, 0 failures, 1 errors
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
The Array is as follows:
FORMATTING_STRINGS = [
[“bold”,“bold”], [“strong”,
“strong”],
[“emphasized”, “emphasized”],
[“italics”, “italics”],
[“citation”, “??citation??”],
[“ClothRed#to_textile
”, “@ClothRed#to_textile@”],
[“delete”, “-delete-”],
[“underline”, “+underline+”],
[“superscript”,“^superscript^”],
[“subscript”,“~subscript~”]
]
An improvised test run produces this:
c:\test.rb
bold
emphasized
italics
c:\cat test.rb
test.rb
11. April 2007
require ‘clothred’
TEST = ‘bold
emphasized
italics’
test = ClothRed.new(TEST)
puts test.to_textile
My Ruby version:
c:\ruby -v
ruby 1.8.5 (2006-12-25 patchlevel 12) [i386-mswin32]
The output of the test suggests, that I’m doing something wrong in my
test, that my test is buggy, and not my code.
Can somebody enlighten me?
–
Phillip “CynicalRyan” Gawlowski
http://cynicalryan.110mb.com/
Rule of Open-Source Programming #6:
The user is always right unless proven otherwise by the developer.