2011/11/21 Jesù¸ Gabriel y GaláÏ <jgabrielygalan / gmail.com>:
> On Mon, Nov 21, 2011 at 6:55 PM, hari mahesh <harismahesh / gmail.com> wrote:
>> Consider I have a ruby file called library.rb.
>>
>> In which i defined a function like this :
>>
>> def Name(testcase, result)
>> pdf = PDF::Writer.new
>> testcase= $testcase
>> pdf.text $testcase, :font_size => 72, :justification => :center
>> result= $result
>> pdf.text $result, :font_size => 72, :justification => :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
> ef initialize testcase
> testcase = testcase
> nd
>
> ef report result
> df = PDF::Writer.new
> df.text @testcase, :font_size => 72, :justification => :center
> df.text result, :font_size => 72, :justification => :center
> nd
> end
>
> #web.rb
> require 'library'
>
> report = 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

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