codeclimate-test-reporter 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2f9c2cd5324d8649ca2a3d3a473525bedbe365c
4
- data.tar.gz: 07804f41564354ff8d7123d6c3f6c2f3650b1c41
3
+ metadata.gz: 156905b7518e6be96dc1c73878da83eade488bc0
4
+ data.tar.gz: 2c67aaa1930dfab9d24dacbbc376fae4394ff112
5
5
  SHA512:
6
- metadata.gz: 3e8a40570da4dc86aafa4f1b6d6aab911e779f1d65ea6b61e91ff7b18f84f688c9ea8fbe5dec34bbda8d876b8e8c0d500d0180627851dcaf62546dd61f940b4f
7
- data.tar.gz: a161bca31e7d2cd5355eefe921f4c4f01056a95268d9bc72b8108e48462c8527eb89f727a3ff5044103e51cef9a8ae3e3515723fce89ef71a78c190482f825f5
6
+ metadata.gz: 03603fd7e4059e13bca3c819ad25d052e4640cd00ae3037f4545085c338e3d4c5841054d2569c8f67ebbcdeb16e942956fc51d7f9a1727fe37dad5422e5c0dbf
7
+ data.tar.gz: 0a230cfe3bb2bc53b49c36c8fe2b9d4cf2bd3c03fb58e6df10f9374065618203c4ef261f1d93bd7340cdd46732a600d59ff1a6a3cea28a1abe76419205f929ec
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # codeclimate-test-reporter
2
2
 
