codeclimate-test-reporter 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +8 -0
- data/README.md +2 -2
- data/codeclimate-test-reporter.gemspec +0 -1
- data/lib/code_climate/test_reporter.rb +11 -7
- data/lib/code_climate/test_reporter/ci.rb +8 -0
- data/lib/code_climate/test_reporter/client.rb +7 -2
- data/lib/code_climate/test_reporter/configuration.rb +5 -1
- data/lib/code_climate/test_reporter/formatter.rb +2 -0
- data/lib/code_climate/test_reporter/version.rb +1 -1
- data/spec/lib/formatter_spec.rb +28 -14
- data/spec/lib/test_reporter_spec.rb +13 -11
- metadata +20 -19
- checksums.yaml +0 -15
data/Gemfile
CHANGED
@@ -2,3 +2,11 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in codeclimate-test-reporter.gemspec
|
4
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/README.md
CHANGED
@@ -9,8 +9,8 @@ Code Climate - [https://codeclimate.com](https://codeclimate.com)
|
|
9
9
|
|
10
10
|
## Installation
|
11
11
|
|
12
|
-
This gem
|
13
|
-
first step is to
|
12
|
+
This gem requires a user, but not necessarily a paid account, on Code Climate, so if you don't have one the
|
13
|
+
first step is to signup at: [https://codeclimate.com](https://codeclimate.com). Then:
|
14
14
|
|
15
15
|
1. Add this to your Gemfile:
|
16
16
|
|
@@ -15,23 +15,27 @@ module CodeClimate
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.environment_variable_set?
|
18
|
-
environment_variable_set
|
19
|
-
|
18
|
+
return @environment_variable_set if defined?(@environment_variable_set)
|
19
|
+
|
20
|
+
@environment_variable_set = !!ENV["CODECLIMATE_REPO_TOKEN"]
|
21
|
+
unless @environment_variable_set
|
20
22
|
logger.info("Not reporting to Code Climate because ENV['CODECLIMATE_REPO_TOKEN'] is not set.")
|
21
23
|
end
|
22
24
|
|
23
|
-
environment_variable_set
|
25
|
+
@environment_variable_set
|
24
26
|
end
|
25
27
|
|
26
28
|
def self.run_on_current_branch?
|
27
|
-
return
|
29
|
+
return @run_on_current_branch if defined?(@run_on_current_branch)
|
30
|
+
|
31
|
+
@run_on_current_branch = true if configured_branch.nil?
|
32
|
+
@run_on_current_branch ||= !!(current_branch =~ /#{configured_branch}/i)
|
28
33
|
|
29
|
-
run_on_current_branch
|
30
|
-
unless run_on_current_branch
|
34
|
+
unless @run_on_current_branch
|
31
35
|
logger.info("Not reporting to Code Climate because #{configured_branch} is set as the reporting branch.")
|
32
36
|
end
|
33
37
|
|
34
|
-
run_on_current_branch
|
38
|
+
@run_on_current_branch
|
35
39
|
end
|
36
40
|
|
37
41
|
def self.configured_branch
|
@@ -37,6 +37,14 @@ module CodeClimate
|
|
37
37
|
build_identifier: ENV['TDDIUM_SESSION_ID'],
|
38
38
|
worker_id: ENV['TDDIUM_TID']
|
39
39
|
}
|
40
|
+
elsif ENV['WERCKER']
|
41
|
+
{
|
42
|
+
name: "wercker",
|
43
|
+
build_identifier: ENV['WERCKER_BUILD_ID'],
|
44
|
+
build_url: ENV['WERCKER_BUILD_URL'],
|
45
|
+
branch: ENV['WERCKER_GIT_BRANCH'],
|
46
|
+
commit_sha: ENV['WERCKER_GIT_COMMIT']
|
47
|
+
}
|
40
48
|
elsif ENV['CI_NAME'] =~ /codeship/i
|
41
49
|
{
|
42
50
|
name: "codeship",
|
@@ -53,8 +53,13 @@ module CodeClimate
|
|
53
53
|
request = Net::HTTP::Post.new(uri.path)
|
54
54
|
request["User-Agent"] = USER_AGENT
|
55
55
|
request["Content-Type"] = "application/json"
|
56
|
-
|
57
|
-
|
56
|
+
|
57
|
+
if CodeClimate::TestReporter.configuration.gzip_request
|
58
|
+
request["Content-Encoding"] = "gzip"
|
59
|
+
request.body = compress(result.to_json)
|
60
|
+
else
|
61
|
+
request.body = result.to_json
|
62
|
+
end
|
58
63
|
|
59
64
|
response = http.request(request)
|
60
65
|
|
@@ -19,7 +19,11 @@ module CodeClimate
|
|
19
19
|
end
|
20
20
|
|
21
21
|
class Configuration
|
22
|
-
attr_accessor :branch, :logger, :profile, :path_prefix
|
22
|
+
attr_accessor :branch, :logger, :profile, :path_prefix, :gzip_request
|
23
|
+
|
24
|
+
def initialize
|
25
|
+
@gzip_request = true
|
26
|
+
end
|
23
27
|
|
24
28
|
def logger
|
25
29
|
@logger ||= default_logger
|
data/spec/lib/formatter_spec.rb
CHANGED
@@ -86,33 +86,47 @@ module CodeClimate::TestReporter
|
|
86
86
|
end
|
87
87
|
|
88
88
|
it "sends an http request with all the coverage information" do
|
89
|
+
allow(CodeClimate::TestReporter).to receive(:run?).and_return(true)
|
90
|
+
|
89
91
|
app = FakeCodeClimateEndpoint.new
|
90
92
|
Artifice.activate_with(app) do
|
91
93
|
formatter.format(simplecov_result)
|
92
94
|
end
|
93
|
-
|
94
|
-
app.
|
95
|
-
app.
|
95
|
+
|
96
|
+
expect(app.path_info).to eq("/test_reports")
|
97
|
+
expect(app.content_type).to eq("application/json")
|
98
|
+
expect(app.http_content_encoding).to eq("gzip")
|
99
|
+
|
96
100
|
uncompressed = inflate(app.request_body)
|
97
|
-
|
98
|
-
|
101
|
+
|
102
|
+
expect(JSON.parse(uncompressed)).to eq(expected_request)
|
103
|
+
expect(app.http_user_agent).to include("v#{CodeClimate::TestReporter::VERSION}")
|
99
104
|
end
|
100
105
|
end
|
101
106
|
|
102
107
|
describe '#short_filename' do
|
108
|
+
let(:formatter) { CodeClimate::TestReporter::Formatter.new }
|
103
109
|
it 'should return the filename of the file relative to the SimpleCov root' do
|
104
|
-
|
105
|
-
|
110
|
+
expect(formatter.short_filename('file1')).to eq('file1')
|
111
|
+
expect(formatter.short_filename("#{::SimpleCov.root}/file1")).to eq('file1')
|
106
112
|
end
|
107
113
|
|
108
|
-
|
109
|
-
|
110
|
-
|
114
|
+
context "with path prefix" do
|
115
|
+
before do
|
116
|
+
CodeClimate::TestReporter.configure do |config|
|
117
|
+
config.path_prefix = 'custom'
|
118
|
+
end
|
111
119
|
end
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
120
|
+
|
121
|
+
after do
|
122
|
+
CodeClimate::TestReporter.configure do |config|
|
123
|
+
config.path_prefix = nil
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should include the path prefix if set' do
|
128
|
+
expect(formatter.short_filename('file1')).to eq('custom/file1')
|
129
|
+
expect(formatter.short_filename("#{::SimpleCov.root}/file1")).to eq('custom/file1')
|
116
130
|
end
|
117
131
|
end
|
118
132
|
end
|
@@ -1,33 +1,35 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe CodeClimate::TestReporter do
|
4
|
+
let(:reporter) { CodeClimate::TestReporter.dup }
|
4
5
|
|
5
6
|
describe '.run_on_current_branch?' do
|
6
7
|
it 'returns true if there is no branch configured' do
|
7
|
-
allow(
|
8
|
-
expect(
|
8
|
+
allow(reporter).to receive(:configured_branch).and_return(nil)
|
9
|
+
expect(reporter).to be_run_on_current_branch
|
9
10
|
end
|
10
11
|
|
11
12
|
it 'returns true if the current branch matches the configured branch' do
|
12
|
-
allow(
|
13
|
-
allow(
|
13
|
+
allow(reporter).to receive(:current_branch).and_return("master\n")
|
14
|
+
allow(reporter).to receive(:configured_branch).and_return(:master)
|
14
15
|
|
15
|
-
expect(
|
16
|
+
expect(reporter).to be_run_on_current_branch
|
16
17
|
end
|
17
18
|
|
18
19
|
it 'returns false if the current branch and configured branch dont match' do
|
19
|
-
allow(
|
20
|
-
allow(
|
20
|
+
allow(reporter).to receive(:current_branch).and_return("some-branch")
|
21
|
+
allow(reporter).to receive(:configured_branch).and_return(:master)
|
21
22
|
|
22
|
-
expect(
|
23
|
+
expect(reporter).to_not be_run_on_current_branch
|
23
24
|
end
|
24
25
|
|
25
26
|
it 'logs a message if false' do
|
26
27
|
expect_any_instance_of(Logger).to receive(:info)
|
27
|
-
allow(CodeClimate::TestReporter).to receive(:current_branch).and_return("another-branch")
|
28
|
-
allow(CodeClimate::TestReporter).to receive(:configured_branch).and_return(:master)
|
29
28
|
|
30
|
-
|
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?
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
metadata
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codeclimate-test-reporter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Bryan Helmkamp
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2014-01
|
12
|
+
date: 2014-08-01 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: simplecov
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
19
|
- - ! '>='
|
18
20
|
- !ruby/object:Gem::Version
|
@@ -23,6 +25,7 @@ dependencies:
|
|
23
25
|
type: :runtime
|
24
26
|
prerelease: false
|
25
27
|
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
26
29
|
requirements:
|
27
30
|
- - ! '>='
|
28
31
|
- !ruby/object:Gem::Version
|
@@ -33,6 +36,7 @@ dependencies:
|
|
33
36
|
- !ruby/object:Gem::Dependency
|
34
37
|
name: bundler
|
35
38
|
requirement: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
36
40
|
requirements:
|
37
41
|
- - ~>
|
38
42
|
- !ruby/object:Gem::Version
|
@@ -40,6 +44,7 @@ dependencies:
|
|
40
44
|
type: :development
|
41
45
|
prerelease: false
|
42
46
|
version_requirements: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
43
48
|
requirements:
|
44
49
|
- - ~>
|
45
50
|
- !ruby/object:Gem::Version
|
@@ -47,6 +52,7 @@ dependencies:
|
|
47
52
|
- !ruby/object:Gem::Dependency
|
48
53
|
name: rake
|
49
54
|
requirement: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
50
56
|
requirements:
|
51
57
|
- - ! '>='
|
52
58
|
- !ruby/object:Gem::Version
|
@@ -54,6 +60,7 @@ dependencies:
|
|
54
60
|
type: :development
|
55
61
|
prerelease: false
|
56
62
|
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
57
64
|
requirements:
|
58
65
|
- - ! '>='
|
59
66
|
- !ruby/object:Gem::Version
|
@@ -61,6 +68,7 @@ dependencies:
|
|
61
68
|
- !ruby/object:Gem::Dependency
|
62
69
|
name: rspec
|
63
70
|
requirement: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
64
72
|
requirements:
|
65
73
|
- - ! '>='
|
66
74
|
- !ruby/object:Gem::Version
|
@@ -68,6 +76,7 @@ dependencies:
|
|
68
76
|
type: :development
|
69
77
|
prerelease: false
|
70
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
71
80
|
requirements:
|
72
81
|
- - ! '>='
|
73
82
|
- !ruby/object:Gem::Version
|
@@ -75,6 +84,7 @@ dependencies:
|
|
75
84
|
- !ruby/object:Gem::Dependency
|
76
85
|
name: artifice
|
77
86
|
requirement: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
78
88
|
requirements:
|
79
89
|
- - ! '>='
|
80
90
|
- !ruby/object:Gem::Version
|
@@ -82,6 +92,7 @@ dependencies:
|
|
82
92
|
type: :development
|
83
93
|
prerelease: false
|
84
94
|
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
85
96
|
requirements:
|
86
97
|
- - ! '>='
|
87
98
|
- !ruby/object:Gem::Version
|
@@ -89,6 +100,7 @@ dependencies:
|
|
89
100
|
- !ruby/object:Gem::Dependency
|
90
101
|
name: pry
|
91
102
|
requirement: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
92
104
|
requirements:
|
93
105
|
- - ! '>='
|
94
106
|
- !ruby/object:Gem::Version
|
@@ -96,20 +108,7 @@ dependencies:
|
|
96
108
|
type: :development
|
97
109
|
prerelease: false
|
98
110
|
version_requirements: !ruby/object:Gem::Requirement
|
99
|
-
|
100
|
-
- - ! '>='
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: '0'
|
103
|
-
- !ruby/object:Gem::Dependency
|
104
|
-
name: pry-debugger
|
105
|
-
requirement: !ruby/object:Gem::Requirement
|
106
|
-
requirements:
|
107
|
-
- - ! '>='
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '0'
|
110
|
-
type: :development
|
111
|
-
prerelease: false
|
112
|
-
version_requirements: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
113
112
|
requirements:
|
114
113
|
- - ! '>='
|
115
114
|
- !ruby/object:Gem::Version
|
@@ -152,26 +151,27 @@ files:
|
|
152
151
|
homepage: ''
|
153
152
|
licenses:
|
154
153
|
- MIT
|
155
|
-
metadata: {}
|
156
154
|
post_install_message:
|
157
155
|
rdoc_options: []
|
158
156
|
require_paths:
|
159
157
|
- lib
|
160
158
|
required_ruby_version: !ruby/object:Gem::Requirement
|
159
|
+
none: false
|
161
160
|
requirements:
|
162
161
|
- - ! '>='
|
163
162
|
- !ruby/object:Gem::Version
|
164
163
|
version: '0'
|
165
164
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
none: false
|
166
166
|
requirements:
|
167
167
|
- - ! '>='
|
168
168
|
- !ruby/object:Gem::Version
|
169
169
|
version: '0'
|
170
170
|
requirements: []
|
171
171
|
rubyforge_project:
|
172
|
-
rubygems_version:
|
172
|
+
rubygems_version: 1.8.23.2
|
173
173
|
signing_key:
|
174
|
-
specification_version:
|
174
|
+
specification_version: 3
|
175
175
|
summary: Uploads Ruby test coverage data to Code Climate.
|
176
176
|
test_files:
|
177
177
|
- spec/lib/ci_spec.rb
|
@@ -181,3 +181,4 @@ test_files:
|
|
181
181
|
- spec/lib/payload_validator_spec.rb
|
182
182
|
- spec/lib/test_reporter_spec.rb
|
183
183
|
- spec/spec_helper.rb
|
184
|
+
has_rdoc:
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
ZGE4Y2ZjZDBmYzMyMzdhNzhkN2M1NGNhZWI5N2JkNWVmY2FjNzAxNA==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
YTc5MjYzNTJmMGViZDdkNTQ5MzhkNjQ4MTE3ODYwMzM4OTk4NGIyMA==
|
7
|
-
SHA512:
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
MTM2ZTY3YWU4MjlmZTdlM2U2NjgyNDVlYTQ1NWI5Y2EwMmRkYTU0MjM3YTM3
|
10
|
-
N2I4YzJjZWZmNmM3NGNlNTkwMDQzNTFjNmZhY2M2YWUwMzQ3YTA4MTc0ZTVi
|
11
|
-
NGI2NjI5NmM3Yzg5MzEyNjJlNWZiYzE0NGIxZGFkNTczMDk3Mjg=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NDc4NzgxNWY5ZWQzMzA2NDBkYmYyMzY2MGJiNjVlYzhlZjZkNjdlMDYzZGY3
|
14
|
-
MzNlNDI0NWJiZWM0YTA0M2U1ZmIzYTg2NDQ1OTIzODEwYjdlMDJkZTVlMTRm
|
15
|
-
ZjM3YWFiNmVkZTY0ZWNjNTIyODIzNjZmNmEyNTA4YWI5Y2VlZTE=
|