test_dots 0.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.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/Gemfile +4 -0
  4. data/README.md +86 -0
  5. data/Rakefile +6 -0
  6. data/bin/console +14 -0
  7. data/bin/setup +8 -0
  8. data/examples/minitest/Gemfile +6 -0
  9. data/examples/minitest/Gemfile.lock +21 -0
  10. data/examples/minitest/Rakefile +6 -0
  11. data/examples/minitest/test/features/feature_example_test.rb +11 -0
  12. data/examples/minitest/test/test_helper.rb +8 -0
  13. data/examples/minitest/test/units/unit_example_test.rb +11 -0
  14. data/examples/minitest_specs/Gemfile +5 -0
  15. data/examples/minitest_specs/Gemfile.lock +19 -0
  16. data/examples/minitest_specs/example_test.rb +20 -0
  17. data/examples/rspec/Gemfile +5 -0
  18. data/examples/rspec/Gemfile.lock +32 -0
  19. data/examples/rspec/spec/features/feature_example_spec.rb +11 -0
  20. data/examples/rspec/spec/spec_helper.rb +10 -0
  21. data/examples/rspec/spec/units/unit_example_spec.rb +11 -0
  22. data/examples/rspec_custom_adapter/Gemfile +5 -0
  23. data/examples/rspec_custom_adapter/Gemfile.lock +32 -0
  24. data/examples/rspec_custom_adapter/example_spec.rb +37 -0
  25. data/examples/rspec_full/Gemfile +5 -0
  26. data/examples/rspec_full/Gemfile.lock +32 -0
  27. data/examples/rspec_full/example_spec.rb +57 -0
  28. data/lib/minitest/test_dots_plugin.rb +66 -0
  29. data/lib/test_dots/api.rb +20 -0
  30. data/lib/test_dots/ci_adapters/base.rb +21 -0
  31. data/lib/test_dots/ci_adapters/circle_ci.rb +21 -0
  32. data/lib/test_dots/ci_adapters/jenkins.rb +21 -0
  33. data/lib/test_dots/ci_adapters/travis_ci.rb +17 -0
  34. data/lib/test_dots/configuration.rb +31 -0
  35. data/lib/test_dots/rspec_listener.rb +68 -0
  36. data/lib/test_dots/version.rb +3 -0
  37. data/lib/test_dots.rb +43 -0
  38. data/resources/cacert.pem +3646 -0
  39. data/test_dots.gemspec +29 -0
  40. metadata +151 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a467e52898dc1852528c61576ee18dd9f74043d8
