class AssertThatBDD::Report

Public Class Methods

upload(accessKey: ENV['ASSERTTHAT_ACCESS_KEY'], secretKey: ENV['ASSERTTHAT_ACCESS_KEY'], projectId: nil, runName: 'Test run '+Time.now.strftime("%d %b %Y %H:%M:%S"), jsonReportFolder: './reports', jsonReportIncludePattern: '.*.json', jiraServerUrl: nil ) click to toggle source
# File lib/assertthat-bdd.rb, line 49
def self.upload(accessKey: ENV['ASSERTTHAT_ACCESS_KEY'], secretKey: ENV['ASSERTTHAT_ACCESS_KEY'], projectId: nil, runName: 'Test run '+Time.now.strftime("%d %b %Y %H:%M:%S"), jsonReportFolder: './reports', jsonReportIncludePattern: '.*.json', jiraServerUrl: nil  )
            url = "https://bdd.assertthat.app/rest/api/1/project/" + projectId + "/report"
            url = jiraServerUrl+"/rest/assertthat/latest/project/"+projectId+"/client/report" unless jiraServerUrl.nil?
    files = Find.find(jsonReportFolder).grep(/#{jsonReportIncludePattern}/)
    puts "*** INFO: #{files.count} files found matching parretn #{jsonReportIncludePattern}:"
    puts "*** INFO: #{files}"
    runId = -1
    files.each do |f|
                    request = RestClient::Request.new(
                   :method => :post,
                   :url => url,
                   :user => accessKey,
                   :password => secretKey,
                   :payload => {
                        :multipart => true,
                        :file => File.new(f, 'rb')
                   },
                   :headers => { :params =>{:runName => runName, :runId=> runId}}
            )      
            begin
                           response = request.execute 
                   rescue => e
                           if e.respond_to?('response') then
                      if e.response.respond_to?('code') then
                        case e.response.code
                          when 401
                            puts '*** ERROR: Unauthorized error (401). Supplied secretKey/accessKey is invalid'
                          when 500
                            puts '*** ERROR: Jira server error (500)'
                        end
                      end
                    else
                          puts "*** ERROR: Failed to submit json #{f}: " + e.message
                    end
                            return
                    end
                    resposne_json = JSON.parse(response)
                    if resposne_json['result'] == 'success'
                            runId = resposne_json['runId']
                    else
                        puts "*** ERROR: Failed to submit json #{f}: " + resposne_json['message']
                    end  
            end
end