testscore 1.0.2 → 1.0.3
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/testscore.rb +62 -36
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76bebdd70a20dcacf62e18deaf47d685e5babb2436631930612732247809d043
|
4
|
+
data.tar.gz: 1a86c18da613bf93eba915f8d93e086f22ca5c9279c6260947c050975315fd96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fb1393c98e734ad8b3e73692c9c4e289afa7fc03e5bd6d6e671be2b9ba9ab4227386e5b5a94b8861d24cd4d087cf13db3444d0e97b8f152f7f13a809001c660
|
7
|
+
data.tar.gz: 705ed7b81f69ad5709d26fd2e4b85f9dba3122a725c7116b706788427482020e15759991c8a7435acb01318d3d6f961a47262a6472ce8ead153b21bcd40352fd
|
data/lib/testscore.rb
CHANGED
@@ -2,53 +2,71 @@ require 'json'
|
|
2
2
|
require 'zlib'
|
3
3
|
require 'net/http'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
class
|
8
|
-
|
9
|
-
|
5
|
+
if defined?(ActiveRecord)
|
6
|
+
module ActiveRecord
|
7
|
+
class QueryCounter
|
8
|
+
class << self
|
9
|
+
attr_accessor :queries
|
10
|
+
end
|
11
|
+
|
12
|
+
IGNORED_SQL = [
|
13
|
+
/^PRAGMA (?!(table_info))/,
|
14
|
+
/^SELECT currval/,
|
15
|
+
/^SELECT CAST/,
|
16
|
+
/^SELECT @@IDENTITY/,
|
17
|
+
/^SELECT @@ROWCOUNT/,
|
18
|
+
/^SAVEPOINT/,
|
19
|
+
/FROM pg_attribute/,
|
20
|
+
/JOIN pg_attribute/,
|
21
|
+
/JOIN pg_namespace/,
|
22
|
+
/SHOW search_path/,
|
23
|
+
/^BEGIN$/,
|
24
|
+
/^ROLLBACK$/,
|
25
|
+
/^ROLLBACK TO SAVEPOINT/,
|
26
|
+
/^RELEASE SAVEPOINT/,
|
27
|
+
/^SHOW max_identifier_length/
|
28
|
+
]
|
10
29
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
/SHOW search_path/,
|
22
|
-
/^BEGIN$/,
|
23
|
-
/^ROLLBACK$/,
|
24
|
-
/^ROLLBACK TO SAVEPOINT/,
|
25
|
-
/^RELEASE SAVEPOINT/,
|
26
|
-
/^SHOW max_identifier_length/
|
27
|
-
]
|
28
|
-
|
29
|
-
def call(name, start, finish, message_id, values)
|
30
|
-
return if 'CACHE' == values[:name]
|
31
|
-
return if IGNORED_SQL.any? { |r| values[:sql] =~ r }
|
32
|
-
|
33
|
-
self.class.queries ||= []
|
34
|
-
self.class.queries << {
|
35
|
-
duration: finish - start,
|
36
|
-
sql: values[:sql]
|
37
|
-
}
|
30
|
+
def call(name, start, finish, message_id, values)
|
31
|
+
return if 'CACHE' == values[:name]
|
32
|
+
return if IGNORED_SQL.any? { |r| values[:sql] =~ r }
|
33
|
+
|
34
|
+
self.class.queries ||= []
|
35
|
+
self.class.queries << {
|
36
|
+
duration: finish - start,
|
37
|
+
sql: values[:sql]
|
38
|
+
}
|
39
|
+
end
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
42
44
|
module TestScore
|
45
|
+
def self.rails?
|
46
|
+
defined?(ActiveRecord) && defined?(ActiveSupport)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.queries
|
50
|
+
return [] unless rails?
|
51
|
+
|
52
|
+
ActiveRecord::QueryCounter.queries
|
53
|
+
end
|
54
|
+
|
43
55
|
def self.log_suite_started
|
44
56
|
@start_time = Time.now
|
45
|
-
|
57
|
+
|
58
|
+
if rails?
|
59
|
+
ActiveSupport::Notifications.subscribe('sql.active_record', ActiveRecord::QueryCounter.new)
|
60
|
+
end
|
46
61
|
end
|
47
62
|
|
48
63
|
def self.spec_started(example)
|
49
64
|
@results ||= {}
|
50
65
|
@results[example.id] = { started_at: Time.now }
|
51
|
-
|
66
|
+
|
67
|
+
if rails?
|
68
|
+
ActiveRecord::QueryCounter.queries = []
|
69
|
+
end
|
52
70
|
end
|
53
71
|
|
54
72
|
def self.spec_ended(example)
|
@@ -56,7 +74,7 @@ module TestScore
|
|
56
74
|
duration: Time.now - @results[example.id][:started_at],
|
57
75
|
description: example.description,
|
58
76
|
metadata: example.metadata.slice(:line_number, :file_path),
|
59
|
-
queries:
|
77
|
+
queries: queries
|
60
78
|
}
|
61
79
|
end
|
62
80
|
|
@@ -74,7 +92,15 @@ module TestScore
|
|
74
92
|
req.body = gzip.close.string
|
75
93
|
http = Net::HTTP.new(uri.host, uri.port)
|
76
94
|
http.use_ssl = (uri.scheme == "https")
|
77
|
-
http.request(req)
|
95
|
+
response = http.request(req).body
|
96
|
+
|
97
|
+
if response && response.length > 0
|
98
|
+
jsonResponse = JSON.parse(response)
|
99
|
+
|
100
|
+
if jsonResponse['error']
|
101
|
+
puts "Unable to report results to TestScore: #{jsonResponse['error']}"
|
102
|
+
end
|
103
|
+
end
|
78
104
|
rescue => e
|
79
105
|
puts "Unable to report results to TestScore: #{e.message}"
|
80
106
|
end
|