4
+ data.tar.gz: bcf7f771ef4c00f6cd3ba40e603029660033c2e8
5
+ SHA512:
6
+ metadata.gz: 1125708c5036e636d8324377dc1e4dc85d8c4534ba558dbdacb4177103247f8c2f826f96672b176a44962c8dcd17c1a2fa165db4546ab598ebe9483674245b50
7
+ data.tar.gz: c080b6225a22d3b72db698a2ad4aa6bbd25dbd1f45c650c1a6499167a6fd2ec20ce540f75b4aae476080f39913b9724395187c7d90c8acfc3ff8dd8bcb848846
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ .rspec_status
12
+
13
+ test_output.log
14
+
15
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in test_dots.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ ## TestDots
2
+
3
+ This is the Ruby gem for the [Test Dots CI performance monitoring service](https://testdots.com/).
4
+
5
+ ## Installation instructions for a Rails Project
6
+
7
+ **1.** Add TestDots to your project's Gemfile in the 'test' group.
8
+
9
+ ```ruby
10
+ group :test do
11
+ gem 'test_dots'
12
+ end
13
+ ```
14
+
15
+ **2.** If you are using RSpec, add the following to your `spec_helper.rb` file. This is not needed for MiniTest.
16
+
17
+ ```ruby
18
+ TestDots.register_rspec_listener
19
+ ```
20
+
21
+ **3.** Configure your API key by setting the `TEST_DOTS_KEY` environment variable in your continuous integration tool.
22
+
23
+ ## Integrating with Test Frameworks
24
+
25
+ Test Dots integrates with different test frameworks to get timing and result information about your tests.
26
+
27
+ ### Supported Test Frameworks
28
+ + RSpec
29
+ + MiniTest
30
+
31
+ ## Integrating with CI services
32
+
33
+ The TestDots gem integrates with different CI services to gather more information about each of your builds. It does this by looking at the environment variables CI services set such as the build number and the name of the branch being built.
34
+
35
+ ### Supported CI services
36
+ + TravisCI
37
+ + CircleCI
38
+ + Jenkins
39
+
40
+ ### Writing a custom adapter
41
+
42
+ If you want to write your own CI adapter you should:
43
+ + Subclass `TestDots::CIAdapters::Base`
44
+ + Implement any of the `branch`, `build` and `url` methods
45
+ + `build` should return a unique identifier to represent the build. Multiple parts of the same build can return the same value.
46
+ + `url` should return be a URL that can be followed to view this build in you CI service.
47
+ + `branch` should return be the name of commit or branch being built
48
+ + Change the `ci_adapter` configuration option to use your adapter.
49
+
50
+ For example, for a fictional 'CoolCI' service, you might write:
51
+
52
+ ```ruby
53
+ class CoolCI < TestDots::CIAdapters::Base
54
+ def branch
55
+ ENV['COOL_CI_BRANCH']
56
+ end
57
+
58
+ def build
59
+ ENV['COOL_CI_BUILD_NUM']
60
+ end
61
+
62
+ def url
63
+ ENV['COOL_CI_BUILD_URL']
64
+ end
65
+ end
66
+
67
+ TestDots.configure do |config|
68
+ config.ci_adapter = CoolCI.new
69
+ end
70
+ ```
71
+
72
+
73
+ ## Configuration options
74
+
75
+ You can override the default configuration options by passing a block to `TestDots.configure`. This can be done in your `test_helper.rb` or `spec_helper.rb` files.
76
+
77
+ ```ruby
78
+ TestDots.configure do |config|
79
+ config.api_key = ENV['MY_TEST_DOTS_KEY']
80
+ end
81
+ ```
82
+
83
+ | Option | Use | Default |
84
+ |:-:|:-:|:-:|
85
+ | `api_key` | Your projects API key. If not set, the test suite will not be monitored | The value of the `TEST_DOTS_KEY` environment variable |
86
+ | `ci_adapter` | What CI service to integrate with | Picks the an adapter based on the [supported CI services](#Supported-CI-Services) |
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "test_dots"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ source "https://rubygems.org"
3
+
4
+ gem "minitest"
5
+ gem 'test_dots', path: '../../'
6
+ gem 'rake'
@@ -0,0 +1,21 @@
1
+ PATH
2
+ remote: ../..
3
+ specs:
4
+ test_dots (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ minitest (5.10.3)
10
+ rake (12.1.0)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ minitest
17
+ rake
18
+ test_dots!
19
+
20
+ BUNDLED WITH
21
+ 1.15.4
@@ -0,0 +1,6 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << "test"
5
+ t.pattern = "test/**/*_test.rb"
6
+ end
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ class FeatureExampleTest < Minitest::Test
4
+ def test_numerics
5
+ assert_equal 1, 1
6
+ end
7
+
8
+ def test_booleans
9
+ assert_equal true, true
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'test_dots'
4
+ require 'minitest/autorun'
5
+
6
+ TestDots.configure do |config|
7
+ config.use_ssl = false
8
+ end
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ class UnitExampleTest < Minitest::Test
4
+ def test_it_passes
5
+ assert_equal true, true
6
+ end
7
+
8
+ def test_it_fails
9
+ assert_equal true, false
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ source "https://rubygems.org"
3
+
4
+ gem "minitest"
5
+ gem 'test_dots', path: '../../'
@@ -0,0 +1,19 @@
1
+ PATH
2
+ remote: ../..
3
+ specs:
4
+ test_dots (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ minitest (5.10.3)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ minitest
16
+ test_dots!
17
+
18
+ BUNDLED WITH
19
+ 1.15.1
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require "minitest/autorun"
4
+ require 'test_dots'
5
+
6
+ TestDots.configure do |config|
7
+ config.use_ssl = false
8
+ end
9
+
10
+ describe 'TestExample' do
11
+ describe "passing" do
12
+ it 'passes' do
13
+ assert_equal true, true
14
+ end
15
+ end
16
+
17
+ it 'fails' do
18
+ assert_equal true, false
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ source "https://rubygems.org"
3
+
4
+ gem "rspec"
5
+ gem 'test_dots', path: '../../'
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: ../..
3
+ specs:
4
+ test_dots (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rspec (3.6.0)
11
+ rspec-core (~> 3.6.0)
12
+ rspec-expectations (~> 3.6.0)
13
+ rspec-mocks (~> 3.6.0)
14
+ rspec-core (3.6.0)
15
+ rspec-support (~> 3.6.0)
16
+ rspec-expectations (3.6.0)
17
+ diff-lcs (>= 1.2.0, < 2.0)
18
+ rspec-support (~> 3.6.0)
19
+ rspec-mocks (3.6.0)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.6.0)
22
+ rspec-support (3.6.0)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ rspec
29
+ test_dots!
30
+
31
+ BUNDLED WITH
32
+ 1.15.1
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe "feature example" do
4
+ it 'works with numbers' do
5
+ expect(1).to eq(1)
6
+ end
7
+
8
+ it 'works with booleans' do
9
+ expect(true).to eq(true)
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rspec'
4
+ require 'test_dots'
5
+
6
+ TestDots.configure do |config|
7
+ config.use_ssl = false
8
+ end
9
+
10
+ TestDots.register_rspec_listener
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe "unit example" do
4
+ it 'is passing' do
5
+ expect(true).to be(true)
6
+ end
7
+
8
+ it 'is failing' do
9
+ expect(true).to be(false)
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ source "https://rubygems.org"
3
+
4
+ gem "rspec"
5
+ gem 'test_dots', path: '../../'
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: ../..
3
+ specs:
4
+ test_dots (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rspec (3.6.0)
11
+ rspec-core (~> 3.6.0)
12
+ rspec-expectations (~> 3.6.0)
13
+ rspec-mocks (~> 3.6.0)
14
+ rspec-core (3.6.0)
15
+ rspec-support (~> 3.6.0)
16
+ rspec-expectations (3.6.0)
17
+ diff-lcs (>= 1.2.0, < 2.0)
18
+ rspec-support (~> 3.6.0)
19
+ rspec-mocks (3.6.0)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.6.0)
22
+ rspec-support (3.6.0)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ rspec
29
+ test_dots!
30
+
31
+ BUNDLED WITH
32
+ 1.16.0
@@ -0,0 +1,37 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rspec'
4
+ require 'test_dots'
5
+
6
+ class MyAdapter < TestDots::CIAdapters::Base
7
+ def build
8
+ 'a-build'
9
+ end
10
+
11
+ def branch
12
+ 'a-branch'
13
+ end
14
+
15
+ def url
16
+ 'http://example.com/a-url'
17
+ end
18
+ end
19
+
20
+ TestDots.configure do |config|
21
+ config.use_ssl = false
22
+ config.ci_adapter = MyAdapter.new
23
+ end
24
+
25
+ TestDots.register_rspec_listener
26
+
27
+ RSpec.describe "example" do
28
+ describe 'odd and even' do
29
+ it 'returns true' do
30
+ expect(2.even?).to be(true)
31
+ end
32
+
33
+ it 'returns false' do
34
+ expect(5.even?).to be(false)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ source "https://rubygems.org"
3
+
4
+ gem "rspec"
5
+ gem 'test_dots', path: '../../'
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: ../..
3
+ specs:
4
+ test_dots (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rspec (3.6.0)
11
+ rspec-core (~> 3.6.0)
12
+ rspec-expectations (~> 3.6.0)
13
+ rspec-mocks (~> 3.6.0)
14
+ rspec-core (3.6.0)
15
+ rspec-support (~> 3.6.0)
16
+ rspec-expectations (3.6.0)
17
+ diff-lcs (>= 1.2.0, < 2.0)
18
+ rspec-support (~> 3.6.0)
19
+ rspec-mocks (3.6.0)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.6.0)
22
+ rspec-support (3.6.0)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ rspec
29
+ test_dots!
30
+
31
+ BUNDLED WITH
32
+ 1.16.0
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rspec'
4
+ require 'test_dots'
5
+
6
+ TestDots.configure do |config|
7
+ config.use_ssl = false
8
+ end
9
+
10
+ TestDots.register_rspec_listener
11
+
12
+ RSpec.describe "example" do
13
+ describe 'odd and even' do
14
+ context 'a group of tests' do
15
+ it 'returns true' do
16
+ expect(2.even?).to be(true)
17
+ end
18
+
19
+ it 'returns false' do
20
+ expect(5.even?).to be(false)
21
+ end
22
+ end
23
+
24
+ context 'a different' do
25
+ it 'returns true' do
26
+ expect(3.odd?).to be(true)
27
+ end
28
+
29
+ it 'returns false' do
30
+ expect(6.odd?).to be(false)
31
+ end
32
+ end
33
+ end
34
+
35
+ it 'is failing' do
36
+ expect(true).to be(false)
37
+ end
38
+
39
+ it 'errors' do
40
+ raise 'hi'
41
+ end
42
+
43
+ it 'is intermittent' do
44
+ random = rand
45
+ expect(random).to be > 0.5
46
+ end
47
+
48
+ it 'it is variably slow' do
49
+ sleep(rand * 2)
50
+ expect(true).to be(true)
51
+ end
52
+
53
+ it 'is slow' do
54
+ sleep(1.5)
55
+ expect(true).to be(true)
56
+ end
57
+ end
@@ -0,0 +1,66 @@
1
+ require 'test_dots'
2
+ require 'pathname'
3
+
4
+ module Minitest
5
+ def self.plugin_test_dots_init(_)
6
+ if TestDots.configuration.collect_test_data?
7
+ self.reporter << TestDotsReporter.new
8
+ end
9
+ end
10
+
11
+ class TestDotsReporter < AbstractReporter
12
+ def initialize
13
+ @dir = Pathname.new(Dir.pwd)
14
+ @results = []
15
+ @start_time = nil
16
+ end
17
+
18
+ def start
19
+ @start_time = Minitest.clock_time
20
+ end
21
+
22
+ def record(result)
23
+ status = if result.passed?
24
+ 'passed'
25
+ elsif result.skipped?
26
+ 'skipped'
27
+ else
28
+ 'failed'
29
+ end
30
+
31
+ @results << {
32
+ description: result.name,
33
+ full_description: "#{result.class}##{result.name}",
34
+ location: location_for_result(result),
35
+ run_time: result.time,
36
+ status: status
37
+ }
38
+ end
39
+
40
+ def report
41
+ run_time = Minitest.clock_time - @start_time
42
+
43
+ TestDots.send_report(
44
+ framework: 'minitest',
45
+ run_time: run_time,
46
+ results: @results
47
+ )
48
+ end
49
+
50
+ private
51
+
52
+ def location_for_result(result)
53
+ file, line = result.method(result.name).source_location
54
+ if file
55
+ [relative_path(file).to_s, line].join(':')
56
+ else
57
+ nil
58
+ end
59
+ end
60
+
61
+ def relative_path(test_path)
62
+ expaned_test_path = File.expand_path(test_path, @dir)
63
+ Pathname.new(expaned_test_path).relative_path_from(@dir)
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,20 @@
1
+ require 'openssl'
2
+
3
+ module TestDots
4
+ class Api
5
+ def post(payload)
6
+ http = Net::HTTP.new(TestDots.configuration.server, TestDots.configuration.port)
7
+ if TestDots.configuration.use_ssl
8
+ http.use_ssl = true
9
+ http.ca_file = TestDots.configuration.cacert_path
10
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
11
+ else
12
+ http.use_ssl = false
13
+ end
14
+ request = Net::HTTP::Post.new(TestDots.configuration.endpoint, 'Content-Type' => 'application/json')
15
+ request.basic_auth(TestDots.configuration.api_key, "")
16
+ request.body = payload
17
+ http.request(request)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ module TestDots
2
+ module CIAdapters
3
+ class Base
4
+ def active?
5
+ true
6
+ end
7
+
8
+ def branch
9
+ '(unknown)'
10
+ end
11
+
12
+ def build
13
+ nil
14
+ end
15
+
16
+ def url
17
+ nil
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module TestDots
2
+ module CIAdapters
3
+ class CircleCI < TestDots::CIAdapters::Base
4
+ def active?
5
+ ENV.has_key?('CIRCLECI')
6
+ end
7
+
8
+ def branch
9
+ ENV['CIRCLE_BRANCH']
10
+ end
11
+
12
+ def build
13
+ ENV['CIRCLE_BUILD_NUM']
14
+ end
15
+
16
+ def url
17
+ ENV['CIRCLE_BUILD_URL']
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module TestDots
2
+ module CIAdapters
3
+ class Jenkins < TestDots::CIAdapters::Base
4
+ def active?
5
+ ENV.has_key?('JENKINS_URL')
6
+ end
7
+
8
+ def branch
9
+ ENV['GIT_BRANCH']
10
+ end
11
+
12
+ def build
13
+ ENV['BUILD_NUMBER']
14
+ end
15
+
16
+ def url
17
+ ENV['BUILD_URL']
18
+ end
19
+ end
20
+ end
21
+ end