[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Problems passing the self.class var as a formal parameter

aidy

6/20/2006 10:14:00 AM

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

2 Answers

zycte

6/20/2006 11:40:00 AM

0

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.

On 2006-06-20 12:14:25 +0200, "aidy" <aidy.rutter@gmail.com> said:

> 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


Kenosis

6/20/2006 7:25:00 PM

0

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

aidy wrote:
> 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