我之前从未使用过Ruby,并试图运行一个程序 很久以前。我已经安装了Ruby 2.4.1和gem包[test-unit 3.4.3]好的,但是当我尝试运行它时,我收到一个错误:
tcreporter.rb:156: formal argument cannot be a class variable
@@tc_array.each do |@@tc|
^
特别是我做错了吗? 以下是代码段:
class TCReporter
@@m = nil; @@c = nil; @@tc = nil; @@status = 'p'; @@notes = nil; @@tlArr = []
@@resultMapping = {'p'=>'PASS', 'f'=>'FAIL', 'b'=>'BLOCKED', 's'=>'SKIP','pr'=>'PREQFAIL', 'con'=>'CONERR', 'h'=>'HWSKIP', 'cor'=>'CORE'}
def self.report_result(currentTest, status, notes=nil)
if $trInit
@@m = currentTest.split('(')[0] #@@m is the test METHOD currently being executed in the framework.
@@c = currentTest.split('(')[1].split(')')[0] #@@c is the test CLASS currently being executed in the framework
if @@c =~ /(?:#{TESTRAIL_TEST_PREFIXES.join('|')})_\d*$/i #If there's a mapping on the test class then report a test class result.
@@tc = @@c.scan(/(?:#{TESTRAIL_TEST_PREFIXES.join('|')})_\d*$/i)[0].upcase.sub('_', '-') #Get the TR class mapping
#When reporting at the test class level, the status always starts out as 'p' (PASS). If there's any
#non-passing status for any test method within the test class (blocked or failed) then use that result
#for reporting. Once the global status '@@status' has been updated once then no more updating occurs.
if @@status == 'p' && status != 'p'
@@status = status
@@notes = notes
end
if eval("#{@@c}.public_instance_methods.grep(/^test_/).sort.first") == @@m && eval("#{@@c}.public_instance_methods.grep(/^test_/).sort.last") == @@m #The first test method is the last test method. All done, do a TestLink update.
begin
result = TR.report_tc_result(@@tc, TESTRAIL_PROJECT, TESTRAIL_MILESTONE, TESTRAIL_PLAN, TESTRAIL_RUN, TESTRAIL_BUILD, @@status, (@@notes ? @@notes : notes))
ensure
result.case_id = @@tc
result.class = @@c
result.method = @@m
if !result.success #success means a successful communication with testLink and test case was found and updated.
$trReport = ReportFile.new('tr_report.txt') if !$trReport
$trReport.puts "#{@@tc}, #{TEST_ARGS.project}, #{TEST_ARGS.plan}, #{TEST_ARGS.build}, #{TEST_ARGS.platform}, #{@@c}, #{@@m}, #{status} 'class', #{result.message ||= result.exception}"
end
end
elsif eval("#{@@c}.public_instance_methods.grep(/^test_/).sort.first") == @@m #A new test class is being evaluated. Set everything to default except status (use whatever the first test class returned).
@@m = nil; @@c = nil; @@tc = nil; @@status = status
elsif eval("#{@@c}.public_instance_methods.grep(/^test_/).sort.last") == @@m #Done with the test class. Time to report the test result.
begin
result = TR.report_tc_result(@@tc, TESTRAIL_PROJECT, TESTRAIL_MILESTONE, TESTRAIL_PLAN, TESTRAIL_RUN, TESTRAIL_BUILD, @@status, (@@notes ? @@notes : notes))
ensure
result.case_id = @@tc
result.class = @@c
result.method = @@m
if !result.success #success means a successful communication with testLink and test case was found and updated.
$trReport = ReportFile.new('tr_report.txt') if !$trReport
$trReport.puts "#{@@tc}, #{TEST_ARGS.project}, #{"#{TEST_ARGS.milestone}, " if TEST_ARGS.milestone}#{TEST_ARGS.plan}, #{TEST_ARGS.build}, #{TEST_ARGS.platform}, #{@@c}, #{@@m}, #{status} 'class', #{result.message ||= result.exception}"
end
end
else #The test class is still being executed. Don't update TestLink yet, just check for a non-passing result.
if @@status == 'p' && status != 'p' #Update the test status if it's a non-pass result. Otherwise, use the earlier failed or blocked status.
@@status = status
end
end
end
#If there's a mapping on a test method then report a test method result.
if @@m =~ /(?:#{TESTRAIL_TEST_PREFIXES.join('|')})_\d?[\d_]+$/i
@@tc_array = @@m.scan(/(?:#{TESTRAIL_TEST_PREFIXES.join('|')})_\d?[\d_]+$/i)[0].upcase.sub('_', '-').split("_")
if @@tc_array.size > 1
tmp_prefix = @@tc_array[0].split("-").first
tmp_array = []
@@tc_array.each do|tmp|
tmp_array << tmp_prefix + "-" + tmp.split("-").last
end
@@tc_array = tmp_array
end
@@tc_array.each do |@@tc|
begin
result = TR.report_tc_result(@@tc, TESTRAIL_PROJECT, TESTRAIL_MILESTONE, TESTRAIL_PLAN, TESTRAIL_RUN, TESTRAIL_BUILD, status, notes)
puts status
rescue => e
puts e
ensure
if result && !result.success
$trReport = ReportFile.new('tr_report.txt') if !$trReport
$trReport.puts "#{@@tc}, #{TEST_ARGS.project}, #{"#{TEST_ARGS.milestone}, " if TEST_ARGS.milestone}#{TEST_ARGS.plan}, #{TEST_ARGS.build}, #{TEST_ARGS.platform}, #{@@c}, #{@@m}, #{status} 'class', #{result.message ||= result.exception}"
end
end
end
end
end
end
提前致谢
答案 0 :(得分:0)
现在修复了#34; tc&#34;作为局部变量。