testmetrics_rspec 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ca2804b98b037c67b23476d07586b3f8c8e0843ffb8ef8b98fbdc7eced0d956b
4
+ data.tar.gz: d402bac313a1668ee771a38347caf94eaa272e3ad44962fe4aa04835935e5ffa
5
+ SHA512:
6
+ metadata.gz: 88a93ab6b35b8fdcca980850eaf63cd96eb6438fdd7c94ff04e499e67db871b51c78687f0a4b4330007b19223382f3d377e939c09a4fa3bad431809f4558c09a
7
+ data.tar.gz: 49bb0f27a4ff2944199df67b0df5ef7ac818c4d1edb39c4a057bfdb5cd570939ed342d1494dcebc8956380a6a45107d6997c135cade0e5dc6ad16d648bbe2ed4
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in testmetrics_rspec.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ testmetrics_rspec (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.8.0)
12
+ rspec-core (~> 3.8.0)
13
+ rspec-expectations (~> 3.8.0)
14
+ rspec-mocks (~> 3.8.0)
15
+ rspec-core (3.8.0)
16
+ rspec-support (~> 3.8.0)
17
+ rspec-expectations (3.8.2)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.8.0)
20
+ rspec-mocks (3.8.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-support (3.8.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.16)
30
+ rake (~> 10.0)
31
+ rspec (~> 3.0)
32
+ testmetrics_rspec!
33
+
34
+ BUNDLED WITH
35
+ 1.16.5
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Testmetrics
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # testmetrics_rspec
2
+ The official RSpec client for Testmetrics
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 "testmetrics_rspec"
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
data/example/.rspec ADDED
@@ -0,0 +1 @@
1
+ --format TestmetricsRSpec
@@ -0,0 +1,51 @@
1
+ require "spec_helper"
2
+ require_relative "shared_examples"
3
+
4
+ describe "some example specs" do
5
+ it "should succeed" do
6
+ expect(true).to be(true)
7
+ end
8
+
9
+ it "should fail" do
10
+ expect(false).to be(true)
11
+ end
12
+
13
+ it "should raise" do
14
+ raise ArgumentError
15
+ end
16
+
17
+ it "should be pending" do
18
+ if defined? skip
19
+ skip
20
+ else
21
+ pending
22
+ end
23
+ end
24
+
25
+ it "shows diffs cleanly" do
26
+ expect({a: "b", c: "d"}).to eql({a: 2, c: 4})
27
+ end
28
+
29
+ it "replaces naughty \0 and \e characters, \x01 and \uFFFF too" do
30
+ expect("\0\0\0").to eql("emergency services")
31
+ end
32
+
33
+ it "escapes controlling \u{7f} characters" do
34
+ expect("\u{7f}").to eql("pacman om nom nom")
35
+ end
36
+
37
+ it "can include unicodes 😁" do
38
+ expect("🚀").to eql("🔥")
39
+ end
40
+
41
+ it %{escapes <html tags='correctly' and="such &amp; such">} do
42
+ expect("<p>This is important</p>").to eql("<p>This is <strong>very</strong> important</p>")
43
+ end
44
+
45
+ it_should_behave_like "shared examples"
46
+
47
+ it "can capture stdout and stderr" do
48
+ $stdout.puts "Test"
49
+ $stderr.puts "Bar"
50
+ end
51
+ end
@@ -0,0 +1,11 @@
1
+ shared_examples "shared examples" do
2
+ context "in a shared example" do
3
+ it "succeeds" do
4
+ expect(true).to be(true)
5
+ end
6
+
7
+ it "also fails" do
8
+ expect(false).to be(true)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ RSpec.configure do |config|
2
+ # register around filter that captures stderr and stdout
3
+ config.around(:each) do |example|
4
+ $stdout = StringIO.new
5
+ $stderr = StringIO.new
6
+
7
+ example.run
8
+
9
+ example.metadata[:stdout] = $stdout.string
10
+ example.metadata[:stderr] = $stderr.string
11
+
12
+ $stdout = STDOUT
13
+ $stderr = STDERR
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ # This sends the results to the Testmetrics server
2
+ module TestmetricsRspec::Persist
3
+ def self.call(results)
4
+ puts results
5
+ end
6
+ end
@@ -0,0 +1,79 @@
1
+ class TestmetricsRspec < RSpec::Core::Formatters::BaseFormatter
2
+ attr_reader :started
3
+
4
+ def start(example_count)
5
+ @started = Time.now
6
+ super
7
+ end
8
+
9
+ def dump_summary(duration, example_count, failure_count, pending_count)
10
+ super
11
+ end
12
+
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)
50
+ end
51
+
52
+ def failure_for(example)
53
+ exception = exception_for(example)
54
+ message = strip_diff_colors(exception.message)
55
+ backtrace = format_backtrace(exception.backtrace, example)
56
+
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]}"
59
+ end
60
+
61
+ "#{message}\n#{backtrace.join("\n")}"
62
+ end
63
+
64
+ def find_shared_group(example)
65
+ group_and_parent_groups(example).find { |group| group.metadata[:shared_group_name] }
66
+ end
67
+
68
+ def group_and_parent_groups(example)
69
+ example.example_group.parent_groups + [example.example_group]
70
+ end
71
+
72
+ def stdout_for(example)
73
+ example.metadata[:stdout]
74
+ end
75
+
76
+ def stderr_for(example)
77
+ example.metadata[:stderr]
78
+ end
79
+ end
@@ -0,0 +1,66 @@
1
+ # Doc
2
+ class TestmetricsRspec < RSpec::Core::Formatters::BaseFormatter
3
+ RSpec::Core::Formatters.register self, :start, :stop, :dump_summary
4
+
5
+ # This sends the "start" message to testmetrics
6
+ def start(notification)
7
+ TestmetricsRspec::Persist.call({})
8
+ super
9
+ end
10
+
11
+ def stop(notification)
12
+ tests = notification.notifications.map do |test|
13
+ {
14
+ name: test.example.full_description,
15
+ total_run_time: test.example.execution_result.run_time,
16
+ state: test.example.execution_result.status
17
+ }
18
+ end
19
+
20
+ @results = {
21
+ total_run_time: nil,
22
+ key: ENV['TESTMETRICS_PROJECT_KEY'],
23
+ branch: git_branch,
24
+ sha: git_sha,
25
+ metadata: {
26
+ ruby_version: RUBY_VERSION,
27
+ ci_platform: ci_platform
28
+ },
29
+ tests: tests
30
+ }
31
+ end
32
+
33
+ # This sends the "end" message to testmetrics
34
+ def dump_summary(notification)
35
+ @results[:total_run_time] = notification.duration
36
+ TestmetricsRspec::Persist.call(@results)
37
+ end
38
+
39
+ BRANCH_VARS = ["TRAVIS_BRANCH", "CIRCLE_BRANCH", "CI_COMMIT_REF_NAME", "BRANCH_NAME"]
40
+ def git_branch
41
+ correct_var = BRANCH_VARS.find do |var| ENV[var] != nil end
42
+ correct_var.nil? ? nil : ENV[correct_var]
43
+ end
44
+
45
+ SHA_VARS = ["TRAVIS_COMMIT", "CIRCLE_SHA1", "CI_COMMIT_SHA", "REVISION"]
46
+ def git_sha
47
+ correct_var = SHA_VARS.find do |var| ENV[var] != nil end
48
+ correct_var.nil? ? nil : ENV[correct_var]
49
+ end
50
+
51
+ def ci_platform
52
+ correct_var = SHA_VARS.find do |var| ENV[var] != nil end
53
+ case correct_var
54
+ when "TRAVIS_COMMIT"
55
+ "Travis CI"
56
+ when "CIRCLE_SHA1"
57
+ "Circle CI"
58
+ when "CI_COMMIT_SHA"
59
+ "Gitlab CI"
60
+ when "REVISION"
61
+ "Semaphore CI"
62
+ else
63
+ "Unknown"
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,2 @@
1
+ VERSION =
2
+ end
@@ -0,0 +1,10 @@
1
+ require 'rspec/core'
2
+ require 'rspec/core/formatters/base_formatter'
3
+
4
+ if Gem::Version.new(RSpec::Core::Version::STRING) >= Gem::Version.new('3')
5
+ require 'testmetrics_rspec/rspec3'
6
+ else
7
+ require 'testmetrics_rspec/rspec2'
8
+ end
9
+
10
+ require 'testmetrics_rspec/persist'
@@ -0,0 +1,26 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "testmetrics_rspec"
7
+ spec.version = "0.1.0"
8
+ spec.authors = ["Devon Estes"]
9
+ spec.email = ["devon.c.estes@gmail.com"]
10
+
11
+ spec.summary = %q{The official RSpec client for Testmetrics}
12
+ spec.homepage = "https://testmetrics.app"
13
+
14
+ # Specify which files should be added to the gem when it is released.
15
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.16"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: testmetrics_rspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Devon Estes
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - devon.c.estes@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - example/.rspec
71
+ - example/spec/example_spec.rb
72
+ - example/spec/shared_examples.rb
73
+ - example/spec/spec_helper.rb
74
+ - lib/testmetrics_rspec.rb
75
+ - lib/testmetrics_rspec/persist.rb
76
+ - lib/testmetrics_rspec/rspec2.rb
77
+ - lib/testmetrics_rspec/rspec3.rb
78
+ - lib/testmetrics_rspec/version.rb
79
+ - testmetrics_rspec.gemspec
80
+ homepage: https://testmetrics.app
81
+ licenses: []
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.7.6
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: The official RSpec client for Testmetrics
103
+ test_files: []