Class: AssertThatBDD::Features

Inherits:
Object
  • Object
show all
Defined in:
lib/assertthat-bdd.rb

Class Method Summary collapse

Class Method Details

.download(accessKey: ENV['ASSERTTHAT_ACCESS_KEY'], secretKey: ENV['ASSERTTHAT_ACCESS_KEY'], projectId: nil, outputFolder: './features/', proxy: nil, mode: 'automated', jql: '', tags: '', jiraServerUrl: nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/assertthat-bdd.rb', line 8

def self.download(accessKey: ENV['ASSERTTHAT_ACCESS_KEY'], secretKey: ENV['ASSERTTHAT_ACCESS_KEY'], projectId: nil, outputFolder: './features/', proxy: nil, mode: 'automated', jql: '', tags: '', jiraServerUrl: nil)
	RestClient.proxy = proxy unless proxy.nil?
	url = ['https://bdd.assertthat.app/rest/api/1/project/', projectId, '/features'].map(&:to_s).join('')
	url = [jiraServerUrl,"/rest/assertthat/latest/project/",projectId,"/client/features"].map(&:to_s).join('') unless jiraServerUrl.nil?
	resource = RestClient::Resource.new(url, :user => accessKey, :password => secretKey, :content_type => 'application/zip')
		resource.get(:accept => 'application/zip', params: {mode: mode, jql: jql, tags: tags}) do |response, request, result|
				case response.code
	              when 401
	                puts '*** ERROR: Unauthorized error (401). Supplied secretKey/accessKey is invalid'
					return
	              when 400
	                puts '*** ERROR: ' + e.response	
					return						
	              when 500
	                puts '*** ERROR: Jira server error (500)'
					return
	            end
		Dir.mkdir("#{outputFolder}") unless File.exists?("#{outputFolder}")
		File.open("#{outputFolder}/features.zip", 'wb') {|f| f.write(response) }
		features_count = 0
		Zip::File.open("#{outputFolder}/features.zip") do |zip_file|
		zip_file.each do |entry|
			features_count = features_count + 1
			File.delete("#{outputFolder}#{entry.name}") if File.exists?("#{outputFolder}#{entry.name}")
			entry.extract("#{outputFolder}#{entry.name}")
		end
		if response.headers.member?('features_count'.to_sym) and response.headers.member?('scenarios_count'.to_sym) then
			puts "*** INFO: #{response.headers['features_count'.to_sym]} features downloaded with #{response.headers['scenarios_count'.to_sym]} scenarios"
		else
			puts "*** INFO: #{features_count} features downloaded"
		end
		File.delete("#{outputFolder}/features.zip")
	end
	end
end