Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion bin/cc-tddium-post-worker
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env ruby

require 'rubygems'
require 'codeclimate-test-reporter'
require 'tmpdir'

Expand Down
2 changes: 1 addition & 1 deletion codeclimate-test-reporter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec"
spec.add_development_dependency "artifice"
spec.add_development_dependency "webmock"
spec.add_development_dependency "pry"
end
1 change: 0 additions & 1 deletion spec/lib/ci_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

module CodeClimate::TestReporter
describe Ci do

describe '.service_data' do
before :each do
@env = {
Expand Down
16 changes: 16 additions & 0 deletions spec/lib/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,21 @@ module CodeClimate::TestReporter

Client.new.post_results("")
end

describe "#batch_post_results" do
let(:uuid) { "my-uuid" }
let(:token) { ENV["CODECLIMATE_REPO_TOKEN"] }

before { expect(SecureRandom).to receive(:uuid).and_return uuid }
around { |test| Dir.mktmpdir { |dir| Dir.chdir(dir, &test) } }

it "posts a single file" do
File.write("a", "Something")
requests = capture_requests(stub_request(:post, "http://cc.dev/test_reports/batch"))
Client.new.batch_post_results(["a"])

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"
end
end
end
end
16 changes: 5 additions & 11 deletions spec/lib/formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,16 @@ module CodeClimate::TestReporter
it "sends an http request with all the coverage information" do
allow(CodeClimate::TestReporter).to receive(:run?).and_return(true)

app = FakeCodeClimateEndpoint.new
Artifice.activate_with(app) do
formatter.format(simplecov_result)
end

expect(app.path_info).to eq("/test_reports")
expect(app.content_type).to eq("application/json")
expect(app.http_content_encoding).to eq("gzip")
stub = stub_request(:post, "http://cc.dev/test_reports").
with(:headers => {'Content-Encoding'=>'gzip', 'Content-Type'=>'application/json', 'User-Agent'=>"Code Climate (Ruby Test Reporter v#{CodeClimate::TestReporter::VERSION})"})
requests = capture_requests(stub)

uncompressed = inflate(app.request_body)
formatter.format(simplecov_result)

uncompressed = inflate(requests.first.body)
expected_request.merge!("ci_service" => Ci.service_data)
expected_json = JSON.parse(expected_request.to_json, symbolize_names: true)

expect(JSON.parse(uncompressed, symbolize_names: true)).to eq(expected_json)
expect(app.http_user_agent).to include("v#{CodeClimate::TestReporter::VERSION}")
end

describe '#short_filename' do
Expand Down
44 changes: 12 additions & 32 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,46 +1,26 @@
require 'rubygems'
require 'bundler/setup'
require 'artifice'
require 'pry'
require 'codeclimate-test-reporter'
require 'webmock/rspec'

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

def inflate(string)
reader = Zlib::GzipReader.new(StringIO.new(string))
reader.read
end

class FakeCodeClimateEndpoint
def call(env)
@env = env
[
200,
{"Content-Type" => 'text/plain'},
["Received"]
]
end

def path_info
@env["PATH_INFO"]
end

def request_body
@env["rack.input"].string
end

def content_type
@env["CONTENT_TYPE"]
module TestHelper
def inflate(string)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was global -> putting it into just tests

reader = Zlib::GzipReader.new(StringIO.new(string))
reader.read
end

def http_content_encoding
@env["HTTP_CONTENT_ENCODING"]
def capture_requests(stub)
requests = []
stub.to_return { |r| requests << r; {body: "hello"} }
requests
end
end

def http_user_agent
@env["HTTP_USER_AGENT"]
end
RSpec.configure do |c|
c.include TestHelper
end