3
- [![Code Climate](https://codeclimate.com/github/codeclimate/ruby-test-reporter.png)](https://codeclimate.com/github/codeclimate/ruby-test-reporter)
3
+ [![Code Climate](https://codeclimate.com/github/codeclimate/ruby-test-reporter/badges/gpa.svg)](https://codeclimate.com/github/codeclimate/ruby-test-reporter)
4
4
 
5
5
  Collects test coverage data from your Ruby test suite and sends it to Code
6
6
  Climate's hosted, automated code review service. Based on SimpleCov.
@@ -17,6 +17,8 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = ">= 1.9"
20
22
 
21
23
  spec.add_dependency "simplecov", ">= 0.7.1", "< 1.0.0"
22
24
  spec.add_development_dependency "bundler", "~> 1.3"
@@ -0,0 +1,39 @@
1
+ module CodeClimate
2
+ module TestReporter
3
+
4
+ class CalculateBlob
5
+
6
+ def initialize(file_path)
7
+ @file_path = file_path
8
+ end
9
+
10
+ def blob_id
11
+ calculate_with_file or calculate_with_git
12
+ end
13
+
14
+ private
15
+
16
+ def calculate_with_file
17
+ File.open(@file_path, "rb") do |file|
18
+ header = "blob #{file.size}\0"
19
+ content = file.read
20
+ store = header + content
21
+
22
+ return Digest::SHA1.hexdigest(store)
23
+ end
24
+ rescue EncodingError
25
+ puts "WARNING: Unable to read #{@file_path}\nUsing git for blob calculation"
26
+ nil
27
+ end
28
+
29
+ def calculate_with_git
30
+ output = `git hash-object -t blob #{@file_path}`.chomp
31
+ raise 'ERROR: Failed to calculate blob with git' unless $?.success?
32
+
33
+ output
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+ end
@@ -49,7 +49,7 @@ module CodeClimate
49
49
 
50
50
  {
51
51
  name: short_filename(file.filename),
52
- blob_id: calculate_blob_id(file.filename),
52
+ blob_id: CalculateBlob.new(file.filename).blob_id,
53
53
  coverage: file.coverage.to_json,
54
54
  covered_percent: round(file.covered_percent, 2),
55
55
  covered_strength: round(file.covered_strength, 2),
@@ -81,15 +81,6 @@ module CodeClimate
81
81
  }
82
82
  end
83
83
 
84
- def calculate_blob_id(path)
85
- File.open(path, "rb") do |file|
86
- header = "blob #{file.size}\0"
87
- content = file.read.force_encoding("iso-8859-1").encode("utf-8", replace: nil)
88
- store = header + content
89
-
90
- return Digest::SHA1.hexdigest(store)
91
- end
92
- end
93
84
 
94
85
  def short_filename(filename)
95
86
  return filename unless ::SimpleCov.root
@@ -1,5 +1,5 @@
1
1
  module CodeClimate
2
2
  module TestReporter
3
- VERSION = "0.4.1"
3
+ VERSION = "0.4.2"
4
4
  end
5
5
  end
@@ -1,8 +1,8 @@
1
1
  require "code_climate/test_reporter"
2
+ require "code_climate/test_reporter/calculate_blob"
2
3
  require "code_climate/test_reporter/version"
3
4
  require "code_climate/test_reporter/client"
4
5
  require "code_climate/test_reporter/formatter"
5
6
  require "code_climate/test_reporter/configuration"
6
7
  require "code_climate/test_reporter/git"
7
8
  require "code_climate/test_reporter/ci"
8
-
@@ -0,0 +1,27 @@
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
@@ -137,15 +137,5 @@ module CodeClimate::TestReporter
137
137
  end
138
138
  end
139
139
  end
140
-
141
- describe "#calculate_blob_id" do
142
- it "forces UTF-8 as encoding for the file content" do
143
- blob_id = formatter.calculate_blob_id(File.expand_path("../../fixtures/encoding_test_iso.rb", __FILE__))
144
- expect(blob_id).to_not be_nil
145
-
146
- blob_id = formatter.calculate_blob_id(File.expand_path("../../fixtures/encoding_test.rb", __FILE__))
147
- expect(blob_id).to_not be_nil
148
- end
149
- end
150
140
  end
151
141
  end
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.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Helmkamp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-27 00:00:00.000000000 Z
11
+ date: 2014-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simplecov
@@ -120,6 +120,7 @@ files:
120
120
  - codeclimate-test-reporter.gemspec
121
121
  - config/cacert.pem
122
122
  - lib/code_climate/test_reporter.rb
123
+ - lib/code_climate/test_reporter/calculate_blob.rb
123
124
  - lib/code_climate/test_reporter/ci.rb
124
125
  - lib/code_climate/test_reporter/client.rb
125
126
  - lib/code_climate/test_reporter/configuration.rb
@@ -131,6 +132,7 @@ files:
131
132
  - lib/codeclimate-test-reporter.rb
132
133
  - spec/fixtures/encoding_test.rb
133
134
  - spec/fixtures/encoding_test_iso.rb
135
+ - spec/lib/calculate_blob_spec.rb
134
136
  - spec/lib/ci_spec.rb
135
137
  - spec/lib/configuration_spec.rb
136
138
  - spec/lib/formatter_spec.rb
@@ -150,7 +152,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
150
152
  requirements:
151
153
  - - ">="
152
154
  - !ruby/object:Gem::Version
153
- version: '0'
155
+ version: '1.9'
154
156
  required_rubygems_version: !ruby/object:Gem::Requirement
155
157
  requirements:
156
158
  - - ">="
@@ -165,6 +167,7 @@ summary: Uploads Ruby test coverage data to Code Climate.
165
167
  test_files:
166
168
  - spec/fixtures/encoding_test.rb
167
169
  - spec/fixtures/encoding_test_iso.rb
170
+ - spec/lib/calculate_blob_spec.rb
168
171
  - spec/lib/ci_spec.rb
169
172
  - spec/lib/configuration_spec.rb
170
173
  - spec/lib/formatter_spec.rb
@@ -172,3 +175,4 @@ test_files:
172
175
  - spec/lib/payload_validator_spec.rb
173
176
  - spec/lib/test_reporter_spec.rb
174
177
  - spec/spec_helper.rb
178
+ has_rdoc: