codeclimate-test-reporter 0.0.11 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ *.DS_Store
6
7
  Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --order rand
data/Rakefile CHANGED
@@ -1,11 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
- require 'rake/testtask'
2
+ require 'rspec/core/rake_task'
3
3
 
4
- Rake::TestTask.new do |t|
5
- t.libs.push "lib"
6
- t.libs.push "spec"
7
- t.test_files = FileList['spec/*_spec.rb']
8
- t.verbose = true
9
- end
4
+ RSpec::Core::RakeTask.new(:spec)
10
5
 
11
- task default: :test
6
+ task :default => :spec
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "codeclimate-test-reporter"
4
+ require "code_climate/test_reporter/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "codeclimate-test-reporter"
@@ -21,4 +21,8 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency "simplecov", ">= 0.7.1", "< 1.0.0"
22
22
  spec.add_development_dependency "bundler", "~> 1.3"
23
23
  spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "artifice"
26
+ spec.add_development_dependency "pry"
27
+ spec.add_development_dependency "pry-debugger"
24
28
  end
@@ -1,6 +1,5 @@
1
1
  module CodeClimate
2
2
  module TestReporter
3
- VERSION = "0.0.11"
4
3
 
5
4
  def self.start
6
5
  if run?
@@ -8,6 +8,7 @@ module CodeClimate
8
8
  class Client
9
9
 
10
10
  DEFAULT_TIMEOUT = 5 # in seconds
11
+ USER_AGENT = "Code Climate (Ruby Test Reporter v#{VERSION})"
11
12
 
12
13
  def host
13
14
  ENV["CODECLIMATE_API_HOST"] ||
@@ -33,6 +34,7 @@ module CodeClimate
33
34
  end
34
35
  post_body << "\r\n--#{boundary}--\r\n"
35
36
  request = Net::HTTP::Post.new(uri.request_uri)
37
+ request["User-Agent"] = USER_AGENT
36
38
  request.body = post_body.join
37
39
  request["Content-Type"] = "multipart/form-data, boundary=#{boundary}"
38
40
  response = http.request(request)
@@ -49,8 +51,10 @@ module CodeClimate
49
51
  http = http_client(uri)
50
52
 
51
53
  request = Net::HTTP::Post.new(uri.path)
54
+ request["User-Agent"] = USER_AGENT
52
55
  request["Content-Type"] = "application/json"
53
- request.body = result.to_json
56
+ request["Content-Encoding"] = "gzip"
57
+ request.body = compress(result.to_json)
54
58
 
55
59
  response = http.request(request)
56
60
 
@@ -76,6 +80,14 @@ module CodeClimate
76
80
  end
77
81
  end
78
82
 
83
+ def compress(str)
84
+ sio = StringIO.new("w")
85
+ gz = Zlib::GzipWriter.new(sio)
86
+ gz.write(str)
87
+ gz.close
88
+ sio.string
89
+ end
90
+
79
91
  end
80
92
 
81
93
  end
@@ -2,6 +2,7 @@ require "tmpdir"
2
2
  require "securerandom"
3
3
  require "json"
4
4
  require "digest/sha1"
5
+ require "simplecov"
5
6
 
6
7
  require "code_climate/test_reporter/exception_message"
7
8
 
