testmetrics_rspec 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca2804b98b037c67b23476d07586b3f8c8e0843ffb8ef8b98fbdc7eced0d956b
4
- data.tar.gz: d402bac313a1668ee771a38347caf94eaa272e3ad44962fe4aa04835935e5ffa
3
+ metadata.gz: f442413399ca375da33c09ac075f6089c76eb539e431bb7a71a99e58fb0deef3
4
+ data.tar.gz: 4ab090299facb131c0e13a0a65bc1290afc28c699799fbf9442167fcdf400dba
5
5
  SHA512:
6
- metadata.gz: 88a93ab6b35b8fdcca980850eaf63cd96eb6438fdd7c94ff04e499e67db871b51c78687f0a4b4330007b19223382f3d377e939c09a4fa3bad431809f4558c09a
7
- data.tar.gz: 49bb0f27a4ff2944199df67b0df5ef7ac818c4d1edb39c4a057bfdb5cd570939ed342d1494dcebc8956380a6a45107d6997c135cade0e5dc6ad16d648bbe2ed4
6
+ metadata.gz: 85851e3687a1ea8098d71ddf1e530bc3fdee1ffae0a81dee1a6ce4c8d894d3d0f80cc1a3bca1ef63f14c225cfba4fe3568c37be8a0b6caf6fd8297f965f5556d
7
+ data.tar.gz: ae1a9e350328fd93165a21235fb6d0fee309bc5153275414a2233d0f8678c585622b97f35d6892c33c29b10e225977f48a56c4758467b710697d11cb3c757a22
data/.travis.yml ADDED
@@ -0,0 +1,20 @@
1
+ rvm:
2
+ - 2.3
3
+ - 2.4
4
+ - 2.5
5
+ - ruby-head
6
+
7
+ before_install:
8
+ - gem update --system
9
+ - gem update bundler
10
+ - gem cleanup bundler
11
+
12
+ install: "bundle install --jobs 8"
13
+ script: "bundle exec rake"
14
+ matrix:
15
+ fast_finish: true
16
+ allow_failures:
17
+ - rvm: ruby-head
18
+
19
+ sudo: false
20
+ cache: bundler
data/Gemfile.lock CHANGED
@@ -1,12 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- testmetrics_rspec (0.1.0)
4
+ testmetrics_rspec (0.2.0)
5
+ faraday (>= 0.9.0)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
9
10
  diff-lcs (1.3)
11
+ faraday (0.15.4)
12
+ multipart-post (>= 1.2, < 3)
13
+ multipart-post (2.0.0)
10
14
  rake (10.5.0)
11
15
  rspec (3.8.0)
12
16
  rspec-core (~> 3.8.0)
@@ -1,6 +1,11 @@
1
- # This sends the results to the Testmetrics server
2
- module TestmetricsRspec::Persist
3
- def self.call(results)
4
- puts results
1
+ class TestmetricsRspec
2
+ # This sends the results to the Testmetrics server
3
+ module Persist
4
+ def self.call(results)
5
+ unless results[:key] == "Unknown"
6
+ Faraday.post('https://www.testmetrics.app/results', results)
7
+ end
8
+ puts results
9
+ end
5
10
  end
6
11
  end
@@ -1,79 +1,78 @@
1
1
  class TestmetricsRspec < RSpec::Core::Formatters::BaseFormatter
2
- attr_reader :started
3
-
4
2
  def start(example_count)
5
- @started = Time.now
3
+ results = {
4
+ key: ENV['TESTMETRICS_PROJECT_KEY'],
5
+ branch: git_branch,
6
+ sha: git_sha,
7
+ metadata: {
8
+ ruby_version: RUBY_VERSION,
9
+ ci_platform: ci_platform
10
+ },
11
+ tests: []
12
+ }
13
+ TestmetricsRspec::Persist.call(results)
6
14
  super
7
15
  end
8
16
 
9
- def dump_summary(duration, example_count, failure_count, pending_count)
17
+ def stop
18
+ @results = {
19
+ key: ENV['TESTMETRICS_PROJECT_KEY'],
20
+ branch: git_branch,
21
+ sha: git_sha,
22
+ metadata: {
23
+ ruby_version: RUBY_VERSION,
24
+ ci_platform: ci_platform
25
+ },
26
+ tests: tests
27
+ }
10
28
  super
11
29
  end
12
30
 
13
- private
14
-
15
- def result_of(example)
16
- example.execution_result[:status].to_sym
17
- end
18
-
19
- def example_group_file_path_for(example)
20
- meta = example.metadata
21
- while meta[:example_group]
22
- meta = meta[:example_group]
23
- end
24
- meta[:file_path]
25
- end
26
-
27
- def classname_for(example)
28
- fp = example_group_file_path_for(example)
29
- fp.sub(%r{\.[^/.]+\Z}, "").gsub("/", ".").gsub(/\A\.+|\.+\Z/, "")
30
- end
31
-
32
- def duration_for(example)
33
- example.execution_result[:run_time]
34
- end
35
-
36
- def description_for(example)
37
- example.full_description
38
- end
39
-
40
- def exception_for(example)
41
- example.execution_result[:exception]
42
- end
43
-
44
- def failure_type_for(example)
45
- exception_for(example).class.name
46
- end
47
-
48
- def failure_message_for(example)
49
- strip_diff_colors(exception_for(example).to_s)
31
+ def dump_summary(duration, example_count, failure_count, pending_count)
32
+ # Send results in microseconds
33
+ @results[:total_run_time] = (duration * 1_000_000).round(0)
34
+ TestmetricsRspec::Persist.call(@results)
35
+ super
50
36
  end
51
37
 
52
- def failure_for(example)
53
- exception = exception_for(example)
54
- message = strip_diff_colors(exception.message)
55
- backtrace = format_backtrace(exception.backtrace, example)
38
+ private
56
39
 
57
- if shared_group = find_shared_group(example)
58
- backtrace << "Shared Example Group: \"#{shared_group.metadata[:shared_group_name]}\" called from #{shared_group.metadata[:example_group][:location]}"
40
+ def tests
41
+ examples.map do |example|
42
+ {
43
+ name: example.full_description,
44
+ # Send results in microseconds
45
+ total_run_time: (example.execution_result[:run_time] * 1_000_000).round(0),
46
+ state: example.execution_result[:status].to_sym
47
+ }
59
48
  end
60
-
61
- "#{message}\n#{backtrace.join("\n")}"
62
49
  end
63
50
 
64
- def find_shared_group(example)
65
- group_and_parent_groups(example).find { |group| group.metadata[:shared_group_name] }
51
+ BRANCH_VARS = ["TRAVIS_BRANCH", "CIRCLE_BRANCH", "CI_COMMIT_REF_NAME", "BRANCH_NAME"]
52
+ def git_branch
53
+ correct_var = BRANCH_VARS.find do |var| ENV[var] != nil end
54
+ correct_var.nil? ? "Unknown" : ENV[correct_var]
66
55
  end
67
56
 
68
- def group_and_parent_groups(example)
69
- example.example_group.parent_groups + [example.example_group]
57
+ SHA_VARS = ["TRAVIS_COMMIT", "CIRCLE_SHA1", "CI_COMMIT_SHA", "REVISION"]
58
+ def git_sha
59
+ correct_var = SHA_VARS.find do |var| ENV[var] != nil end
60
+ correct_var.nil? ? "Unknown" : ENV[correct_var]
70
61
  end
71
62
 
72
- def stdout_for(example)
73
- example.metadata[:stdout]
74
- end
75
-
76
- def stderr_for(example)
77
- example.metadata[:stderr]
63
+ def ci_platform
64
+ correct_var = SHA_VARS.find do |var| ENV[var] != nil end
65
+ case correct_var
66
+ when "TRAVIS_COMMIT"
67
+ "Travis CI"
68
+ when "CIRCLE_SHA1"
69
+ "Circle CI"
70
+ when "CI_COMMIT_SHA"
71
+ "Gitlab CI"
72
+ when "REVISION"
73
+ "Semaphore CI"
74
+ else
75
+ "Unknown"
76
+ end
78
77
  end
79
78
  end
@@ -1,10 +1,19 @@
1
- # Doc
2
1
  class TestmetricsRspec < RSpec::Core::Formatters::BaseFormatter
3
2
  RSpec::Core::Formatters.register self, :start, :stop, :dump_summary
4
3
 
5
4
  # This sends the "start" message to testmetrics
6
5
  def start(notification)
7
- TestmetricsRspec::Persist.call({})
6
+ results = {
7
+ key: ENV['TESTMETRICS_PROJECT_KEY'] || "Unknown",
8
+ branch: git_branch,
9
+ sha: git_sha,
10
+ metadata: {
11
+ ruby_version: RUBY_VERSION,
12
+ ci_platform: ci_platform
13
+ },
14
+ tests: []
15
+ }
16
+ TestmetricsRspec::Persist.call(results)
8
17
  super
9
18
  end
10
19
 
@@ -12,14 +21,14 @@ class TestmetricsRspec < RSpec::Core::Formatters::BaseFormatter
12
21
  tests = notification.notifications.map do |test|
13
22
  {
14
23
  name: test.example.full_description,
15
- total_run_time: test.example.execution_result.run_time,
24
+ # Send results in microseconds
25
+ total_run_time: (test.example.execution_result.run_time * 1_000_000).round(0),
16
26
  state: test.example.execution_result.status
17
27
  }
18
28
  end
19
29
 
20
30
  @results = {
21
- total_run_time: nil,
22
- key: ENV['TESTMETRICS_PROJECT_KEY'],
31
+ key: ENV['TESTMETRICS_PROJECT_KEY'] || "Unknown",
23
32
  branch: git_branch,
24
33
  sha: git_sha,
25
34
  metadata: {
@@ -32,20 +41,21 @@ class TestmetricsRspec < RSpec::Core::Formatters::BaseFormatter
32
41
 
33
42
  # This sends the "end" message to testmetrics
34
43
  def dump_summary(notification)
35
- @results[:total_run_time] = notification.duration
44
+ # Send results in microseconds
45
+ @results[:total_run_time] = (notification.duration * 1_000_000).round(0)
36
46
  TestmetricsRspec::Persist.call(@results)
37
47
  end
38
48
 
39
49
  BRANCH_VARS = ["TRAVIS_BRANCH", "CIRCLE_BRANCH", "CI_COMMIT_REF_NAME", "BRANCH_NAME"]
40
50
  def git_branch
41
51
  correct_var = BRANCH_VARS.find do |var| ENV[var] != nil end
42
- correct_var.nil? ? nil : ENV[correct_var]
52
+ correct_var.nil? ? "Unknown" : ENV[correct_var]
43
53
  end
44
54
 
45
55
  SHA_VARS = ["TRAVIS_COMMIT", "CIRCLE_SHA1", "CI_COMMIT_SHA", "REVISION"]
46
56
  def git_sha
47
57
  correct_var = SHA_VARS.find do |var| ENV[var] != nil end
48
- correct_var.nil? ? nil : ENV[correct_var]
58
+ correct_var.nil? ? "Unknown" : ENV[correct_var]
49
59
  end
50
60
 
51
61
  def ci_platform
@@ -1,3 +1,4 @@
1
+ require 'faraday'
1
2
  require 'rspec/core'
2
3
  require 'rspec/core/formatters/base_formatter'
3
4
 
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "testmetrics_rspec"
7
- spec.version = "0.1.0"
7
+ spec.version = "0.2.0"
8
8
  spec.authors = ["Devon Estes"]
9
9
  spec.email = ["devon.c.estes@gmail.com"]
10
10
 
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 1.16"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
25
  spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_runtime_dependency "faraday", ">= 0.9.0"
26
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testmetrics_rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Devon Estes
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.9.0
55
69
  description:
56
70
  email:
57
71
  - devon.c.estes@gmail.com
@@ -60,6 +74,7 @@ extensions: []
60
74
  extra_rdoc_files: []
61
75
  files:
62
76
  - ".gitignore"
77
+ - ".travis.yml"
63
78
  - Gemfile
64
79
  - Gemfile.lock
65
80
  - LICENSE