2011/11/21 Jes=FAs Gabriel y Gal=E1n <jgabrielygalan / gmail.com>:
> On Mon, Nov 21, 2011 at 6:55 PM, hari mahesh <harismahesh / gmail.com> wrot=
e:
>> Consider I have a ruby file called library.rb.
>>
>> In which i defined a function like this :
>>
>> def Name(testcase, result)
>> pdf =3D PDF::Writer.new
>> testcase=3D $testcase
>> pdf.text $testcase, :font_size =3D> 72, :justification =3D> :center
>> result=3D $result
>> pdf.text $result, :font_size =3D> 72, :justification =3D> :center
>> end
>>
>> now i have another ruby file named web.rb which calls thus library.rb.
>>
>> My Problem is I need to pass these arguments separately.
>>
>> Means , I need to call Testcase argument firstly and then after many
>> conditions I need to pass result as Pass or fail.
>>
>> The Testcase is like I am doing a web automation and the library.rb is
>> the report part where From the web.rb I need to pass the testcase name
>> and then at the end I need to pass end result.
>>
>> Please help me to do this.
>
> You could create a class in library.rb that receives a testcase in the
> constructor, and has a method report which receives the result and
> does what you are doing in the above method. Then in your web.rb you
> will create an instance of that class passing the testcase, then you
> do your thing, and at the end you call the report method. Something
> like:
>
> #library.rb
> class Report
> =A0def initialize testcase
> =A0 =A0@testcase =3D testcase
> =A0end
>
> =A0def report result
> =A0 =A0pdf =3D PDF::Writer.new
> =A0 =A0pdf.text @testcase, :font_size =3D> 72, :justification =3D> :cente=
r
> =A0 =A0pdf.text result, :font_size =3D> 72, :justification =3D> :center
> =A0end
> end
>
> #web.rb
> require 'library'
>
> report =3D Report.new testcase
> #... your testing stuff
> report.report result

Just a minor nitpick: the file should not be called "library.rb"
because that is way too unspecific.  In your example it could be
called "report.rb" or "report_test.rb" or "test-report.rb".

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/