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
  def initialize testcase
    @testcase = testcase
  end

  def report result
    pdf = PDF::Writer.new
    pdf.text @testcase, :font_size => 72, :justification => :center
    pdf.text result, :font_size => 72, :justification => :center
  end
end

#web.rb
require 'library'

report = Report.new testcase
#... your testing stuff
report.report result

Jesus.