Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 592638f

Browse files
committed
Merge pull request #79 from grosser/grosser/merge
cleanup + tests
2 parents d0b84a6 + 20de39a commit 592638f

File tree

6 files changed

+34
-46
lines changed

6 files changed

+34
-46
lines changed

bin/cc-tddium-post-worker

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env ruby
22

3-
require 'rubygems'
43
require 'codeclimate-test-reporter'
54
require 'tmpdir'
65

codeclimate-test-reporter.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ Gem::Specification.new do |spec|
1919
spec.add_development_dependency "bundler", "~> 1.3"
2020
spec.add_development_dependency "rake"
2121
spec.add_development_dependency "rspec"
22-
spec.add_development_dependency "artifice"
22+
spec.add_development_dependency "webmock"
2323
spec.add_development_dependency "pry"
2424
end

spec/lib/ci_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
module CodeClimate::TestReporter
44
describe Ci do
5-
65
describe '.service_data' do
76
before :each do
87
@env = {

spec/lib/client_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,21 @@ module CodeClimate::TestReporter
2020

2121
Client.new.post_results("")
2222
end
23+
24+
describe "#batch_post_results" do
25+
let(:uuid) { "my-uuid" }
26+
let(:token) { ENV["CODECLIMATE_REPO_TOKEN"] }
27+
28+
before { expect(SecureRandom).to receive(:uuid).and_return uuid }
29+
around { |test| Dir.mktmpdir { |dir| Dir.chdir(dir, &test) } }
30+
31+
it "posts a single file" do
32+
File.write("a", "Something")
33+
requests = capture_requests(stub_request(:post, "http://cc.dev/test_reports/batch"))
34+
Client.new.batch_post_results(["a"])
35+
36+
expect(requests.first.body).to eq "--#{uuid}\r\nContent-Disposition: form-data; name=\"repo_token\"\r\n\r\n#{token}\r\n--#{uuid}\r\nContent-Disposition: form-data; name=\"coverage_reports[0]\"; filename=\"a\"\r\nContent-Type: application/json\r\n\r\nSomething\r\n--#{uuid}--\r\n"
37+
end
38+
end
2339
end
2440
end

spec/lib/formatter_spec.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,16 @@ module CodeClimate::TestReporter
9494
it "sends an http request with all the coverage information" do
9595
allow(CodeClimate::TestReporter).to receive(:run?).and_return(true)
9696

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")
97+
stub = stub_request(:post, "http://cc.dev/test_reports").
98+
with(:headers => {'Content-Encoding'=>'gzip', 'Content-Type'=>'application/json', 'User-Agent'=>"Code Climate (Ruby Test Reporter v#{CodeClimate::TestReporter::VERSION})"})
99+
requests = capture_requests(stub)
105100

106-
uncompressed = inflate(app.request_body)
101+
formatter.format(simplecov_result)
107102

103+
uncompressed = inflate(requests.first.body)
108104
expected_request.merge!("ci_service" => Ci.service_data)
109105
expected_json = JSON.parse(expected_request.to_json, symbolize_names: true)
110-
111106
expect(JSON.parse(uncompressed, symbolize_names: true)).to eq(expected_json)
112-
expect(app.http_user_agent).to include("v#{CodeClimate::TestReporter::VERSION}")
113107
end
114108

115109
describe '#short_filename' do

spec/spec_helper.rb

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,26 @@
1-
require 'rubygems'
21
require 'bundler/setup'
3-
require 'artifice'
42
require 'pry'
53
require 'codeclimate-test-reporter'
4+
require 'webmock/rspec'
65

76
ENV['CODECLIMATE_REPO_TOKEN'] = "172754c1bf9a3c698f7770b9fb648f1ebb214425120022d0b2ffc65b97dff531"
87
ENV['CODECLIMATE_API_HOST'] = "http://cc.dev"
98

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"]
9+
module TestHelper
10+
def inflate(string)
11+
reader = Zlib::GzipReader.new(StringIO.new(string))
12+
reader.read
3513
end
3614

37-
def http_content_encoding
38-
@env["HTTP_CONTENT_ENCODING"]
15+
def capture_requests(stub)
16+
requests = []
17+
stub.to_return { |r| requests << r; {body: "hello"} }
18+
requests
3919
end
20+
end
4021

41-
def http_user_agent
42-
@env["HTTP_USER_AGENT"]
43-
end
22+
RSpec.configure do |c|
23+
c.include TestHelper
4424
end
4525

4626

0 commit comments

Comments
 (0)