testmetrics_rspec 1.0.1 → 1.1.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/Gemfile +1 -3
- data/README.md +35 -26
- data/Rakefile +3 -3
- data/bin/console +3 -3
- data/example/spec/example_spec.rb +19 -19
- data/example/spec/shared_examples.rb +4 -4
- data/example/spec/spec_helper.rb +1 -0
- data/lib/testmetrics_rspec/parallel_tests.rb +39 -0
- data/lib/testmetrics_rspec/persist.rb +38 -8
- data/lib/testmetrics_rspec/rspec2.rb +11 -77
- data/lib/testmetrics_rspec/rspec3.rb +9 -75
- data/lib/testmetrics_rspec/shared.rb +91 -0
- data/lib/testmetrics_rspec.rb +3 -2
- data/testmetrics_rspec.gemspec +19 -16
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61a13a84f9ca0a791bc49e5883790d2d11273208f465990aca64ae1134e4c6b6
|
4
|
+
data.tar.gz: 7512a2be5780a01369b6ace01a8afd375c03a96742f749047f61c92d286a1a90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8153b351c7752b79b854de242ef38a9f7c1f4df4f37c48a40d3390c0e849afc186450bb8fb806a6def3e925aa40e5b4bffd82682fd9cfeaa25bc2165d66c6058
|
7
|
+
data.tar.gz: 85ef93d5e182f64ae3600b88774599b36aa638d208d297b708357ecfcbe0cd800297d625eaaf4163bd371498c6523705f5a335f788a25fb5fb7ccdec05c69f48
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -4,51 +4,60 @@ The official [RSpec][rspec] 2 & 3 client for [Testmetrics](https://www.testmetri
|
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
7
|
-
|
7
|
+
Add it to your Gemfile in the same groups as rspec.
|
8
8
|
|
9
|
-
```
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
```sh
|
16
|
-
rspec --format TestmetricsRspec
|
9
|
+
```ruby
|
10
|
+
group :test do
|
11
|
+
gem "rspec"
|
12
|
+
gem "testmetrics_rspec"
|
13
|
+
end
|
17
14
|
```
|
18
15
|
|
19
|
-
|
16
|
+
Add `TestmetricsRspec` as a formatter in [your `.rspec` file][rspec-file]:
|
20
17
|
|
21
18
|
```sh
|
22
|
-
|
19
|
+
--format TestmetricsRspec
|
23
20
|
```
|
24
21
|
|
25
|
-
[
|
22
|
+
[bundler]: https://bundler.io
|
23
|
+
[rspec-file]: https://relishapp.com/rspec/rspec-core/v/3-6/docs/configuration/read-command-line-configuration-options-from-files
|
26
24
|
|
27
|
-
In order for the metrics to be
|
25
|
+
In order for the metrics to be sent to Testmetrics, you must have your
|
28
26
|
Testmetrics Project Key set in the "TESTMETRICS_PROJECT_KEY" environment
|
29
27
|
variable in your CI environment. If this environment variable isn't set, the
|
30
|
-
collected metrics for your CI run will be discarded.
|
31
|
-
private and not exposed to the public.
|
28
|
+
collected metrics for your CI run will be discarded.
|
32
29
|
|
33
|
-
|
30
|
+
This key should be kept private and not exposed to the public.
|
34
31
|
|
35
|
-
|
32
|
+
### Additional setup for using with the `parallel_tests` gem
|
36
33
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
```
|
34
|
+
If you are running your tests in parallel in CI with the `parallel_tests` gem,
|
35
|
+
there are additional steps you need to take to start collecting metrics in CI.
|
36
|
+
|
37
|
+
First, do the steps listed above.
|
43
38
|
|
44
|
-
|
39
|
+
If you have a `.rspec_parallel` file, also add `TestmetricsRspec` as a formatter
|
40
|
+
there:
|
45
41
|
|
46
42
|
```sh
|
47
43
|
--format TestmetricsRspec
|
48
44
|
```
|
49
45
|
|
50
|
-
|
51
|
-
|
46
|
+
Then, add the following task to your `Rakefile`
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
require 'testmetrics_rspec'
|
50
|
+
task :testmetrics_parallel_rspec do
|
51
|
+
TestmetricsRspec::ParallelTests.run()
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
Lastly, you'll need to change your CI script to use that rake task to run your
|
56
|
+
tests. `rake testmetrics_parallel_rspec` (or whatever you name that task - it
|
57
|
+
can be whatever you want) is just a wrapper around running `parallel_rspec`, so
|
58
|
+
all command line options that you would normally give work just the same. You
|
59
|
+
just replace `parallel_rspec` with `rake testmetrics_parallel_rspec` and it will
|
60
|
+
work.
|
52
61
|
|
53
62
|
## License
|
54
63
|
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'testmetrics_rspec'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "testmetrics_rspec"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start(__FILE__)
|
@@ -1,20 +1,20 @@
|
|
1
|
-
require
|
2
|
-
require_relative
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'shared_examples'
|
3
3
|
|
4
|
-
describe
|
5
|
-
it
|
4
|
+
describe 'some example specs' do
|
5
|
+
it 'should succeed' do
|
6
6
|
expect(true).to be(true)
|
7
7
|
end
|
8
8
|
|
9
|
-
it
|
9
|
+
it 'should fail' do
|
10
10
|
expect(false).to be(true)
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
13
|
+
it 'should raise' do
|
14
14
|
raise ArgumentError
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it 'should be pending' do
|
18
18
|
if defined? skip
|
19
19
|
skip
|
20
20
|
else
|
@@ -22,30 +22,30 @@ describe "some example specs" do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
26
|
-
expect(
|
25
|
+
it 'shows diffs cleanly' do
|
26
|
+
expect(a: 'b', c: 'd').to eql(a: 2, c: 4)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "replaces naughty \0 and \e characters, \x01 and \uFFFF too" do
|
30
|
-
expect("\0\0\0").to eql(
|
30
|
+
expect("\0\0\0").to eql('emergency services')
|
31
31
|
end
|
32
32
|
|
33
33
|
it "escapes controlling \u{7f} characters" do
|
34
|
-
expect("\u{7f}").to eql(
|
34
|
+
expect("\u{7f}").to eql('pacman om nom nom')
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
38
|
-
expect(
|
37
|
+
it 'can include unicodes 😁' do
|
38
|
+
expect('🚀').to eql('🔥')
|
39
39
|
end
|
40
40
|
|
41
|
-
it %
|
42
|
-
expect(
|
41
|
+
it %(escapes <html tags='correctly' and="such & such">) do
|
42
|
+
expect('<p>This is important</p>').to eql('<p>This is <strong>very</strong> important</p>')
|
43
43
|
end
|
44
44
|
|
45
|
-
it_should_behave_like
|
45
|
+
it_should_behave_like 'shared examples'
|
46
46
|
|
47
|
-
it
|
48
|
-
$stdout.puts
|
49
|
-
|
47
|
+
it 'can capture stdout and stderr' do
|
48
|
+
$stdout.puts 'Test'
|
49
|
+
warn 'Bar'
|
50
50
|
end
|
51
51
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
shared_examples
|
2
|
-
context
|
3
|
-
it
|
1
|
+
shared_examples 'shared examples' do
|
2
|
+
context 'in a shared example' do
|
3
|
+
it 'succeeds' do
|
4
4
|
expect(true).to be(true)
|
5
5
|
end
|
6
6
|
|
7
|
-
it
|
7
|
+
it 'also fails' do
|
8
8
|
expect(false).to be(true)
|
9
9
|
end
|
10
10
|
end
|
data/example/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
class TestmetricsRspec < RSpec::Core::Formatters::BaseFormatter
|
2
|
+
# This is a wrapper around running RSpec with the `parallel_tests` gem
|
3
|
+
class ParallelTests
|
4
|
+
class << self
|
5
|
+
include ::TestmetricsRspec::Shared
|
6
|
+
|
7
|
+
def run
|
8
|
+
key = ENV['TESTMETRICS_PROJECT_KEY']
|
9
|
+
|
10
|
+
post(starting_results) unless key.nil?
|
11
|
+
|
12
|
+
ENV['PARALLEL_FORMAT'] = 'true'
|
13
|
+
system("parallel_rspec #{ARGV[1..-1].join(' ')}")
|
14
|
+
ENV['PARALLEL_FORMAT'] = nil
|
15
|
+
|
16
|
+
send_end_results unless key.nil?
|
17
|
+
end
|
18
|
+
|
19
|
+
def send_end_results
|
20
|
+
results = Dir.glob('results*.json').each_with_object([]) do |path, acc|
|
21
|
+
acc << JSON.parse(IO.read(path))
|
22
|
+
FileUtils.rm(path)
|
23
|
+
end
|
24
|
+
|
25
|
+
post(combined(results))
|
26
|
+
end
|
27
|
+
|
28
|
+
def combined(results)
|
29
|
+
start = results.pop
|
30
|
+
|
31
|
+
results.each_with_object(start) do |result, acc|
|
32
|
+
acc['tests'] = acc['tests'] + result['tests']
|
33
|
+
acc['total_run_time'] = acc['total_run_time'] +
|
34
|
+
result['total_run_time']
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -1,15 +1,45 @@
|
|
1
1
|
class TestmetricsRspec
|
2
|
-
# This sends the results to the Testmetrics server
|
2
|
+
# This sends the results to the Testmetrics server or writes them to a file
|
3
|
+
# if the tests are being run in parallel.
|
3
4
|
module Persist
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
class << self
|
6
|
+
include ::TestmetricsRspec::Shared
|
7
|
+
def call(results)
|
8
|
+
puts results if currently_running_tests_for_this_gem?
|
9
|
+
return if project_key_missing?(results)
|
10
|
+
|
11
|
+
persist(results)
|
12
|
+
end
|
13
|
+
|
14
|
+
def persist(results)
|
15
|
+
if running_in_parallel?
|
16
|
+
return if ignore_results?(results)
|
17
|
+
|
18
|
+
write_to_file(results)
|
19
|
+
else
|
20
|
+
post(results)
|
10
21
|
end
|
11
22
|
end
|
12
|
-
|
23
|
+
|
24
|
+
def write_to_file(results)
|
25
|
+
IO.write("results#{ENV['TEST_ENV_NUMBER']}.json", results.to_json)
|
26
|
+
end
|
27
|
+
|
28
|
+
def project_key_missing?(results)
|
29
|
+
results[:key] == 'Unknown'
|
30
|
+
end
|
31
|
+
|
32
|
+
def running_in_parallel?
|
33
|
+
ENV['PARALLEL_FORMAT'] == 'true'
|
34
|
+
end
|
35
|
+
|
36
|
+
def ignore_results?(results)
|
37
|
+
results[:tests] == []
|
38
|
+
end
|
39
|
+
|
40
|
+
def currently_running_tests_for_this_gem?
|
41
|
+
ENV['PRINT_TESTMETRICS_RESULTS'] == 'true'
|
42
|
+
end
|
13
43
|
end
|
14
44
|
end
|
15
45
|
end
|
@@ -1,88 +1,22 @@
|
|
1
|
+
# The RSpec 2 formatter
|
1
2
|
class TestmetricsRspec < RSpec::Core::Formatters::BaseFormatter
|
2
|
-
|
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)
|
14
|
-
super
|
15
|
-
end
|
3
|
+
include ::TestmetricsRspec::Shared
|
16
4
|
|
17
5
|
def stop
|
18
|
-
@results =
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
tests: tests
|
27
|
-
}
|
6
|
+
@results = results do
|
7
|
+
examples.map do |example|
|
8
|
+
format(example.full_description,
|
9
|
+
example.execution_result[:run_time],
|
10
|
+
example.execution_result[:status].to_sym)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
28
14
|
super
|
29
15
|
end
|
30
16
|
|
31
17
|
def dump_summary(duration, example_count, failure_count, pending_count)
|
32
|
-
|
33
|
-
@results[:total_run_time] = (duration * 1_000_000).round(0)
|
18
|
+
@results[:total_run_time] = run_time_in_microseconds(duration)
|
34
19
|
TestmetricsRspec::Persist.call(@results)
|
35
20
|
super
|
36
21
|
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def tests
|
41
|
-
examples.map do |example|
|
42
|
-
{
|
43
|
-
name: example.full_description.delete("\0").delete("\x01").delete("\e"),
|
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
|
-
}
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
BRANCH_VARS = ["TRAVIS_EVENT_TYPE", "CIRCLE_BRANCH", "CI_COMMIT_REF_NAME", "BRANCH_NAME"]
|
52
|
-
def git_branch
|
53
|
-
correct_var = BRANCH_VARS.find do |var| ENV[var] != nil && ENV[var] != "" end
|
54
|
-
|
55
|
-
if correct_var == "TRAVIS_EVENT_TYPE"
|
56
|
-
case ENV[correct_var]
|
57
|
-
when "push"
|
58
|
-
ENV["TRAVIS_BRANCH"]
|
59
|
-
when "pull_request"
|
60
|
-
ENV["TRAVIS_PULL_REQUEST_BRANCH"]
|
61
|
-
end
|
62
|
-
else
|
63
|
-
correct_var.nil? ? "Unknown" : ENV[correct_var]
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
SHA_VARS = ["TRAVIS_COMMIT", "CIRCLE_SHA1", "CI_COMMIT_SHA", "REVISION"]
|
68
|
-
def git_sha
|
69
|
-
correct_var = SHA_VARS.find do |var| ENV[var] != nil end
|
70
|
-
correct_var.nil? ? "Unknown" : ENV[correct_var]
|
71
|
-
end
|
72
|
-
|
73
|
-
def ci_platform
|
74
|
-
correct_var = SHA_VARS.find do |var| ENV[var] != nil end
|
75
|
-
case correct_var
|
76
|
-
when "TRAVIS_COMMIT"
|
77
|
-
"Travis CI"
|
78
|
-
when "CIRCLE_SHA1"
|
79
|
-
"Circle CI"
|
80
|
-
when "CI_COMMIT_SHA"
|
81
|
-
"Gitlab CI"
|
82
|
-
when "REVISION"
|
83
|
-
"Semaphore CI"
|
84
|
-
else
|
85
|
-
"Unknown"
|
86
|
-
end
|
87
|
-
end
|
88
22
|
end
|
@@ -1,86 +1,20 @@
|
|
1
|
+
# The RSpec 3 formatter
|
1
2
|
class TestmetricsRspec < RSpec::Core::Formatters::BaseFormatter
|
2
3
|
RSpec::Core::Formatters.register self, :start, :stop, :dump_summary
|
3
|
-
|
4
|
-
# This sends the "start" message to testmetrics
|
5
|
-
def start(notification)
|
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)
|
17
|
-
super
|
18
|
-
end
|
4
|
+
include ::TestmetricsRspec::Shared
|
19
5
|
|
20
6
|
def stop(notification)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
}
|
7
|
+
@results = results do
|
8
|
+
notification.notifications.map do |test|
|
9
|
+
format(test.example.full_description,
|
10
|
+
test.example.execution_result.run_time,
|
11
|
+
test.example.execution_result.status)
|
12
|
+
end
|
28
13
|
end
|
29
|
-
|
30
|
-
@results = {
|
31
|
-
key: ENV['TESTMETRICS_PROJECT_KEY'] || "Unknown",
|
32
|
-
branch: git_branch,
|
33
|
-
sha: git_sha,
|
34
|
-
metadata: {
|
35
|
-
ruby_version: RUBY_VERSION,
|
36
|
-
ci_platform: ci_platform
|
37
|
-
},
|
38
|
-
tests: tests
|
39
|
-
}
|
40
14
|
end
|
41
15
|
|
42
|
-
# This sends the "end" message to testmetrics
|
43
16
|
def dump_summary(notification)
|
44
|
-
|
45
|
-
@results[:total_run_time] = (notification.duration * 1_000_000).round(0)
|
17
|
+
@results[:total_run_time] = run_time_in_microseconds(notification.duration)
|
46
18
|
TestmetricsRspec::Persist.call(@results)
|
47
19
|
end
|
48
|
-
|
49
|
-
BRANCH_VARS = ["TRAVIS_EVENT_TYPE", "CIRCLE_BRANCH", "CI_COMMIT_REF_NAME", "BRANCH_NAME"]
|
50
|
-
def git_branch
|
51
|
-
correct_var = BRANCH_VARS.find do |var| ENV[var] != nil && ENV[var] != "" end
|
52
|
-
|
53
|
-
if correct_var == "TRAVIS_EVENT_TYPE"
|
54
|
-
case ENV[correct_var]
|
55
|
-
when "push"
|
56
|
-
ENV["TRAVIS_BRANCH"]
|
57
|
-
when "pull_request"
|
58
|
-
ENV["TRAVIS_PULL_REQUEST_BRANCH"]
|
59
|
-
end
|
60
|
-
else
|
61
|
-
correct_var.nil? ? "Unknown" : ENV[correct_var]
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
SHA_VARS = ["TRAVIS_COMMIT", "CIRCLE_SHA1", "CI_COMMIT_SHA", "REVISION"]
|
66
|
-
def git_sha
|
67
|
-
correct_var = SHA_VARS.find do |var| ENV[var] != nil && ENV[var] != "" end
|
68
|
-
correct_var.nil? ? "Unknown" : ENV[correct_var]
|
69
|
-
end
|
70
|
-
|
71
|
-
def ci_platform
|
72
|
-
correct_var = SHA_VARS.find do |var| ENV[var] != nil end
|
73
|
-
case correct_var
|
74
|
-
when "TRAVIS_COMMIT"
|
75
|
-
"Travis CI"
|
76
|
-
when "CIRCLE_SHA1"
|
77
|
-
"Circle CI"
|
78
|
-
when "CI_COMMIT_SHA"
|
79
|
-
"Gitlab CI"
|
80
|
-
when "REVISION"
|
81
|
-
"Semaphore CI"
|
82
|
-
else
|
83
|
-
"Unknown"
|
84
|
-
end
|
85
|
-
end
|
86
20
|
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
class TestmetricsRspec < RSpec::Core::Formatters::BaseFormatter
|
2
|
+
# Shared stuff between formatters
|
3
|
+
module Shared
|
4
|
+
def start(notification)
|
5
|
+
TestmetricsRspec::Persist.call(starting_results)
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def post(results)
|
10
|
+
Faraday.post do |req|
|
11
|
+
req.url 'https://www.testmetrics.app/results'
|
12
|
+
req.headers['Content-Type'] = 'application/json'
|
13
|
+
req.body = results.to_json
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def format(description, run_time, status)
|
18
|
+
{
|
19
|
+
name: description.delete("\0").delete("\x01").delete("\e"),
|
20
|
+
total_run_time: run_time_in_microseconds(run_time),
|
21
|
+
state: status
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def starting_results
|
26
|
+
results { [] }
|
27
|
+
end
|
28
|
+
|
29
|
+
def results
|
30
|
+
{
|
31
|
+
key: ENV['TESTMETRICS_PROJECT_KEY'] || 'Unknown',
|
32
|
+
branch: git_branch,
|
33
|
+
sha: git_sha,
|
34
|
+
metadata: {
|
35
|
+
ruby_version: RUBY_VERSION,
|
36
|
+
ci_platform: ci_platform
|
37
|
+
},
|
38
|
+
tests: yield
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def run_time_in_microseconds(time)
|
43
|
+
(time * 1_000_000).round(0)
|
44
|
+
end
|
45
|
+
|
46
|
+
BRANCH_VARS = %w[
|
47
|
+
TRAVIS_EVENT_TYPE
|
48
|
+
CIRCLE_BRANCH
|
49
|
+
CI_COMMIT_REF_NAME
|
50
|
+
BRANCH_NAME
|
51
|
+
].freeze
|
52
|
+
def git_branch
|
53
|
+
correct_var = correct_var(BRANCH_VARS)
|
54
|
+
|
55
|
+
if correct_var == 'TRAVIS_EVENT_TYPE'
|
56
|
+
travis_branch(correct_var)
|
57
|
+
else
|
58
|
+
correct_var.nil? ? 'Unknown' : ENV[correct_var]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def travis_branch(var)
|
63
|
+
case ENV[var]
|
64
|
+
when 'push'
|
65
|
+
ENV['TRAVIS_BRANCH']
|
66
|
+
when 'pull_request'
|
67
|
+
ENV['TRAVIS_PULL_REQUEST_BRANCH']
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
SHA_VARS = %w[TRAVIS_COMMIT CIRCLE_SHA1 CI_COMMIT_SHA REVISION].freeze
|
72
|
+
def git_sha
|
73
|
+
correct_var = correct_var(SHA_VARS)
|
74
|
+
correct_var.nil? ? 'Unknown' : ENV[correct_var]
|
75
|
+
end
|
76
|
+
|
77
|
+
def ci_platform
|
78
|
+
case correct_var(SHA_VARS)
|
79
|
+
when 'TRAVIS_COMMIT' then 'Travis CI'
|
80
|
+
when 'CIRCLE_SHA1' then 'Circle CI'
|
81
|
+
when 'CI_COMMIT_SHA' then 'Gitlab CI'
|
82
|
+
when 'REVISION' then 'Semaphore CI'
|
83
|
+
else 'Unknown'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def correct_var(vars)
|
88
|
+
vars.find { |var| !ENV[var].nil? && ENV[var] != '' }
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/lib/testmetrics_rspec.rb
CHANGED
@@ -2,11 +2,12 @@ require 'json'
|
|
2
2
|
require 'faraday'
|
3
3
|
require 'rspec/core'
|
4
4
|
require 'rspec/core/formatters/base_formatter'
|
5
|
+
require 'testmetrics_rspec/shared'
|
6
|
+
require 'testmetrics_rspec/persist'
|
7
|
+
require 'testmetrics_rspec/parallel_tests'
|
5
8
|
|
6
9
|
if Gem::Version.new(RSpec::Core::Version::STRING) >= Gem::Version.new('3')
|
7
10
|
require 'testmetrics_rspec/rspec3'
|
8
11
|
else
|
9
12
|
require 'testmetrics_rspec/rspec2'
|
10
13
|
end
|
11
|
-
|
12
|
-
require 'testmetrics_rspec/persist'
|
data/testmetrics_rspec.gemspec
CHANGED
@@ -1,26 +1,29 @@
|
|
1
|
-
lib = File.expand_path(
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
|
-
spec.name =
|
6
|
-
spec.version =
|
7
|
-
spec.authors = [
|
8
|
-
spec.email = [
|
5
|
+
spec.name = 'testmetrics_rspec'
|
6
|
+
spec.version = '1.1.0'
|
7
|
+
spec.authors = ['Devon Estes']
|
8
|
+
spec.email = ['devon.c.estes@gmail.com']
|
9
9
|
|
10
|
-
spec.summary =
|
11
|
-
spec.homepage =
|
10
|
+
spec.summary = 'The official RSpec client for Testmetrics'
|
11
|
+
spec.homepage = 'https://testmetrics.app'
|
12
12
|
|
13
13
|
# Specify which files should be added to the gem when it is released.
|
14
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added
|
15
|
-
|
16
|
-
|
14
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added
|
15
|
+
# into git.
|
16
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
17
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
17
20
|
end
|
18
|
-
spec.bindir =
|
21
|
+
spec.bindir = 'exe'
|
19
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = [
|
23
|
+
spec.require_paths = ['lib']
|
21
24
|
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_runtime_dependency
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
|
+
spec.add_runtime_dependency 'faraday', '>= 0.9.0'
|
26
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: testmetrics_rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Devon Estes
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -87,9 +87,11 @@ files:
|
|
87
87
|
- example/spec/shared_examples.rb
|
88
88
|
- example/spec/spec_helper.rb
|
89
89
|
- lib/testmetrics_rspec.rb
|
90
|
+
- lib/testmetrics_rspec/parallel_tests.rb
|
90
91
|
- lib/testmetrics_rspec/persist.rb
|
91
92
|
- lib/testmetrics_rspec/rspec2.rb
|
92
93
|
- lib/testmetrics_rspec/rspec3.rb
|
94
|
+
- lib/testmetrics_rspec/shared.rb
|
93
95
|
- testmetrics_rspec.gemspec
|
94
96
|
homepage: https://testmetrics.app
|
95
97
|
licenses: []
|