2013-06-20 61 views
1

我正在做一個工具來自Jenkins作業爲我提供的xml文件自動創建測試文件夾(測試套件)和測試用例。 可能是一件愚蠢的事情,但我找不到解決方案,事情是當測試文件夾名稱包含一個空格時,我無法查詢它是否已經存在。我想要逃避空白,並將其編碼爲url,但沒有任何反應。爲包含空格的測試文件夾查詢使用rally_api

test_suite_name = ts_line["name"] 

    if test_suite_name.match(/\s/) 
      #test_suite_name_nows = test_suite_name.gsub(/ /,"\\ \\") 
      test_suite_name_nows = URI::encode(test_suite_name) 

    end 
    #==================== Querying the test suite in Rally ========================== 
    test_suite_query = RallyAPI::RallyQuery.new({:type => :testfolder, :query_string => "(Name = #{test_suite_name_nows})"}) 

你知道哪些應該是能夠查詢測試文件夾名稱爲「Test folder1」的格式?

我總是得到:

/usr/local/rvm/gems/ruby-2.0.0-p195/gems/rally_api-0.9.14/lib/rally_api/rally_json_connection.rb:153:in`send_request 「:(StandardError的) 誤差對請求 - https://rally1.rallydev.com/slm/webservice/1.42/testfolder.js - {:誤差=> [ 「無法解析:無法解析表達式\」 版測試\ 「作爲查詢」]

感謝。

回答

0

這裏是格式:

query.query_string = "(Name = \"My Test Folder 1\")" 

和一個完整的例子:

require 'rally_api' 

#Setup custom app information 
headers = RallyAPI::CustomHttpHeader.new() 
headers.name = "find test folder" 
headers.vendor = "NickM RallyLab" 
headers.version = "1.0" 

# Connection to Rally 
config = {:base_url => "https://rally1.rallydev.com/slm"} 
config[:username] = "[email protected]" 
config[:password] = "1984" 
config[:workspace] = "W" 
config[:project] = "P" 
config[:headers] = headers #from RallyAPI::CustomHttpHeader.new() 

@rally = RallyAPI::RallyRestJson.new(config) 

query = RallyAPI::RallyQuery.new() 
query.type = :test_folder 
query.fetch = "Name,FormattedID" 
query.workspace = {"_ref" => "https://rally1.rallydev.com/slm/webservice/1.43/workspace/12345.js" } #use yoru OID 
query.project = {"_ref" => "https://rally1.rallydev.com/slm/webservice/1.43/project/67890.js" } #user yoru OID 
query.page_size = 200 #optional - default is 200 
query.limit = 1000 #optional - default is 99999 
query.project_scope_up = false 
query.project_scope_down = true 
query.order = "Name Asc" 
query.query_string = "(Name = \"My Test Folder 1\")" 

results = @rally.find(query) 

results.each do |t| 
    puts "Name: #{t["Name"]}, FormattedID: #{t["FormattedID"]}" 
    t.read 
    #............. 
end 
相關問題