codeclimate-test-reporter 0.4.7 → 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -1
- data/bin/cc-tddium-post-worker +0 -1
- data/lib/code_climate/test_reporter.rb +2 -2
- data/lib/code_climate/test_reporter/ci.rb +9 -0
- data/lib/code_climate/test_reporter/client.rb +3 -0
- data/lib/code_climate/test_reporter/formatter.rb +14 -9
- data/lib/code_climate/test_reporter/version.rb +1 -1
- metadata +5 -33
- data/.gitignore +0 -18
- data/.rspec +0 -2
- data/.travis.yml +0 -8
- data/Gemfile +0 -12
- data/Rakefile +0 -6
- data/codeclimate-test-reporter.gemspec +0 -29
- data/spec/fixtures/encoding_test.rb +0 -6
- data/spec/fixtures/encoding_test_iso.rb +0 -6
- data/spec/lib/calculate_blob_spec.rb +0 -27
- data/spec/lib/ci_spec.rb +0 -26
- data/spec/lib/client_spec.rb +0 -24
- data/spec/lib/configuration_spec.rb +0 -75
- data/spec/lib/formatter_spec.rb +0 -141
- data/spec/lib/git_spec.rb +0 -83
- data/spec/lib/payload_validator_spec.rb +0 -89
- data/spec/lib/test_reporter_spec.rb +0 -36
- data/spec/spec_helper.rb +0 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff53f8b5912319ff45fbc1f985198ebb45618a58
|
4
|
+
data.tar.gz: 17de77b7e0fb71b1649899c10c4b17575d73da68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fd772d49b8fd66c7852b1db96cedcec310236b99637eded4408f125a57913d9ee6b2c7ba5425a156bc001057ec722f081999f722d871edc84aa18902f1abeb1
|
7
|
+
data.tar.gz: fd004e622891172ecc0d015ce417456d4325fa45eb9142e398c4871bc24069cfa8d56ac3c80b5789d4d2ba7b06f77bab21323dbea26344470cd46eb6333f3521
|
data/README.md
CHANGED
@@ -7,6 +7,18 @@ Climate's hosted, automated code review service. Based on SimpleCov.
|
|
7
7
|
|
8
8
|
Code Climate - [https://codeclimate.com](https://codeclimate.com)
|
9
9
|
|
10
|
+
# Important FYIs
|
11
|
+
|
12
|
+
Across the many different testing frameworks, setups, and environments, there are lots of variables at play. Before setting up test coverage, it's important to understand what we do and do not currently support:
|
13
|
+
|
14
|
+
* **Default branch only:** We only support test coverage for your [default branch](http://docs.codeclimate.com/article/151-glossary-default-branch). Be sure to check out this branch before running your tests.
|
15
|
+
* **Single payload:** We currently only support a single test coverage payload per commit. If you run your tests in multiple steps, or via parallel tests, Code Climate will only process the first payload that we receive. If you are using a CI, be sure to check if you are running your tests in a parallel mode.
|
16
|
+
|
17
|
+
**Note:** There is one exception to this rule. We've specifically built an integration with [Solano Labs](https://www.solanolabs.com/) to support parallel tests.
|
18
|
+
|
19
|
+
**Note:** If you've configured Code Climate to analyze multiple languages in the same repository (e.g., Ruby and JavaScript), we can nonetheless only process test coverage information for one of these languages. We'll process the first payload that we receive.
|
20
|
+
* **Invalid File Paths:** By default, our test reporters expect your application to exist at the root of your repository. If this is not the case, the file paths in your test coverage payload will not match the file paths that Code Climate expects. For our Ruby test reporter, [we have a work-around to this issue](http://docs.codeclimate.com/article/220-help-im-having-trouble-with-test-coverage#ruby_sub_folder).
|
21
|
+
|
10
22
|
## Installation
|
11
23
|
|
12
24
|
This gem requires a user, but not necessarily a paid account, on Code Climate, so if you don't have one the
|
@@ -57,6 +69,10 @@ end
|
|
57
69
|
CodeClimate::TestReporter.start
|
58
70
|
```
|
59
71
|
|
72
|
+
## Troubleshooting
|
73
|
+
|
74
|
+
If you're having trouble setting up or working with our test coverage feature, [see our detailed help doc](http://docs.codeclimate.com/article/220-help-im-having-trouble-with-test-coverage), which covers the most common issues encountered.
|
75
|
+
|
60
76
|
## Extending Simplecov with other formatters
|
61
77
|
|
62
78
|
Since ruby-test-reporter 0.4.0 you can use `CodeClimate::TestReporter::Formatter` as a Simplecov formatter directly. Just add the formatter to your Simplecov formatter in addition to the rest of your configuration:
|
@@ -76,7 +92,7 @@ end
|
|
76
92
|
|
77
93
|
Note: This may work with other parallel test runners as long as they run on the same machine.
|
78
94
|
|
79
|
-
Be sure you're using `simplecov` `>= 0.9.0`.
|
95
|
+
Be sure you're using `simplecov` `>= 0.9.0`.
|
80
96
|
|
81
97
|
Add the following to your `test_helper.rb`/`spec_helper.rb` instead of what is normally required.
|
82
98
|
|
@@ -96,6 +112,12 @@ require 'codeclimate-test-reporter'
|
|
96
112
|
CodeClimate::TestReporter::Formatter.new.format(SimpleCov.result)
|
97
113
|
```
|
98
114
|
|
115
|
+
## Using with multiple machines
|
116
|
+
|
117
|
+
For the time-being, we don't officially support coverage data from parallel test runs. That said, [codeclimate batch](https://github.com/grosser/codeclimate_batch) is a handy work-around that was created by one of our customers.
|
118
|
+
|
119
|
+
Note that this solution requires standing up a separate server (like a Heroku instance) that sits between your testing environment and Code Climate. Though this option is not formally supported, if you have an immediate need for parallel testing support, [codeclimate batch](https://github.com/grosser/codeclimate_batch) is a helpful interim solution until we can release our official support for this.
|
120
|
+
|
99
121
|
## Help! Your gem is raising a ...
|
100
122
|
|
101
123
|
### VCR::Errors::UnhandledHTTPRequestError
|
data/bin/cc-tddium-post-worker
CHANGED
@@ -20,8 +20,8 @@ module CodeClimate
|
|
20
20
|
return @environment_variable_set if defined?(@environment_variable_set)
|
21
21
|
|
22
22
|
@environment_variable_set = !!ENV["CODECLIMATE_REPO_TOKEN"]
|
23
|
-
|
24
|
-
logger.info("
|
23
|
+
if @environment_variable_set
|
24
|
+
logger.info("Reporting coverage data to Code Climate.")
|
25
25
|
end
|
26
26
|
|
27
27
|
@environment_variable_set
|
@@ -71,6 +71,15 @@ module CodeClimate
|
|
71
71
|
branch: env['CI_BRANCH'],
|
72
72
|
commit_sha: env['CI_COMMIT_ID'],
|
73
73
|
}
|
74
|
+
elsif env['CI_NAME'] =~ /VEXOR/i
|
75
|
+
{
|
76
|
+
name: 'vexor',
|
77
|
+
build_identifier: env['CI_BUILD_NUMBER'],
|
78
|
+
build_url: env['CI_BUILD_URL'],
|
79
|
+
branch: env['CI_BRANCH'],
|
80
|
+
commit_sha: env['CI_BUILD_SHA'],
|
81
|
+
pull_request: env['CI_PULL_REQUEST_ID']
|
82
|
+
}
|
74
83
|
elsif env['BUILDBOX']
|
75
84
|
{
|
76
85
|
name: "buildbox",
|
@@ -15,6 +15,9 @@ module CodeClimate
|
|
15
15
|
"https://codeclimate.com"
|
16
16
|
end
|
17
17
|
|
18
|
+
# N.B. Not a generalized solution for posting multiple results
|
19
|
+
# N.B. Only works with in tandem with additional communication from
|
20
|
+
# Solano.
|
18
21
|
def batch_post_results(files)
|
19
22
|
uri = URI.parse("#{host}/test_reports/batch")
|
20
23
|
http = http_client(uri)
|
@@ -19,7 +19,7 @@ module CodeClimate
|
|
19
19
|
|
20
20
|
payload = to_payload(result)
|
21
21
|
PayloadValidator.validate(payload)
|
22
|
-
if
|
22
|
+
if write_to_file?
|
23
23
|
file_path = File.join(Dir.tmpdir, "codeclimate-test-coverage-#{SecureRandom.uuid}.json")
|
24
24
|
print "Coverage results saved to #{file_path}... "
|
25
25
|
File.open(file_path, "w") { |file| file.write(payload.to_json) }
|
@@ -36,6 +36,15 @@ module CodeClimate
|
|
36
36
|
false
|
37
37
|
end
|
38
38
|
|
39
|
+
# actually private ...
|
40
|
+
def short_filename(filename)
|
41
|
+
return filename unless ::SimpleCov.root
|
42
|
+
filename = filename.gsub(::SimpleCov.root, '.').gsub(/^\.\//, '')
|
43
|
+
apply_prefix filename
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
39
48
|
def partial?
|
40
49
|
tddium?
|
41
50
|
end
|
@@ -81,13 +90,6 @@ module CodeClimate
|
|
81
90
|
}
|
82
91
|
end
|
83
92
|
|
84
|
-
|
85
|
-
def short_filename(filename)
|
86
|
-
return filename unless ::SimpleCov.root
|
87
|
-
filename = filename.gsub(::SimpleCov.root, '.').gsub(/^\.\//, '')
|
88
|
-
apply_prefix filename
|
89
|
-
end
|
90
|
-
|
91
93
|
def tddium?
|
92
94
|
ci_service_data && ci_service_data[:name] == "tddium"
|
93
95
|
end
|
@@ -98,7 +100,10 @@ module CodeClimate
|
|
98
100
|
Float(numeric).round(precision)
|
99
101
|
end
|
100
102
|
|
101
|
-
|
103
|
+
def write_to_file?
|
104
|
+
warn "TO_FILE is deprecated, use CODECLIMATE_TO_FILE" if ENV["TO_FILE"]
|
105
|
+
tddium? || ENV["CODECLIMATE_TO_FILE"] || ENV["TO_FILE"]
|
106
|
+
end
|
102
107
|
|
103
108
|
def apply_prefix filename
|
104
109
|
prefix = CodeClimate::TestReporter.configuration.path_prefix
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codeclimate-test-reporter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Helmkamp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02
|
11
|
+
date: 2015-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simplecov
|
@@ -73,7 +73,7 @@ dependencies:
|
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
76
|
+
name: webmock
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
79
|
- - ">="
|
@@ -109,15 +109,9 @@ executables:
|
|
109
109
|
extensions: []
|
110
110
|
extra_rdoc_files: []
|
111
111
|
files:
|
112
|
-
- ".gitignore"
|
113
|
-
- ".rspec"
|
114
|
-
- ".travis.yml"
|
115
|
-
- Gemfile
|
116
112
|
- LICENSE.txt
|
117
113
|
- README.md
|
118
|
-
- Rakefile
|
119
114
|
- bin/cc-tddium-post-worker
|
120
|
-
- codeclimate-test-reporter.gemspec
|
121
115
|
- config/cacert.pem
|
122
116
|
- lib/code_climate/test_reporter.rb
|
123
117
|
- lib/code_climate/test_reporter/calculate_blob.rb
|
@@ -130,18 +124,7 @@ files:
|
|
130
124
|
- lib/code_climate/test_reporter/payload_validator.rb
|
131
125
|
- lib/code_climate/test_reporter/version.rb
|
132
126
|
- lib/codeclimate-test-reporter.rb
|
133
|
-
|
134
|
-
- spec/fixtures/encoding_test_iso.rb
|
135
|
-
- spec/lib/calculate_blob_spec.rb
|
136
|
-
- spec/lib/ci_spec.rb
|
137
|
-
- spec/lib/client_spec.rb
|
138
|
-
- spec/lib/configuration_spec.rb
|
139
|
-
- spec/lib/formatter_spec.rb
|
140
|
-
- spec/lib/git_spec.rb
|
141
|
-
- spec/lib/payload_validator_spec.rb
|
142
|
-
- spec/lib/test_reporter_spec.rb
|
143
|
-
- spec/spec_helper.rb
|
144
|
-
homepage: ''
|
127
|
+
homepage: https://github.com/codeclimate/ruby-test-reporter
|
145
128
|
licenses:
|
146
129
|
- MIT
|
147
130
|
metadata: {}
|
@@ -165,15 +148,4 @@ rubygems_version: 2.2.2
|
|
165
148
|
signing_key:
|
166
149
|
specification_version: 4
|
167
150
|
summary: Uploads Ruby test coverage data to Code Climate.
|
168
|
-
test_files:
|
169
|
-
- spec/fixtures/encoding_test.rb
|
170
|
-
- spec/fixtures/encoding_test_iso.rb
|
171
|
-
- spec/lib/calculate_blob_spec.rb
|
172
|
-
- spec/lib/ci_spec.rb
|
173
|
-
- spec/lib/client_spec.rb
|
174
|
-
- spec/lib/configuration_spec.rb
|
175
|
-
- spec/lib/formatter_spec.rb
|
176
|
-
- spec/lib/git_spec.rb
|
177
|
-
- spec/lib/payload_validator_spec.rb
|
178
|
-
- spec/lib/test_reporter_spec.rb
|
179
|
-
- spec/spec_helper.rb
|
151
|
+
test_files: []
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in codeclimate-test-reporter.gemspec
|
4
|
-
gemspec
|
5
|
-
|
6
|
-
platform :ruby_19 do
|
7
|
-
gem "pry-debugger", group: :development
|
8
|
-
end
|
9
|
-
|
10
|
-
platform :ruby_21 do
|
11
|
-
gem "pry-byebug", group: :development
|
12
|
-
end
|
data/Rakefile
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "code_climate/test_reporter/version"
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "codeclimate-test-reporter"
|
8
|
-
spec.version = CodeClimate::TestReporter::VERSION
|
9
|
-
spec.authors = ["Bryan Helmkamp"]
|
10
|
-
spec.email = ["bryan@brynary.com"]
|
11
|
-
spec.description = %q{Collects test coverage data from your Ruby test suite and sends it to Code Climate's hosted, automated code review service. Based on SimpleCov.}
|
12
|
-
spec.summary = %q{Uploads Ruby test coverage data to Code Climate.}
|
13
|
-
spec.homepage = ""
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files`.split($/)
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.required_ruby_version = ">= 1.9"
|
22
|
-
|
23
|
-
spec.add_dependency "simplecov", ">= 0.7.1", "< 1.0.0"
|
24
|
-
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
-
spec.add_development_dependency "rake"
|
26
|
-
spec.add_development_dependency "rspec"
|
27
|
-
spec.add_development_dependency "artifice"
|
28
|
-
spec.add_development_dependency "pry"
|
29
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module CodeClimate::TestReporter
|
4
|
-
|
5
|
-
describe CalculateBlob do
|
6
|
-
|
7
|
-
subject { CalculateBlob.new(fixture) }
|
8
|
-
let(:fixture) { File.expand_path("../../fixtures/encoding_test.rb", __FILE__) }
|
9
|
-
|
10
|
-
it 'hex digests content of file' do
|
11
|
-
expect(subject.blob_id).to_not be_nil
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'encoding error' do
|
15
|
-
|
16
|
-
let(:fixture) { File.expand_path("../../fixtures/encoding_test_iso.rb", __FILE__) }
|
17
|
-
|
18
|
-
it 'falls back to git' do
|
19
|
-
expect(File).to receive(:open).and_raise(EncodingError)
|
20
|
-
expect(subject.blob_id).to eq('eb82c22dadb9c47a7fed87211623f6856e112f46')
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
data/spec/lib/ci_spec.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module CodeClimate::TestReporter
|
4
|
-
describe Ci do
|
5
|
-
|
6
|
-
describe '.service_data' do
|
7
|
-
before :each do
|
8
|
-
@env = {
|
9
|
-
'SEMAPHORE' => 'yes?',
|
10
|
-
'BRANCH_NAME' => 'master',
|
11
|
-
'SEMAPHORE_BUILD_NUMBER' => '1234'
|
12
|
-
}
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'returns a hash of CI environment info' do
|
16
|
-
expected_semaphore_hash = {
|
17
|
-
name: 'semaphore',
|
18
|
-
branch: 'master',
|
19
|
-
build_identifier: '1234'
|
20
|
-
}
|
21
|
-
|
22
|
-
expect(Ci.service_data(@env)).to include expected_semaphore_hash
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
data/spec/lib/client_spec.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module CodeClimate::TestReporter
|
4
|
-
describe Client do
|
5
|
-
it 'sets the http timeout per configuration' do
|
6
|
-
new_timeout = 969
|
7
|
-
CodeClimate::TestReporter.configure do |config|
|
8
|
-
config.timeout = new_timeout
|
9
|
-
end
|
10
|
-
|
11
|
-
response = double(:response, code: 200)
|
12
|
-
net_http = double(:net_http, request: response)
|
13
|
-
allow(Net::HTTP).to receive(:new).
|
14
|
-
and_return(net_http)
|
15
|
-
|
16
|
-
expect(net_http).to receive(:open_timeout=).
|
17
|
-
with(new_timeout)
|
18
|
-
expect(net_http).to receive(:read_timeout=).
|
19
|
-
with(new_timeout)
|
20
|
-
|
21
|
-
Client.new.post_results("")
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'logger'
|
3
|
-
|
4
|
-
module CodeClimate::TestReporter
|
5
|
-
describe Configuration do
|
6
|
-
describe 'none given' do
|
7
|
-
before do
|
8
|
-
CodeClimate::TestReporter.configure
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'provides defaults' do
|
12
|
-
expect(CodeClimate::TestReporter.configuration.branch).to be_nil
|
13
|
-
expect(CodeClimate::TestReporter.configuration.logger).to be_instance_of Logger
|
14
|
-
expect(CodeClimate::TestReporter.configuration.logger.level).to eq Logger::INFO
|
15
|
-
expect(CodeClimate::TestReporter.configuration.profile).to eq('test_frameworks')
|
16
|
-
expect(CodeClimate::TestReporter.configuration.path_prefix).to be_nil
|
17
|
-
expect(CodeClimate::TestReporter.configuration.skip_token).to eq('nocov')
|
18
|
-
expect(CodeClimate::TestReporter.configuration.timeout).to eq(Client::DEFAULT_TIMEOUT)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe 'with config block' do
|
23
|
-
after do
|
24
|
-
CodeClimate::TestReporter.configure
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'stores logger' do
|
28
|
-
logger = Logger.new($stderr)
|
29
|
-
|
30
|
-
CodeClimate::TestReporter.configure do |config|
|
31
|
-
logger.level = Logger::DEBUG
|
32
|
-
config.logger = logger
|
33
|
-
end
|
34
|
-
|
35
|
-
expect(CodeClimate::TestReporter.configuration.logger).to eq logger
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'stores branch' do
|
39
|
-
CodeClimate::TestReporter.configure do |config|
|
40
|
-
config.branch = :master
|
41
|
-
end
|
42
|
-
|
43
|
-
expect(CodeClimate::TestReporter.configuration.branch).to eq :master
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'stores profile' do
|
47
|
-
CodeClimate::TestReporter.configure do |config|
|
48
|
-
config.profile = 'custom'
|
49
|
-
end
|
50
|
-
|
51
|
-
expect(CodeClimate::TestReporter.configuration.profile).to eq('custom')
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'stores path prefix' do
|
55
|
-
CodeClimate::TestReporter.configure do |config|
|
56
|
-
config.path_prefix = 'custom'
|
57
|
-
end
|
58
|
-
|
59
|
-
expect(CodeClimate::TestReporter.configuration.path_prefix).to eq('custom')
|
60
|
-
|
61
|
-
CodeClimate::TestReporter.configure do |config|
|
62
|
-
config.path_prefix = nil
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'stores timeout' do
|
67
|
-
CodeClimate::TestReporter.configure do |config|
|
68
|
-
config.timeout = 666
|
69
|
-
end
|
70
|
-
|
71
|
-
expect(CodeClimate::TestReporter.configuration.timeout).to eq(666)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
data/spec/lib/formatter_spec.rb
DELETED
@@ -1,141 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
module CodeClimate::TestReporter
|
5
|
-
describe Formatter do
|
6
|
-
let(:project_path) { "spec/tmp" }
|
7
|
-
let(:project_file) { "fake_project.rb" }
|
8
|
-
let(:formatter) { Formatter.new }
|
9
|
-
let(:source_files) {
|
10
|
-
double(
|
11
|
-
:covered_percent => 24.3,
|
12
|
-
:covered_strength => 33.2,
|
13
|
-
)
|
14
|
-
}
|
15
|
-
let(:files) {
|
16
|
-
[
|
17
|
-
double(
|
18
|
-
:lines => [double, double, double],
|
19
|
-
:covered_lines => [double, double],
|
20
|
-
:missed_lines => [double],
|
21
|
-
:filename => project_file,
|
22
|
-
:coverage => [0,3,2,nil],
|
23
|
-
:covered_percent => 33.2,
|
24
|
-
:covered_strength => 2
|
25
|
-
)
|
26
|
-
]
|
27
|
-
}
|
28
|
-
|
29
|
-
let(:simplecov_result) {
|
30
|
-
double(
|
31
|
-
:covered_percent => 24.3,
|
32
|
-
:covered_strength => 33.2,
|
33
|
-
:files => files,
|
34
|
-
:source_files => source_files,
|
35
|
-
:created_at => Time.at(1379704336),
|
36
|
-
:command_name => "rspec"
|
37
|
-
)
|
38
|
-
}
|
39
|
-
|
40
|
-
let(:expected_request) {
|
41
|
-
{
|
42
|
-
"repo_token" => "172754c1bf9a3c698f7770b9fb648f1ebb214425120022d0b2ffc65b97dff531",
|
43
|
-
"source_files" =>
|
44
|
-
[
|
45
|
-
{
|
46
|
-
"name" => project_file,
|
47
|
-
"blob_id" => "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
|
48
|
-
"coverage" => "[0,3,2,null]",
|
49
|
-
"covered_percent" => 33.2,
|
50
|
-
"covered_strength" => 2.0,
|
51
|
-
"line_counts" => {"total"=>3, "covered"=>2, "missed"=>1}
|
52
|
-
}
|
53
|
-
],
|
54
|
-
"run_at" => 1379704336,
|
55
|
-
"covered_percent" => 24.3,
|
56
|
-
"covered_strength" => 33.2,
|
57
|
-
"line_counts" => {"total" => 3, "covered" => 2, "missed" => 1 },
|
58
|
-
"partial"=> false,
|
59
|
-
"git" =>
|
60
|
-
{
|
61
|
-
"head" => @commit_sha,
|
62
|
-
"committed_at" => @committed_at.to_i,
|
63
|
-
"branch" => "master"
|
64
|
-
},
|
65
|
-
"environment" =>
|
66
|
-
{
|
67
|
-
"test_framework" => "rspec",
|
68
|
-
"pwd" => Dir.pwd,
|
69
|
-
"rails_root" => nil,
|
70
|
-
"simplecov_root" => Dir.pwd,
|
71
|
-
"gem_version" => VERSION
|
72
|
-
},
|
73
|
-
}
|
74
|
-
}
|
75
|
-
|
76
|
-
before do
|
77
|
-
@old_pwd = Dir.pwd
|
78
|
-
FileUtils.mkdir_p(project_path)
|
79
|
-
FileUtils.cd(project_path)
|
80
|
-
FileUtils.touch(project_file)
|
81
|
-
SimpleCov.root(Dir.pwd)
|
82
|
-
system("git init")
|
83
|
-
system("git add #{project_file}")
|
84
|
-
system("git commit -m 'initial commit'")
|
85
|
-
@commit_sha = `git log -1 --pretty=format:'%H'`
|
86
|
-
@committed_at = `git log -1 --pretty=format:'%ct'`
|
87
|
-
end
|
88
|
-
|
89
|
-
after do
|
90
|
-
FileUtils.cd(@old_pwd)
|
91
|
-
FileUtils.rm_rf(project_path)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "sends an http request with all the coverage information" do
|
95
|
-
allow(CodeClimate::TestReporter).to receive(:run?).and_return(true)
|
96
|
-
|
97
|
-
app = FakeCodeClimateEndpoint.new
|
98
|
-
Artifice.activate_with(app) do
|
99
|
-
formatter.format(simplecov_result)
|
100
|
-
end
|
101
|
-
|
102
|
-
expect(app.path_info).to eq("/test_reports")
|
103
|
-
expect(app.content_type).to eq("application/json")
|
104
|
-
expect(app.http_content_encoding).to eq("gzip")
|
105
|
-
|
106
|
-
uncompressed = inflate(app.request_body)
|
107
|
-
|
108
|
-
expected_request.merge!("ci_service" => Ci.service_data)
|
109
|
-
expected_json = JSON.parse(expected_request.to_json, symbolize_names: true)
|
110
|
-
|
111
|
-
expect(JSON.parse(uncompressed, symbolize_names: true)).to eq(expected_json)
|
112
|
-
expect(app.http_user_agent).to include("v#{CodeClimate::TestReporter::VERSION}")
|
113
|
-
end
|
114
|
-
|
115
|
-
describe '#short_filename' do
|
116
|
-
it 'should return the filename of the file relative to the SimpleCov root' do
|
117
|
-
expect(formatter.short_filename('file1')).to eq('file1')
|
118
|
-
expect(formatter.short_filename("#{::SimpleCov.root}/file1")).to eq('file1')
|
119
|
-
end
|
120
|
-
|
121
|
-
context "with path prefix" do
|
122
|
-
before do
|
123
|
-
CodeClimate::TestReporter.configure do |config|
|
124
|
-
config.path_prefix = 'custom'
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
after do
|
129
|
-
CodeClimate::TestReporter.configure do |config|
|
130
|
-
config.path_prefix = nil
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'should include the path prefix if set' do
|
135
|
-
expect(formatter.short_filename('file1')).to eq('custom/file1')
|
136
|
-
expect(formatter.short_filename("#{::SimpleCov.root}/file1")).to eq('custom/file1')
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
data/spec/lib/git_spec.rb
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module CodeClimate::TestReporter
|
4
|
-
describe Git do
|
5
|
-
describe '.info' do
|
6
|
-
it 'returns a hash with git information.' do
|
7
|
-
expected_git_hash = {
|
8
|
-
head: `git log -1 --pretty=format:'%H'`,
|
9
|
-
committed_at: `git log -1 --pretty=format:%ct`.to_i,
|
10
|
-
branch: Git.send(:branch_from_git)
|
11
|
-
}
|
12
|
-
|
13
|
-
expect(Git.info).to include expected_git_hash
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe 'git' do
|
18
|
-
it 'should quote the git repository directory' do
|
19
|
-
path = '/path/to/foo bar'
|
20
|
-
|
21
|
-
allow(CodeClimate::TestReporter.configuration).to receive(:git_dir).and_return path
|
22
|
-
expect(Git).to receive(:`).once.with "git --git-dir=\"#{path}/.git\" help"
|
23
|
-
|
24
|
-
Git.send :git, 'help'
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'ensure logic that replies on Rails is robust in non-rails environments' do
|
28
|
-
before :all do
|
29
|
-
module ::Rails; end
|
30
|
-
end
|
31
|
-
|
32
|
-
after :all do
|
33
|
-
Object.send(:remove_const, :Rails)
|
34
|
-
end
|
35
|
-
|
36
|
-
after :each do
|
37
|
-
Git.send :git, 'help'
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'will check if constant Rails is defined' do
|
41
|
-
expect(Git).to receive(:configured_git_dir).once.and_return(nil)
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'will not call method "root" (a 3rd time) if constant Rails is defined but does not respond to root' do
|
45
|
-
expect(Git).to receive(:configured_git_dir).once.and_return(nil)
|
46
|
-
expect(Rails).to receive(:root).twice.and_return('/path')
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'will call rails root if constant Rails is defined and root method is defined' do
|
50
|
-
module ::Rails
|
51
|
-
def self.root
|
52
|
-
'/path'
|
53
|
-
end
|
54
|
-
end
|
55
|
-
expect(Git).to receive(:configured_git_dir).once.and_return(nil)
|
56
|
-
expect(Rails).to receive(:root).twice.and_return('/path')
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe 'branch_from_git_or_ci' do
|
62
|
-
it 'returns the branch from ci' do
|
63
|
-
allow(Ci).to receive(:service_data).and_return({branch: 'ci-branch'})
|
64
|
-
|
65
|
-
expect(Git.branch_from_git_or_ci).to eq 'ci-branch'
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'returns the branch from git if there is no ci branch' do
|
69
|
-
allow(Ci).to receive(:service_data).and_return({})
|
70
|
-
|
71
|
-
expect(Git.branch_from_git_or_ci).to eq Git.clean_git_branch
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'returns master otherwise' do
|
75
|
-
allow(Ci).to receive(:service_data).and_return({})
|
76
|
-
allow(Git).to receive(:branch_from_git).and_return(nil)
|
77
|
-
|
78
|
-
expect(Git.branch_from_git_or_ci).to eq 'master'
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
end
|
@@ -1,89 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module CodeClimate::TestReporter
|
4
|
-
describe PayloadValidator do
|
5
|
-
let(:payload) {
|
6
|
-
{
|
7
|
-
git: {
|
8
|
-
committed_at: 1389603672,
|
9
|
-
head: "4b968f076d169c3d98089fba27988f0d52ba803d"
|
10
|
-
},
|
11
|
-
run_at: 1379704336,
|
12
|
-
source_files: [
|
13
|
-
{ coverage: "[0,3,4]", name: "user.rb" }
|
14
|
-
]
|
15
|
-
}
|
16
|
-
}
|
17
|
-
|
18
|
-
it "does not raise if there's a minimally valid test report payload" do
|
19
|
-
expect {
|
20
|
-
PayloadValidator.validate(payload)
|
21
|
-
}.to_not raise_error
|
22
|
-
end
|
23
|
-
|
24
|
-
it "raises when there's no commit sha" do
|
25
|
-
payload[:git][:head] = nil
|
26
|
-
expect {
|
27
|
-
PayloadValidator.validate(payload)
|
28
|
-
}.to raise_error(InvalidPayload, /A git commit sha was not found/)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "does not raise if there's a commit sha in ci_service data" do
|
32
|
-
payload[:git][:head] = nil
|
33
|
-
payload[:ci_service] = {}
|
34
|
-
payload[:ci_service][:commit_sha] = "4b968f076d169c3d98089fba27988f0d52ba803d"
|
35
|
-
expect {
|
36
|
-
PayloadValidator.validate(payload)
|
37
|
-
}.to_not raise_error
|
38
|
-
end
|
39
|
-
|
40
|
-
it "raises when there is no committed_at" do
|
41
|
-
payload[:git][:committed_at] = nil
|
42
|
-
expect {
|
43
|
-
PayloadValidator.validate(payload)
|
44
|
-
}.to raise_error(InvalidPayload, /A git commit timestamp was not found/)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "raises when there's no run_at" do
|
48
|
-
payload[:run_at] = nil
|
49
|
-
expect {
|
50
|
-
PayloadValidator.validate(payload)
|
51
|
-
}.to raise_error(InvalidPayload, /A run at timestamp was not found/)
|
52
|
-
end
|
53
|
-
|
54
|
-
it "raises when no source_files parameter is passed" do
|
55
|
-
payload[:source_files] = nil
|
56
|
-
expect {
|
57
|
-
PayloadValidator.validate(payload)
|
58
|
-
}.to raise_error(InvalidPayload, /No source files were found/)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "raises when there's no source files" do
|
62
|
-
payload[:source_files] = []
|
63
|
-
expect {
|
64
|
-
PayloadValidator.validate(payload)
|
65
|
-
}.to raise_error(InvalidPayload, /No source files were found/)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "raises if source files aren't hashes" do
|
69
|
-
payload[:source_files] = [1,2,3]
|
70
|
-
expect {
|
71
|
-
PayloadValidator.validate(payload)
|
72
|
-
}.to raise_error(InvalidPayload, /Invalid source files/)
|
73
|
-
end
|
74
|
-
|
75
|
-
it "raises if source files don't have names" do
|
76
|
-
payload[:source_files] = [{ coverage: "[1,1]" }]
|
77
|
-
expect {
|
78
|
-
PayloadValidator.validate(payload)
|
79
|
-
}.to raise_error(InvalidPayload, /Invalid source files/)
|
80
|
-
end
|
81
|
-
|
82
|
-
it "raises if source files don't have coverage" do
|
83
|
-
payload[:source_files] = [{ name: "foo.rb" }]
|
84
|
-
expect {
|
85
|
-
PayloadValidator.validate(payload)
|
86
|
-
}.to raise_error(InvalidPayload, /Invalid source files/)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe CodeClimate::TestReporter do
|
4
|
-
let(:reporter) { CodeClimate::TestReporter.dup }
|
5
|
-
|
6
|
-
describe '.run_on_current_branch?' do
|
7
|
-
it 'returns true if there is no branch configured' do
|
8
|
-
allow(reporter).to receive(:configured_branch).and_return(nil)
|
9
|
-
expect(reporter).to be_run_on_current_branch
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'returns true if the current branch matches the configured branch' do
|
13
|
-
allow(reporter).to receive(:current_branch).and_return("master\n")
|
14
|
-
allow(reporter).to receive(:configured_branch).and_return(:master)
|
15
|
-
|
16
|
-
expect(reporter).to be_run_on_current_branch
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'returns false if the current branch and configured branch dont match' do
|
20
|
-
allow(reporter).to receive(:current_branch).and_return("some-branch")
|
21
|
-
allow(reporter).to receive(:configured_branch).and_return(:master)
|
22
|
-
|
23
|
-
expect(reporter).to_not be_run_on_current_branch
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'logs a message if false' do
|
27
|
-
expect_any_instance_of(Logger).to receive(:info)
|
28
|
-
|
29
|
-
allow(reporter).to receive(:current_branch).and_return("another-branch")
|
30
|
-
allow(reporter).to receive(:configured_branch).and_return(:master)
|
31
|
-
|
32
|
-
reporter.run_on_current_branch?
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler/setup'
|
3
|
-
require 'artifice'
|
4
|
-
require 'pry'
|
5
|
-
require 'codeclimate-test-reporter'
|
6
|
-
|
7
|
-
ENV['CODECLIMATE_REPO_TOKEN'] = "172754c1bf9a3c698f7770b9fb648f1ebb214425120022d0b2ffc65b97dff531"
|
8
|
-
ENV['CODECLIMATE_API_HOST'] = "http://cc.dev"
|
9
|
-
|
10
|
-
def inflate(string)
|
11
|
-
reader = Zlib::GzipReader.new(StringIO.new(string))
|
12
|
-
reader.read
|
13
|
-
end
|
14
|
-
|
15
|
-
class FakeCodeClimateEndpoint
|
16
|
-
def call(env)
|
17
|
-
@env = env
|
18
|
-
[
|
19
|
-
200,
|
20
|
-
{"Content-Type" => 'text/plain'},
|
21
|
-
["Received"]
|
22
|
-
]
|
23
|
-
end
|
24
|
-
|
25
|
-
def path_info
|
26
|
-
@env["PATH_INFO"]
|
27
|
-
end
|
28
|
-
|
29
|
-
def request_body
|
30
|
-
@env["rack.input"].string
|
31
|
-
end
|
32
|
-
|
33
|
-
def content_type
|
34
|
-
@env["CONTENT_TYPE"]
|
35
|
-
end
|
36
|
-
|
37
|
-
def http_content_encoding
|
38
|
-
@env["HTTP_CONTENT_ENCODING"]
|
39
|
-
end
|
40
|
-
|
41
|
-
def http_user_agent
|
42
|
-
@env["HTTP_USER_AGENT"]
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
|