Problems passing the self.class var as a formal parameter

A

aidy

Hello,

I my script I have a method call

class ST_LTD_1 < Test::Unit::TestCase
def test_st_ltd_1
xml_logger(self.class, string_to_search)
end
end


this is the invoked method

def xml_logger (test_id, vp_text)
doc = Document.new
xmldecl = XMLDecl.default
doc.add(xmldecl)
test_result = doc.add_element 'testresults'
test_id = test_result.add_element 'testID'
test_id.text = test_id
if verify_result_1(vp_text) then
pass = test_id.add_element 'pass'
pass.text = 'PASS'
else
pass = test_id.add_element 'fail'
pass.text = 'FAIL!'
end
doc.write($stdout, 1)
end

this is the line of code where the calling class name should be passed
to an XML node

test_id.text = test_id

However the XML produced is this

<testresults>
<testID>&lt;testID/&gt;<pass>PASS</pass>
</testID>
</testresults>

and I am not sure so why?

Thanks for the help

Aidy
 
Z

zycte

You are using the variable test_id twice, once in the parameter list
and once as a temporary variable to assign the XML node. Once you say
test_id.text = test_id, test_id is already overwritten to be an xml
node with name 'testID'. So the text of the XML node testID is set to
<testID>, but with the brackets escaped because it is text inside XML.
 
K

Kenosis

Not sure but in all other assignments to ".text" members, you assign a
string, eg, 'PASS' but in the line you call out, you don't:
test_id.text = test_id. It may be that test_ids .to_s method is being
called implicitly which converts to testID?

Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top