results_keeper 0.5.0 → 0.6.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 +4 -4
- data/lib/results_keeper.rb +53 -51
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29e6f515750e584c6a8eb7ebf99c8d0953231c43
|
4
|
+
data.tar.gz: 0fe308d8e3a3729f2fce4af7315a0db59edadae0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efdd084b8978c642b768c97b73f7a8dc34be0000d29d66dd487d7b425b9ead683b62ebd68116f0354895a42e78ea7fbab10f87d58ff9d780a74f68276e4e1f4a
|
7
|
+
data.tar.gz: 8c115a544bf00d172e5fb33cc7be73c19b29133a4b6c3feae431ba81fbb0a3e427de3231006d61843d9737e915c9319d6a5e287de9c18bafbbd9dea8d3a3567f
|
data/lib/results_keeper.rb
CHANGED
@@ -4,57 +4,44 @@ require 'rest_client'
|
|
4
4
|
require_relative 'string'
|
5
5
|
require 'singleton'
|
6
6
|
require 'pry'
|
7
|
+
require_relative 'test_data_generator'
|
7
8
|
|
8
9
|
class ResultsKeeper
|
9
10
|
include Singleton
|
10
11
|
|
11
|
-
attr_reader :revision_name, :revision_project
|
12
|
-
|
13
12
|
DEFAULT_PORT = 3000
|
14
13
|
DEFAULT_HOST = 'localhost'
|
15
14
|
|
16
15
|
def initialize
|
17
|
-
@
|
18
|
-
@
|
16
|
+
@data_generator = TestDataGenerator.new
|
17
|
+
@tmp_data ||= {}
|
18
|
+
@tmp_data[:tests] ||= []
|
19
|
+
@rk_host = ENV['RK_REPORT_SERVER_HOST'] || DEFAULT_HOST
|
20
|
+
@rk_port = ENV['RK_REPORT_SERVER_PORT'] || DEFAULT_PORT
|
19
21
|
end
|
20
22
|
|
21
23
|
def send_revision
|
22
|
-
|
23
|
-
|
24
|
+
@revision = send_json(@data_generator.revision_data,
|
25
|
+
'revisions',
|
26
|
+
"#{@data_generator.project_name} > #{@data_generator.revision_name} started")
|
24
27
|
end
|
25
28
|
|
26
29
|
def send_revision_complete
|
27
|
-
|
28
|
-
send_json(
|
30
|
+
send_not_sent_scenarios
|
31
|
+
send_json(@data_generator.revision_completed_data,
|
32
|
+
'revisions',
|
33
|
+
"#{@data_generator.revision_name} completed")
|
29
34
|
end
|
30
35
|
|
31
36
|
def send_test(scenario)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
status: scenario.status,
|
38
|
-
feature_name: scenario.feature.name,
|
39
|
-
run_path: run_path,
|
40
|
-
tags: scenario.tags.map(&:name).join(', '),
|
41
|
-
error: scenario_error,
|
42
|
-
revision_id: @revision['revision_id'],
|
43
|
-
steps: scenario_steps(scenario),
|
44
|
-
duration: test_duration
|
45
|
-
}
|
46
|
-
@test = send_json(data, 'tests')
|
37
|
+
# In case if the host is not available we need to send revision once more (when it comes back)
|
38
|
+
send_revision unless @revision
|
39
|
+
return add_test_to_tmp(scenario) unless @revision
|
40
|
+
@screenshot_path = save_screenshot(scenario) if ENV['RK_SEND_SCREENSHOTS']
|
41
|
+
@test = send_json(@data_generator.test_data(scenario, @revision), 'tests')
|
47
42
|
send_screenshot(@screenshot_path) if @screenshot_path
|
48
43
|
end
|
49
44
|
|
50
|
-
def scenario_steps(scenario)
|
51
|
-
if scenario.test_steps.first.to_s.include? 'Cucumber::Core::Test'
|
52
|
-
scenario.test_steps.map { |s| "And #{s.name.to_s}" }
|
53
|
-
else
|
54
|
-
scenario.test_steps.map { |s| "And #{s.to_s}" }
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
45
|
def save_screenshot(scenario)
|
59
46
|
if scenario.exception
|
60
47
|
begin
|
@@ -69,48 +56,63 @@ class ResultsKeeper
|
|
69
56
|
end
|
70
57
|
end
|
71
58
|
|
59
|
+
def add_test_to_tmp(scenario)
|
60
|
+
#console_warning_message("Could not send '#{scenario.name}' there seems to be a problem with #{@rk_host}:#{@rk_port}")
|
61
|
+
@tmp_data[:tests] << scenario
|
62
|
+
puts console_warning_message("Not sent scenarios amount: #{@tmp_data[:tests].count}")
|
63
|
+
end
|
64
|
+
|
65
|
+
def send_not_sent_scenarios
|
66
|
+
if @revision
|
67
|
+
@tmp_data[:tests].each do |s|
|
68
|
+
console_message("Trying to re-send '#{s.name}' once more")
|
69
|
+
send_test(s)
|
70
|
+
end
|
71
|
+
else
|
72
|
+
false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
72
76
|
def send_json(body, path, message_to_client=nil)
|
73
|
-
@host = ENV['REPORT_SERVER_HOST'] || DEFAULT_HOST
|
74
|
-
@port = ENV['REPORT_SERVER_PORT'] || DEFAULT_PORT
|
75
77
|
|
76
78
|
body['secret_key'] = ENV['RK_SECRET_KEY']
|
77
79
|
@path = "/api/#{path}"
|
78
80
|
@body = body.to_json
|
79
81
|
|
80
|
-
request = Net::HTTP::Post.new(@path, initheader = {'Content-Type' => 'application/json'})
|
81
|
-
request.body = @body
|
82
|
-
response = Net::HTTP.new(@host, @port).start {|http| http.request(request)}
|
83
82
|
begin
|
83
|
+
request = Net::HTTP::Post.new(@path, initheader = {'Content-Type' => 'application/json'})
|
84
|
+
request.body = @body
|
85
|
+
response = Net::HTTP.new(@rk_host, @rk_port).start {|http| http.request(request)}
|
86
|
+
|
84
87
|
message_to_client ? console_message("#{message_to_client} - #{response.code} - #{response.message}") : console_message("#{response.code} - #{response.message}")
|
85
|
-
|
86
|
-
results_hash
|
88
|
+
JSON.parse(response.body)
|
87
89
|
rescue
|
88
|
-
|
90
|
+
console_warning_message("There seems to be a problem with #{@rk_host}:#{@rk_port}, make sure your RK_SECRET_KEY is correct and server is up.")
|
91
|
+
false
|
89
92
|
end
|
90
93
|
end
|
91
94
|
|
92
95
|
def send_screenshot(screenshot_path)
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
t1.join
|
96
|
+
begin
|
97
|
+
params = {project: @revision['project_id'], revision: @revision['revision_id'], test: @test['id']}
|
98
|
+
RestClient.post("http://#{@rk_host}:#{@rk_port}/api/tests/upload_screenshot",
|
99
|
+
:name_of_file_param => File.new(screenshot_path), :body => params)
|
100
|
+
File.delete(screenshot_path)
|
101
|
+
rescue => e
|
102
|
+
console_warning_message("Could not send screenshot, there seems to be a problem with #{@rk_host}:#{@rk_port}")
|
101
103
|
end
|
102
104
|
end
|
103
105
|
|
104
|
-
def
|
105
|
-
|
106
|
+
def test_started(scenarion=nil)
|
107
|
+
@data_generator.test_started
|
106
108
|
end
|
107
109
|
|
108
110
|
def console_message(text)
|
109
111
|
puts " Results Keeper: #{text}".blue unless ENV['HIDE_RK_MESSAGES'] == 'true'
|
110
112
|
end
|
111
113
|
|
112
|
-
def
|
113
|
-
|
114
|
+
def console_warning_message(text)
|
115
|
+
puts " Results Keeper: #{text}".yellow unless ENV['HIDE_RK_MESSAGES'] == 'true'
|
114
116
|
end
|
115
117
|
end
|
116
118
|
|