On 22/11/11 09:36, hari mahesh wrote:
> Hi Jesus,
>
> When I run I am getting an error "undefined local variable or method
> `testcase' for main:Object (NameError)"
>
> I will share u my both scripts :
>
> #testcase_lib.rb
>
> require 'rubygems'
> require 'pdf/writer'
> require 'pdf/simpletable'
>
> class Report
>    def initialize testcase
>      @testcase = testcase
>    end
>
>    def report result
>      pdf = PDF::Writer.new
>      pdf.select_font "Times-Roman"
>      pdf.text @testcase, :font_size =>  72, :justification =>  :center
>      pdf.text result, :font_size =>  72, :justification =>  :center
>      pdf.save_as("Report.pdf")
>    end
> end
>
>
> #testcase.rb
>
> require 'rubygems'
> require 'pdf/writer'
> require "testcase_lib"
>
>
> report = Report.new testcase
>
> @testcase = "Login Test";
>
> report.report result
> result = "PASS"
>
>
> What I was trying to do is, when i run I want to pass the testcase name
> to testcase_lib.rb, which will be saved to PDF, after running the
> testcase, the result Pass or Fail will be passed as result. I tried for
> 2 days but no matter what its not working. Please help
>
Looks like you are trying to use variables before they are defined.

Try this;

#testcase.rb

require 'rubygems'
require 'pdf/writer'
require "testcase_lib"

testcase = "Login Test";
report = Report.new testcase

result = "PASS"
report.report result


Sam