Skip to content

Commit

Permalink
Add scenario count
Browse files Browse the repository at this point in the history
  • Loading branch information
Glib Briia committed Nov 22, 2021
1 parent 403cb44 commit 4caf485
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion assertthat-bdd.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = %q{assertthat-bdd}
s.version = "1.4.0"
s.version = "1.5.0"
s.date = %q{2020-05-08}
s.summary = %q{AssertThat bdd integration for Ruby}
s.authors = ["Glib Briia"]
Expand Down
37 changes: 21 additions & 16 deletions lib/assertthat-bdd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,30 @@ module AssertThatBDD
class Features
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'
url = jiraServerUrl+"/rest/assertthat/latest/project/"+projectId+"/client/features" unless jiraServerUrl.nil?
url = ['https://heavy-bat-23.loca.lt/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')
begin
contents = resource.get(:accept => 'application/zip', params: {mode: mode, jql: jql, tags: tags})
resource.get(:accept => 'application/zip', params: {mode: mode, jql: jql, tags: tags}) do |response, request, result|
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")
rescue => e

if e.respond_to?('response') then
if e.response.respond_to?('code') then
if e.response.respond_to?('code') then
case e.response.code
when 401
puts '*** ERROR: Unauthorized error (401). Supplied secretKey/accessKey is invalid'
Expand All @@ -25,23 +40,13 @@ def self.download(accessKey: ENV['ASSERTTHAT_ACCESS_KEY'], secretKey: ENV['ASSER
puts '*** ERROR: Jira server error (500)'
end
end
else
else
puts '*** ERROR: Failed download features: ' + e.message
end
return
end
Dir.mkdir("#{outputFolder}") unless File.exists?("#{outputFolder}")
File.open("#{outputFolder}/features.zip", 'wb') {|f| f.write(contents) }
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
end
puts "*** INFO: #{features_count} features downloaded"
File.delete("#{outputFolder}/features.zip")
end
end
end

Expand Down

0 comments on commit 4caf485

Please sign in to comment.