@@ -58,7 +59,7 @@ module CodeClimate
58
59
  {
59
60
  repo_token: ENV["CODECLIMATE_REPO_TOKEN"],
60
61
  source_files: source_files,
61
- run_at: result.created_at,
62
+ run_at: result.created_at.to_i,
62
63
  covered_percent: round(result.covered_percent, 2),
63
64
  covered_strength: round(result.covered_strength, 2),
64
65
  line_counts: totals,
@@ -0,0 +1,5 @@
1
+ module CodeClimate
2
+ module TestReporter
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -1,3 +1,4 @@
1
- require 'code_climate/test_reporter'
1
+ require "code_climate/test_reporter"
2
2
  require "code_climate/test_reporter/client"
3
3
  require "code_climate/test_reporter/formatter"
4
+ require "code_climate/test_reporter/version"
@@ -0,0 +1,101 @@
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(:files) {
10
+ [
11
+ mock(
12
+ :lines => [mock, mock, mock],
13
+ :covered_lines => [mock, mock],
14
+ :missed_lines => [mock],
15
+ :filename => project_file,
16
+ :coverage => [0,3,2,nil],
17
+ :covered_percent => 33.2,
18
+ :covered_strength => 2
19
+ )
20
+ ]
21
+ }
22
+
23
+ let(:simplecov_result) {
24
+ mock(
25
+ :covered_percent => 24.3,
26
+ :covered_strength => 33.2,
27
+ :files => files,
28
+ :created_at => Time.at(1379704336),
29
+ :command_name => "rspec"
30
+ )
31
+ }
32
+
33
+ let(:expected_request) {
34
+ {
35
+ "repo_token" => "172754c1bf9a3c698f7770b9fb648f1ebb214425120022d0b2ffc65b97dff531",
36
+ "source_files" =>
37
+ [
38
+ {
39
+ "name" => project_file,
40
+ "blob_id" => "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
41
+ "coverage" => "[0,3,2,null]",
42
+ "covered_percent" => 33.2,
43
+ "covered_strength" => 2.0,
44
+ "line_counts" => {"total"=>3, "covered"=>2, "missed"=>1}
45
+ }
46
+ ],
47
+ "run_at" => 1379704336,
48
+ "covered_percent" => 24.3,
49
+ "covered_strength" => 33.2,
50
+ "line_counts" => {"total" => 3, "covered" => 2, "missed" => 1 },
51
+ "partial"=> false,
52
+ "git" =>
53
+ {
54
+ "head" => @commit_sha,
55
+ "committed_at" => @committed_at.to_i,
56
+ "branch" => "master"
57
+ },
58
+ "environment" =>
59
+ {
60
+ "test_framework" => "rspec",
61
+ "pwd" => Dir.pwd,
62
+ "rails_root" => nil,
63
+ "simplecov_root" => Dir.pwd,
64
+ "gem_version" => "0.0.11"
65
+ },
66
+ "ci_service" => {}
67
+ }
68
+ }
69
+
70
+ before do
71
+ @old_pwd = Dir.pwd
72
+ FileUtils.mkdir_p(project_path)
73
+ FileUtils.cd(project_path)
74
+ FileUtils.touch(project_file)
75
+ SimpleCov.root(Dir.pwd)
76
+ system("git init")
77
+ system("git add #{project_file}")
78
+ system("git commit -m 'initial commit'")
79
+ @commit_sha = `git log -1 --pretty=format:'%H'`
80
+ @committed_at = `git log -1 --pretty=format:'%ct'`
81
+ end
82
+
83
+ after do
84
+ FileUtils.cd(@old_pwd)
85
+ FileUtils.rm_rf(project_path)
86
+ end
87
+
88
+ it "sends an http request with all the coverage information" do
89
+ app = FakeCodeClimateEndpoint.new
90
+ Artifice.activate_with(app) do
91
+ formatter.format(simplecov_result)
92
+ end
93
+ app.path_info.should == "/test_reports"
94
+ app.content_type.should == "application/json"
95
+ app.http_content_encoding.should == "gzip"
96
+ uncompressed = inflate(app.request_body)
97
+ JSON.parse(uncompressed).should == expected_request
98
+ app.http_user_agent.should include("v#{CodeClimate::TestReporter::VERSION}")
99
+ end
100
+ end
101
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,46 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'artifice'
4
+ require 'pry'
1
5
  require 'codeclimate-test-reporter'
2
- CodeClimate::TestReporter.start
3
6
 
4
- require 'minitest/spec'
5
- require 'minitest/autorun'
6
- require 'minitest/pride'
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
+
7
46
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codeclimate-test-reporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-19 00:00:00.000000000 Z
12
+ date: 2013-09-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: simplecov
@@ -65,6 +65,70 @@ dependencies:
65
65
  - - ! '>='
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: rspec
70
+ requirement: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: artifice
86
+ requirement: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ - !ruby/object:Gem::Dependency
101
+ name: pry
102
+ requirement: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ type: :development
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ - !ruby/object:Gem::Dependency
117
+ name: pry-debugger
118
+ requirement: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
68
132
  description: Collects test coverage data from your Ruby test suite and sends it to
69
133
  Code Climate's hosted, automated code review service. Based on SimpleCov.
70
134
  email:
@@ -75,6 +139,7 @@ extensions: []
75
139
  extra_rdoc_files: []
76
140
  files:
77
141
  - .gitignore
142
+ - .rspec
78
143
  - Gemfile
79
144
  - LICENSE.txt
80
145
  - README.md
@@ -86,7 +151,9 @@ files:
86
151
  - lib/code_climate/test_reporter/client.rb
87
152
  - lib/code_climate/test_reporter/exception_message.rb
88
153
  - lib/code_climate/test_reporter/formatter.rb
154
+ - lib/code_climate/test_reporter/version.rb
89
155
  - lib/codeclimate-test-reporter.rb
156
+ - spec/lib/formatter_spec.rb
90
157
  - spec/spec_helper.rb
91
158
  homepage: ''
92
159
  licenses:
@@ -114,5 +181,6 @@ signing_key:
114
181
  specification_version: 3
115
182
  summary: Uploads Ruby test coverage data to Code Climate.
116
183
  test_files:
184
+ - spec/lib/formatter_spec.rb
117
185
  - spec/spec_helper.rb
118
186
  has_rdoc: