cukerail 0.6.4 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: acbe632026d6a5cd33ee306e3945632d4d6dbd36
4
- data.tar.gz: 6e77965518ae731c673d8ed1448b96ea9716700f
3
+ metadata.gz: 79c53868c8db18616e0ae5bc4dc9d9a46f3b3952
4
+ data.tar.gz: ad501cb97cac693991fd4f2eb9733f01f5e37f24
5
5
  SHA512:
6
- metadata.gz: cd9cb997cef8ea267464400419803a777dee9c2c1dedf7f9e25ac2c2322aa4a0e15e12c3b3d35691d0b5358c00636287f5c44771145ed134e2c61df20cadbbc0
7
- data.tar.gz: 491648c6ed448ef4f51fa15d183d2336a50efb433f6a64c2c215b3f19e0959753944182567f224a74864e8eeedeebf0f9ca9a3ed4ee8c4c38550f64535c336dc
6
+ metadata.gz: fd0882992340a8342fa62b4ab31a40c37508e6172e06ee738860cc13908101a4cc847699d9754039423510a863ca4c9f5f9d1465ca4d5cac640fd396114b3580
7
+ data.tar.gz: 974b68e15999fc11fa565595cac85829c4644090d13450de562071677b1d6ed36ba30107e87fdb07af0d61ab18555a2b50cefd906d633dbdcc48504b643dfd3d
data/lib/cukerail.rb CHANGED
@@ -66,7 +66,6 @@ module Cukerail
66
66
  project_id = /\d+/.match(tags.select{|tag| tag.name =~/project/}.last.name)[0]
67
67
  suite_id = /\d+/.match(tags.select{|tag| tag.name =~/suite/}.last.name)[0]
68
68
  section_id = /\d+/.match(tags.select{|tag| tag.name =~/sub_section/}.last.name)[0]
69
- puts section_id
70
69
  title = extract_title(test_case)
71
70
  found_case = testrail_api_client.send_get("get_cases/#{project_id}&suite_id=#{suite_id}&section_id=#{section_id}").select{|c| c['title'] == title}.first
72
71
  if found_case
@@ -68,7 +68,7 @@ module TestRail
68
68
 
69
69
  private
70
70
  def _send_request(method, uri, data)
71
- Retriable.retriable multiplier: 3 do
71
+ Retriable.retriable multiplier: 3,tries: 5 do
72
72
  url = URI.parse(@url + uri)
73
73
  if method == 'POST'
74
74
  request = Net::HTTP::Post.new(url.path + '?' + url.query)
@@ -1,3 +1,3 @@
1
1
  module Cukerail
2
- VERSION = "0.6.4"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -0,0 +1,76 @@
1
+ require_relative "cukerail/version"
2
+ require_relative "cukerail/testrail"
3
+ require 'awesome_print'
4
+ module Cukerail
5
+
6
+ class JunitSender
7
+ attr_reader :testrail_api_client,:results,:project_id,:suite_id,:testcases,:run_id
8
+ def initialize(junit_file)
9
+ if %w(BASE_URL USER PASSWORD).map{|e| ENV["TESTRAIL_#{e}"]}.any?{|e| e=='' || !e}
10
+ raise 'You need to setup Testrail environment parameters see https://bbcworldwide.atlassian.net/wiki/display/BAR/Installing+and+Running+Cukerail'
11
+ end
12
+ @project_id = ENV['PROJECT_ID']
13
+ @suite_id = ENV['SUITE_ID']
14
+ @testrail_api_client = TestRail::APIClient.new(ENV['TESTRAIL_BASE_URL'],ENV['TESTRAIL_USER'],ENV['TESTRAIL_PASSWORD'])
15
+ @results = Nokogiri::XML(File.read(junit_file))
16
+ @testcases = Hash.new
17
+ @run_id = ENV['TESTRUN']
18
+ end
19
+
20
+ def load
21
+ results.children.each do |child|
22
+ recurse_down(child)
23
+ end
24
+ end
25
+
26
+ def recurse_down(element,level=0,parent_id=nil)
27
+ element.children.select{|n| n.name=='testcase'}.each do |testcase|
28
+ case_id = get_testcase_id(testcase,parent_id)
29
+ report_result(case_id,testcase) if run_id
30
+ end
31
+ element.children.select{|n| n.name=='testsuite'}.each do |testsuite|
32
+ section_id = get_section_id(testsuite,parent_id) if testsuite.attributes['name'].value.size > 0
33
+ recurse_down(testsuite,level+1,(section_id || parent_id))
34
+ end
35
+ end
36
+
37
+ def get_section_id(testsuite,parent_id=nil)
38
+ section = sections.detect{|s| s['name'] == testsuite.attributes['name'].value}
39
+ unless section
40
+ section = testrail_api_client.send_post("add_section/#{project_id}",{suite_id:suite_id,name:testsuite.attributes['name'].value,parent_id:parent_id})
41
+ sections << section
42
+ end
43
+ section['id']
44
+ end
45
+
46
+ def sections
47
+ @all_sections ||= get_sections
48
+ end
49
+
50
+ def get_sections
51
+ sections = testrail_api_client.send_get("get_sections/#{project_id}&suite_id=#{suite_id}")
52
+ end
53
+
54
+ def get_testcase_id(testcase,section_id)
55
+ unless testcases[section_id]
56
+ testcases[section_id] = testrail_api_client.send_get("get_cases/#{project_id}&suite_id=#{suite_id}&section_id=#{section_id}")
57
+ end
58
+ unless testcases[section_id].detect{|tc| tc['title'] == testcase.attributes['name'].value}
59
+ new_tc = testrail_api_client.send_post("add_case/#{section_id}",{title:testcase.attributes['name'].value,type_id:1})
60
+ testcases[section_id] << new_tc
61
+ end
62
+ testcases[section_id].detect{|tc| tc['title'] == testcase.attributes['name'].value}['id']
63
+ end
64
+
65
+ def report_result(case_id,testcase)
66
+ if testcase.children.any?{|c| c.name=='failure'}
67
+ failure_text = testcase.children.select{|c| c.name=='failure'}.map{|c| c.text}.join("\n")
68
+ result = {status_id: 5,comment: failure_text}
69
+ else
70
+ result = {status_id: 1,comment: 'passed'}
71
+ end
72
+ testrail_api_client.send_post("add_result_for_case/#{run_id}/#{case_id}",result)
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,22 @@
1
+ require_relative '../junit_sender'
2
+ desc "load Junit style xml results into test suite,FILE=results_file, PROJECT_ID=X, SUITE_ID=Y, optional SUB_SECTION=Z"
3
+ task :load_junit_results_to_test_suite do
4
+ check_command_line_parameters_are_present
5
+ junit = Cukerail::JunitSender.new(ENV['FILE'])
6
+ junit.load
7
+ end
8
+
9
+ desc "load Junit style xml results into tesrun,FILE=results_file, PROJECT_ID=X, SUITE_ID=Y, optional SUB_SECTION=Z, TESTRUN=A"
10
+ task :load_junit_results_to_test_run do
11
+ check_command_line_parameters_are_present
12
+ raise 'TESTRUN is required' unless ENV['TESTRUN']
13
+ junit = Cukerail::JunitSender.new(ENV['FILE'])
14
+ junit.load
15
+ end
16
+
17
+ def check_command_line_parameters_are_present
18
+ raise 'PROJECT_ID is required' unless ENV['PROJECT_ID']
19
+ raise 'SUITE_ID is required' unless ENV['SUITE_ID']
20
+ raise 'SUB_SECTION is required' unless ENV['SUB_SECTION']
21
+ raise 'FILE is required' unless ENV['FILE']
22
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cukerail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Small
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-01 00:00:00.000000000 Z
11
+ date: 2016-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber
@@ -142,7 +142,9 @@ files:
142
142
  - lib/cukerail/testrail.rb
143
143
  - lib/cukerail/version.rb
144
144
  - lib/json_sender.rb
145
+ - lib/junit_sender.rb
145
146
  - lib/tasks/cukerail.rake
147
+ - lib/tasks/junit.rake
146
148
  - spec/cukerail_spec.rb
147
149
  - spec/spec_helper.rb
148
150
  homepage: ''