coveralls_reborn 0.8.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +24 -0
- data/CHANGELOG.md +21 -0
- data/Gemfile +29 -0
- data/LICENSE +22 -0
- data/README.md +5 -0
- data/Rakefile +14 -0
- data/bin/coveralls +9 -0
- data/coveralls-ruby.gemspec +29 -0
- data/lib/coveralls/api.rb +128 -0
- data/lib/coveralls/command.rb +69 -0
- data/lib/coveralls/configuration.rb +230 -0
- data/lib/coveralls/output.rb +114 -0
- data/lib/coveralls/rake/task.rb +19 -0
- data/lib/coveralls/simplecov.rb +101 -0
- data/lib/coveralls/version.rb +3 -0
- data/lib/coveralls.rb +101 -0
- data/spec/coveralls/configuration_spec.rb +355 -0
- data/spec/coveralls/coveralls_spec.rb +106 -0
- data/spec/coveralls/fixtures/app/controllers/sample.rb +12 -0
- data/spec/coveralls/fixtures/app/models/airplane.rb +10 -0
- data/spec/coveralls/fixtures/app/models/dog.rb +10 -0
- data/spec/coveralls/fixtures/app/models/house.rb +10 -0
- data/spec/coveralls/fixtures/app/models/robot.rb +10 -0
- data/spec/coveralls/fixtures/app/models/user.rb +10 -0
- data/spec/coveralls/fixtures/app/vendor/vendored_gem.rb +1 -0
- data/spec/coveralls/fixtures/sample.rb +12 -0
- data/spec/coveralls/output_spec.rb +92 -0
- data/spec/coveralls/simplecov_spec.rb +82 -0
- data/spec/spec_helper.rb +82 -0
- metadata +174 -0
@@ -0,0 +1,114 @@
|
|
1
|
+
module Coveralls
|
2
|
+
#
|
3
|
+
# Public: Methods for formatting strings with Term::ANSIColor.
|
4
|
+
# Does not utilize monkey-patching and should play nicely when
|
5
|
+
# included with other libraries.
|
6
|
+
#
|
7
|
+
# All methods are module methods and should be called on
|
8
|
+
# the Coveralls::Output module.
|
9
|
+
#
|
10
|
+
# Examples
|
11
|
+
#
|
12
|
+
# Coveralls::Output.format("Hello World", :color => "cyan")
|
13
|
+
# # => "\e[36mHello World\e[0m"
|
14
|
+
#
|
15
|
+
# Coveralls::Output.print("Hello World")
|
16
|
+
# # Hello World => nil
|
17
|
+
#
|
18
|
+
# Coveralls::Output.puts("Hello World", :color => "underline")
|
19
|
+
# # Hello World
|
20
|
+
# # => nil
|
21
|
+
#
|
22
|
+
# To silence output completely:
|
23
|
+
#
|
24
|
+
# Coveralls::Output.silent = true
|
25
|
+
#
|
26
|
+
# or set this environment variable:
|
27
|
+
#
|
28
|
+
# COVERALLS_SILENT
|
29
|
+
#
|
30
|
+
# To disable color completely:
|
31
|
+
#
|
32
|
+
# Coveralls::Output.no_color = true
|
33
|
+
|
34
|
+
module Output
|
35
|
+
attr_accessor :silent, :no_color
|
36
|
+
attr_writer :output
|
37
|
+
extend self
|
38
|
+
|
39
|
+
def output
|
40
|
+
(defined?(@output) && @output) || $stdout
|
41
|
+
end
|
42
|
+
|
43
|
+
def no_color?
|
44
|
+
(defined?(@no_color)) && @no_color
|
45
|
+
end
|
46
|
+
|
47
|
+
# Public: Formats the given string with the specified color
|
48
|
+
# through Term::ANSIColor
|
49
|
+
#
|
50
|
+
# string - the text to be formatted
|
51
|
+
# options - The hash of options used for formatting the text:
|
52
|
+
# :color - The color to be passed as a method to
|
53
|
+
# Term::ANSIColor
|
54
|
+
#
|
55
|
+
# Examples
|
56
|
+
#
|
57
|
+
# Coveralls::Output.format("Hello World!", :color => "cyan")
|
58
|
+
# # => "\e[36mHello World\e[0m"
|
59
|
+
#
|
60
|
+
# Returns the formatted string.
|
61
|
+
def format(string, options = {})
|
62
|
+
unless no_color?
|
63
|
+
require 'term/ansicolor'
|
64
|
+
if options[:color]
|
65
|
+
options[:color].split(/\s/).reverse_each do |color|
|
66
|
+
if Term::ANSIColor.respond_to?(color.to_sym)
|
67
|
+
string = Term::ANSIColor.send(color.to_sym, string)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
string
|
73
|
+
end
|
74
|
+
|
75
|
+
# Public: Passes .format to Kernel#puts
|
76
|
+
#
|
77
|
+
# string - the text to be formatted
|
78
|
+
# options - The hash of options used for formatting the text:
|
79
|
+
# :color - The color to be passed as a method to
|
80
|
+
# Term::ANSIColor
|
81
|
+
#
|
82
|
+
#
|
83
|
+
# Example
|
84
|
+
#
|
85
|
+
# Coveralls::Output.puts("Hello World", :color => "cyan")
|
86
|
+
#
|
87
|
+
# Returns nil.
|
88
|
+
def puts(string, options = {})
|
89
|
+
return if silent?
|
90
|
+
(options[:output] || output).puts self.format(string, options)
|
91
|
+
end
|
92
|
+
|
93
|
+
# Public: Passes .format to Kernel#print
|
94
|
+
#
|
95
|
+
# string - the text to be formatted
|
96
|
+
# options - The hash of options used for formatting the text:
|
97
|
+
# :color - The color to be passed as a method to
|
98
|
+
# Term::ANSIColor
|
99
|
+
#
|
100
|
+
# Example
|
101
|
+
#
|
102
|
+
# Coveralls::Output.print("Hello World!", :color => "underline")
|
103
|
+
#
|
104
|
+
# Returns nil.
|
105
|
+
def print(string, options = {})
|
106
|
+
return if silent?
|
107
|
+
(options[:output] || output).print self.format(string, options)
|
108
|
+
end
|
109
|
+
|
110
|
+
def silent?
|
111
|
+
ENV["COVERALLS_SILENT"] || (defined?(@silent) && @silent)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/tasklib'
|
3
|
+
|
4
|
+
module Coveralls
|
5
|
+
class RakeTask < ::Rake::TaskLib
|
6
|
+
include ::Rake::DSL if defined?(::Rake::DSL)
|
7
|
+
|
8
|
+
def initialize(*args, &task_block)
|
9
|
+
namespace :coveralls do
|
10
|
+
desc "Push latest coverage results to Coveralls.io"
|
11
|
+
task :push do
|
12
|
+
require 'coveralls'
|
13
|
+
Coveralls.push!
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end # initialize
|
17
|
+
|
18
|
+
end # class
|
19
|
+
end # module
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module Coveralls
|
2
|
+
module SimpleCov
|
3
|
+
class Formatter
|
4
|
+
|
5
|
+
def display_result(result)
|
6
|
+
# Log which files would be submitted.
|
7
|
+
if result.files.length > 0
|
8
|
+
Coveralls::Output.puts "[Coveralls] Some handy coverage stats:"
|
9
|
+
else
|
10
|
+
Coveralls::Output.puts "[Coveralls] There are no covered files.", color: "yellow"
|
11
|
+
end
|
12
|
+
result.files.each do |f|
|
13
|
+
Coveralls::Output.print " * "
|
14
|
+
Coveralls::Output.print short_filename(f.filename).to_s, color: "cyan"
|
15
|
+
Coveralls::Output.print " => ", color: "white"
|
16
|
+
cov = "#{f.covered_percent.round}%"
|
17
|
+
if f.covered_percent > 90
|
18
|
+
Coveralls::Output.print cov, color: "green"
|
19
|
+
elsif f.covered_percent > 80
|
20
|
+
Coveralls::Output.print cov, color: "yellow"
|
21
|
+
else
|
22
|
+
Coveralls::Output.print cov, color: "red"
|
23
|
+
end
|
24
|
+
Coveralls::Output.puts ""
|
25
|
+
end
|
26
|
+
true
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_source_files(result)
|
30
|
+
# Gather the source files.
|
31
|
+
source_files = []
|
32
|
+
result.files.each do |file|
|
33
|
+
properties = {}
|
34
|
+
|
35
|
+
# Get Source
|
36
|
+
properties[:source] = File.open(file.filename, "rb:utf-8").read
|
37
|
+
|
38
|
+
# Get the root-relative filename
|
39
|
+
properties[:name] = short_filename(file.filename)
|
40
|
+
|
41
|
+
# Get the coverage
|
42
|
+
properties[:coverage] = file.coverage.dup
|
43
|
+
|
44
|
+
# Skip nocov lines
|
45
|
+
file.lines.each_with_index do |line, i|
|
46
|
+
properties[:coverage][i] = nil if line.skipped?
|
47
|
+
end
|
48
|
+
|
49
|
+
source_files << properties
|
50
|
+
end
|
51
|
+
source_files
|
52
|
+
end
|
53
|
+
|
54
|
+
def format(result)
|
55
|
+
|
56
|
+
unless Coveralls.should_run?
|
57
|
+
if Coveralls.noisy?
|
58
|
+
display_result result
|
59
|
+
end
|
60
|
+
return
|
61
|
+
end
|
62
|
+
|
63
|
+
# Post to Coveralls.
|
64
|
+
API.post_json "jobs",
|
65
|
+
source_files: get_source_files(result),
|
66
|
+
test_framework: result.command_name.downcase,
|
67
|
+
run_at: result.created_at
|
68
|
+
|
69
|
+
Coveralls::Output.puts output_message result
|
70
|
+
|
71
|
+
true
|
72
|
+
|
73
|
+
rescue Exception => e
|
74
|
+
display_error e
|
75
|
+
end
|
76
|
+
|
77
|
+
def display_error(e)
|
78
|
+
Coveralls::Output.puts "Coveralls encountered an exception:", color: "red"
|
79
|
+
Coveralls::Output.puts e.class.to_s, color: "red"
|
80
|
+
Coveralls::Output.puts e.message, color: "red"
|
81
|
+
e.backtrace.each do |line|
|
82
|
+
Coveralls::Output.puts line, color: "red"
|
83
|
+
end if e.backtrace
|
84
|
+
if e.respond_to?(:response) && e.response
|
85
|
+
Coveralls::Output.puts e.response.to_s, color: "red"
|
86
|
+
end
|
87
|
+
false
|
88
|
+
end
|
89
|
+
|
90
|
+
def output_message(result)
|
91
|
+
"Coverage is at #{result.covered_percent.round(2) rescue result.covered_percent.round}%.\nCoverage report sent to Coveralls."
|
92
|
+
end
|
93
|
+
|
94
|
+
def short_filename(filename)
|
95
|
+
filename = filename.gsub(::SimpleCov.root, '.').gsub(/^\.\//, '') if ::SimpleCov.root
|
96
|
+
filename
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
data/lib/coveralls.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
require "coveralls/version"
|
2
|
+
require "coveralls/configuration"
|
3
|
+
require "coveralls/api"
|
4
|
+
require "coveralls/output"
|
5
|
+
require "coveralls/simplecov"
|
6
|
+
|
7
|
+
module Coveralls
|
8
|
+
extend self
|
9
|
+
|
10
|
+
class NilFormatter
|
11
|
+
def format(result)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_accessor :testing, :noisy, :run_locally
|
16
|
+
|
17
|
+
def wear!(simplecov_setting=nil, &block)
|
18
|
+
setup!
|
19
|
+
start! simplecov_setting, &block
|
20
|
+
end
|
21
|
+
|
22
|
+
def wear_merged!(simplecov_setting=nil, &block)
|
23
|
+
require 'simplecov'
|
24
|
+
@@adapter = :simplecov
|
25
|
+
::SimpleCov.formatter = NilFormatter
|
26
|
+
start! simplecov_setting, &block
|
27
|
+
end
|
28
|
+
|
29
|
+
def push!
|
30
|
+
require 'simplecov'
|
31
|
+
result = ::SimpleCov::ResultMerger.merged_result
|
32
|
+
Coveralls::SimpleCov::Formatter.new.format result
|
33
|
+
end
|
34
|
+
|
35
|
+
def setup!
|
36
|
+
# Try to load up SimpleCov.
|
37
|
+
@@adapter = nil
|
38
|
+
if defined?(::SimpleCov)
|
39
|
+
@@adapter = :simplecov
|
40
|
+
else
|
41
|
+
begin
|
42
|
+
require 'simplecov'
|
43
|
+
@@adapter = :simplecov if defined?(::SimpleCov)
|
44
|
+
rescue
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Load the appropriate adapter.
|
49
|
+
if @@adapter == :simplecov
|
50
|
+
::SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
51
|
+
Coveralls::Output.puts("[Coveralls] Set up the SimpleCov formatter.", color: "green")
|
52
|
+
else
|
53
|
+
Coveralls::Output.puts("[Coveralls] Couldn't find an appropriate adapter.", color: "red")
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
def start!(simplecov_setting = 'test_frameworks', &block)
|
59
|
+
if @@adapter == :simplecov
|
60
|
+
::SimpleCov.add_filter 'vendor'
|
61
|
+
|
62
|
+
if simplecov_setting
|
63
|
+
Coveralls::Output.puts("[Coveralls] Using SimpleCov's '#{simplecov_setting}' settings.", color: "green")
|
64
|
+
if block_given?
|
65
|
+
::SimpleCov.start(simplecov_setting) { instance_eval(&block)}
|
66
|
+
else
|
67
|
+
::SimpleCov.start(simplecov_setting)
|
68
|
+
end
|
69
|
+
elsif block
|
70
|
+
Coveralls::Output.puts("[Coveralls] Using SimpleCov settings defined in block.", color: "green")
|
71
|
+
::SimpleCov.start { instance_eval(&block) }
|
72
|
+
else
|
73
|
+
Coveralls::Output.puts("[Coveralls] Using SimpleCov's default settings.", color: "green")
|
74
|
+
::SimpleCov.start
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def should_run?
|
80
|
+
# Fail early if we're not on a CI
|
81
|
+
unless will_run?
|
82
|
+
Coveralls::Output.puts("[Coveralls] Outside the CI environment, not sending data.", color: "yellow")
|
83
|
+
return false
|
84
|
+
end
|
85
|
+
|
86
|
+
if ENV["COVERALLS_RUN_LOCALLY"] || (defined?(@run_locally) && @run_locally)
|
87
|
+
Coveralls::Output.puts("[Coveralls] Creating a new job on Coveralls from local coverage results.", color: "cyan")
|
88
|
+
end
|
89
|
+
|
90
|
+
true
|
91
|
+
end
|
92
|
+
|
93
|
+
def will_run?
|
94
|
+
ENV["CI"] || ENV["JENKINS_URL"] || ENV['TDDIUM'] ||
|
95
|
+
ENV["COVERALLS_RUN_LOCALLY"] || (defined?(@testing) && @testing)
|
96
|
+
end
|
97
|
+
|
98
|
+
def noisy?
|
99
|
+
ENV["COVERALLS_NOISY"] || (defined?(@noisy) && @noisy)
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,355 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Coveralls::Configuration do
|
4
|
+
before do
|
5
|
+
ENV.stub(:[]).and_return(nil)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.configuration' do
|
9
|
+
it "returns a hash with the default keys" do
|
10
|
+
config = Coveralls::Configuration.configuration
|
11
|
+
config.should be_a(Hash)
|
12
|
+
config.keys.should include(:environment)
|
13
|
+
config.keys.should include(:git)
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'yaml_config' do
|
17
|
+
let(:repo_token) { SecureRandom.hex(4) }
|
18
|
+
let(:repo_secret_token) { SecureRandom.hex(4) }
|
19
|
+
let(:yaml_config) {
|
20
|
+
{
|
21
|
+
'repo_token' => repo_token,
|
22
|
+
'repo_secret_token' => repo_secret_token
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
before do
|
27
|
+
Coveralls::Configuration.stub(:yaml_config).and_return(yaml_config)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'sets the Yaml config and associated variables if present' do
|
31
|
+
config = Coveralls::Configuration.configuration
|
32
|
+
config[:configuration].should eq(yaml_config)
|
33
|
+
config[:repo_token].should eq(repo_token)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'uses the repo_secret_token if the repo_token is not set' do
|
37
|
+
yaml_config.delete('repo_token')
|
38
|
+
config = Coveralls::Configuration.configuration
|
39
|
+
config[:configuration].should eq(yaml_config)
|
40
|
+
config[:repo_token].should eq(repo_secret_token)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'repo_token in environment' do
|
45
|
+
let(:repo_token) { SecureRandom.hex(4) }
|
46
|
+
|
47
|
+
before do
|
48
|
+
ENV.stub(:[]).with('COVERALLS_REPO_TOKEN').and_return(repo_token)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'pulls the repo token from the environment if set' do
|
52
|
+
config = Coveralls::Configuration.configuration
|
53
|
+
config[:repo_token].should eq(repo_token)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'Services' do
|
58
|
+
context 'with env based service name' do
|
59
|
+
let(:service_name) { 'travis-enterprise' }
|
60
|
+
before do
|
61
|
+
ENV.stub(:[]).with('TRAVIS').and_return('1')
|
62
|
+
ENV.stub(:[]).with('COVERALLS_SERVICE_NAME').and_return(service_name)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'pulls the service name from the environment if set' do
|
66
|
+
config = Coveralls::Configuration.configuration
|
67
|
+
config[:service_name].should eq(service_name)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'on Travis' do
|
72
|
+
before do
|
73
|
+
ENV.stub(:[]).with('TRAVIS').and_return('1')
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should set service parameters for this service and no other' do
|
77
|
+
Coveralls::Configuration.should_receive(:set_service_params_for_travis).with(anything, anything)
|
78
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_circleci)
|
79
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_semaphore)
|
80
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_jenkins)
|
81
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_coveralls_local)
|
82
|
+
Coveralls::Configuration.should_receive(:set_standard_service_params_for_generic_ci)
|
83
|
+
Coveralls::Configuration.configuration
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'on CircleCI' do
|
88
|
+
before do
|
89
|
+
ENV.stub(:[]).with('CIRCLECI').and_return('1')
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should set service parameters for this service and no other' do
|
93
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_travis)
|
94
|
+
Coveralls::Configuration.should_receive(:set_service_params_for_circleci)
|
95
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_semaphore)
|
96
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_jenkins)
|
97
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_coveralls_local)
|
98
|
+
Coveralls::Configuration.should_receive(:set_standard_service_params_for_generic_ci)
|
99
|
+
Coveralls::Configuration.configuration
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'on Semaphore' do
|
104
|
+
before do
|
105
|
+
ENV.stub(:[]).with('SEMAPHORE').and_return('1')
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should set service parameters for this service and no other' do
|
109
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_travis)
|
110
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_circleci)
|
111
|
+
Coveralls::Configuration.should_receive(:set_service_params_for_semaphore)
|
112
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_jenkins)
|
113
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_coveralls_local)
|
114
|
+
Coveralls::Configuration.should_receive(:set_standard_service_params_for_generic_ci)
|
115
|
+
Coveralls::Configuration.configuration
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'when using Jenkins' do
|
120
|
+
before do
|
121
|
+
ENV.stub(:[]).with('JENKINS_URL').and_return('1')
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'should set service parameters for this service and no other' do
|
125
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_travis)
|
126
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_circleci)
|
127
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_semaphore)
|
128
|
+
Coveralls::Configuration.should_receive(:set_service_params_for_jenkins)
|
129
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_coveralls_local)
|
130
|
+
Coveralls::Configuration.should_receive(:set_standard_service_params_for_generic_ci)
|
131
|
+
Coveralls::Configuration.configuration
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context 'when running Coveralls locally' do
|
136
|
+
before do
|
137
|
+
ENV.stub(:[]).with('COVERALLS_RUN_LOCALLY').and_return('1')
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'should set service parameters for this service and no other' do
|
141
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_travis)
|
142
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_circleci)
|
143
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_semaphore)
|
144
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_jenkins)
|
145
|
+
Coveralls::Configuration.should_receive(:set_service_params_for_coveralls_local)
|
146
|
+
Coveralls::Configuration.should_receive(:set_standard_service_params_for_generic_ci)
|
147
|
+
Coveralls::Configuration.configuration
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
context 'for generic CI' do
|
152
|
+
before do
|
153
|
+
ENV.stub(:[]).with('CI_NAME').and_return('1')
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'should set service parameters for this service and no other' do
|
157
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_travis)
|
158
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_circleci)
|
159
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_semaphore)
|
160
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_jenkins)
|
161
|
+
Coveralls::Configuration.should_not_receive(:set_service_params_for_coveralls_local)
|
162
|
+
Coveralls::Configuration.should_receive(:set_standard_service_params_for_generic_ci).with(anything)
|
163
|
+
Coveralls::Configuration.configuration
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe '.set_service_params_for_travis' do
|
170
|
+
let(:travis_job_id) { SecureRandom.hex(4) }
|
171
|
+
before do
|
172
|
+
ENV.stub(:[]).with('TRAVIS_JOB_ID').and_return(travis_job_id)
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'should set the service_job_id' do
|
176
|
+
config = {}
|
177
|
+
Coveralls::Configuration.set_service_params_for_travis(config, nil)
|
178
|
+
config[:service_job_id].should eq(travis_job_id)
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'should set the service_name to travis-ci by default' do
|
182
|
+
config = {}
|
183
|
+
Coveralls::Configuration.set_service_params_for_travis(config, nil)
|
184
|
+
config[:service_name].should eq('travis-ci')
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'should set the service_name to a value if one is passed in' do
|
188
|
+
config = {}
|
189
|
+
random_name = SecureRandom.hex(4)
|
190
|
+
Coveralls::Configuration.set_service_params_for_travis(config, random_name)
|
191
|
+
config[:service_name].should eq(random_name)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe '.set_service_params_for_circleci' do
|
196
|
+
let(:circle_build_num) { SecureRandom.hex(4) }
|
197
|
+
before do
|
198
|
+
ENV.stub(:[]).with('CIRCLE_BUILD_NUM').and_return(circle_build_num)
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'should set the expected parameters' do
|
202
|
+
config = {}
|
203
|
+
Coveralls::Configuration.set_service_params_for_circleci(config)
|
204
|
+
config[:service_name].should eq('circleci')
|
205
|
+
config[:service_number].should eq(circle_build_num)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe '.set_service_params_for_gitlab' do
|
210
|
+
let(:commit_sha) { SecureRandom.hex(32) }
|
211
|
+
let(:service_job_number) { "spec:one" }
|
212
|
+
let(:service_job_id) { 1234 }
|
213
|
+
let(:service_branch) { "feature" }
|
214
|
+
|
215
|
+
before do
|
216
|
+
ENV.stub(:[]).with('CI_BUILD_NAME').and_return(service_job_number)
|
217
|
+
ENV.stub(:[]).with('CI_BUILD_ID').and_return(service_job_id)
|
218
|
+
ENV.stub(:[]).with('CI_BUILD_REF_NAME').and_return(service_branch)
|
219
|
+
ENV.stub(:[]).with('CI_BUILD_REF').and_return(commit_sha)
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'should set the expected parameters' do
|
223
|
+
config = {}
|
224
|
+
Coveralls::Configuration.set_service_params_for_gitlab(config)
|
225
|
+
config[:service_name].should eq('gitlab-ci')
|
226
|
+
config[:service_job_number].should eq(service_job_number)
|
227
|
+
config[:service_job_id].should eq(service_job_id)
|
228
|
+
config[:service_branch].should eq(service_branch)
|
229
|
+
config[:commit_sha].should eq(commit_sha)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
describe '.set_service_params_for_semaphore' do
|
234
|
+
let(:semaphore_build_num) { SecureRandom.hex(4) }
|
235
|
+
before do
|
236
|
+
ENV.stub(:[]).with('SEMAPHORE_BUILD_NUMBER').and_return(semaphore_build_num)
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'should set the expected parameters' do
|
240
|
+
config = {}
|
241
|
+
Coveralls::Configuration.set_service_params_for_semaphore(config)
|
242
|
+
config[:service_name].should eq('semaphore')
|
243
|
+
config[:service_number].should eq(semaphore_build_num)
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
describe '.set_service_params_for_jenkins' do
|
248
|
+
let(:service_pull_request) { '1234' }
|
249
|
+
let(:build_num) { SecureRandom.hex(4) }
|
250
|
+
before do
|
251
|
+
ENV.stub(:[]).with('CI_PULL_REQUEST').and_return(service_pull_request)
|
252
|
+
ENV.stub(:[]).with('BUILD_NUMBER').and_return(build_num)
|
253
|
+
end
|
254
|
+
|
255
|
+
it 'should set the expected parameters' do
|
256
|
+
config = {}
|
257
|
+
Coveralls::Configuration.set_service_params_for_jenkins(config)
|
258
|
+
Coveralls::Configuration.set_standard_service_params_for_generic_ci(config)
|
259
|
+
config[:service_name].should eq('jenkins')
|
260
|
+
config[:service_number].should eq(build_num)
|
261
|
+
config[:service_pull_request].should eq(service_pull_request)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
describe '.set_service_params_for_coveralls_local' do
|
266
|
+
it 'should set the expected parameters' do
|
267
|
+
config = {}
|
268
|
+
Coveralls::Configuration.set_service_params_for_coveralls_local(config)
|
269
|
+
config[:service_name].should eq('coveralls-ruby')
|
270
|
+
config[:service_job_id].should be_nil
|
271
|
+
config[:service_event_type].should eq('manual')
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
describe '.set_service_params_for_generic_ci' do
|
276
|
+
let(:service_name) { SecureRandom.hex(4) }
|
277
|
+
let(:service_number) { SecureRandom.hex(4) }
|
278
|
+
let(:service_build_url) { SecureRandom.hex(4) }
|
279
|
+
let(:service_branch) { SecureRandom.hex(4) }
|
280
|
+
let(:service_pull_request) { '1234' }
|
281
|
+
|
282
|
+
before do
|
283
|
+
ENV.stub(:[]).with('CI_NAME').and_return(service_name)
|
284
|
+
ENV.stub(:[]).with('CI_BUILD_NUMBER').and_return(service_number)
|
285
|
+
ENV.stub(:[]).with('CI_BUILD_URL').and_return(service_build_url)
|
286
|
+
ENV.stub(:[]).with('CI_BRANCH').and_return(service_branch)
|
287
|
+
ENV.stub(:[]).with('CI_PULL_REQUEST').and_return(service_pull_request)
|
288
|
+
end
|
289
|
+
|
290
|
+
it 'should set the expected parameters' do
|
291
|
+
config = {}
|
292
|
+
Coveralls::Configuration.set_standard_service_params_for_generic_ci(config)
|
293
|
+
config[:service_name].should eq(service_name)
|
294
|
+
config[:service_number].should eq(service_number)
|
295
|
+
config[:service_build_url].should eq(service_build_url)
|
296
|
+
config[:service_branch].should eq(service_branch)
|
297
|
+
config[:service_pull_request].should eq(service_pull_request)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
describe '.set_service_params_for_appveyor' do
|
302
|
+
let(:service_number) { SecureRandom.hex(4) }
|
303
|
+
let(:service_branch) { SecureRandom.hex(4) }
|
304
|
+
let(:commit_sha) { SecureRandom.hex(4) }
|
305
|
+
let(:repo_name) { SecureRandom.hex(4) }
|
306
|
+
|
307
|
+
before do
|
308
|
+
ENV.stub(:[]).with('APPVEYOR_BUILD_VERSION').and_return(service_number)
|
309
|
+
ENV.stub(:[]).with('APPVEYOR_REPO_BRANCH').and_return(service_branch)
|
310
|
+
ENV.stub(:[]).with('APPVEYOR_REPO_COMMIT').and_return(commit_sha)
|
311
|
+
ENV.stub(:[]).with('APPVEYOR_REPO_NAME').and_return(repo_name)
|
312
|
+
end
|
313
|
+
|
314
|
+
it 'should set the expected parameters' do
|
315
|
+
config = {}
|
316
|
+
Coveralls::Configuration.set_service_params_for_appveyor(config)
|
317
|
+
config[:service_name].should eq('appveyor')
|
318
|
+
config[:service_number].should eq(service_number)
|
319
|
+
config[:service_branch].should eq(service_branch)
|
320
|
+
config[:commit_sha].should eq(commit_sha)
|
321
|
+
config[:service_build_url].should eq('https://ci.appveyor.com/project/%s/build/%s' % [repo_name, service_number])
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
describe '.git' do
|
326
|
+
let(:git_id) { SecureRandom.hex(2) }
|
327
|
+
let(:author_name) { SecureRandom.hex(4) }
|
328
|
+
let(:author_email) { SecureRandom.hex(4) }
|
329
|
+
let(:committer_name) { SecureRandom.hex(4) }
|
330
|
+
let(:committer_email) { SecureRandom.hex(4) }
|
331
|
+
let(:message) { SecureRandom.hex(4) }
|
332
|
+
let(:branch) { SecureRandom.hex(4) }
|
333
|
+
|
334
|
+
before do
|
335
|
+
allow(ENV).to receive(:fetch).with('GIT_ID', anything).and_return(git_id)
|
336
|
+
allow(ENV).to receive(:fetch).with('GIT_AUTHOR_NAME', anything).and_return(author_name)
|
337
|
+
allow(ENV).to receive(:fetch).with('GIT_AUTHOR_EMAIL', anything).and_return(author_email)
|
338
|
+
allow(ENV).to receive(:fetch).with('GIT_COMMITTER_NAME', anything).and_return(committer_name)
|
339
|
+
allow(ENV).to receive(:fetch).with('GIT_COMMITTER_EMAIL', anything).and_return(committer_email)
|
340
|
+
allow(ENV).to receive(:fetch).with('GIT_MESSAGE', anything).and_return(message)
|
341
|
+
allow(ENV).to receive(:fetch).with('GIT_BRANCH', anything).and_return(branch)
|
342
|
+
end
|
343
|
+
|
344
|
+
it 'uses ENV vars' do
|
345
|
+
config = Coveralls::Configuration.git
|
346
|
+
config[:head][:id].should eq(git_id)
|
347
|
+
config[:head][:author_name].should eq(author_name)
|
348
|
+
config[:head][:author_email].should eq(author_email)
|
349
|
+
config[:head][:committer_name].should eq(committer_name)
|
350
|
+
config[:head][:committer_email].should eq(committer_email)
|
351
|
+
config[:head][:message].should eq(message)
|
352
|
+
config[:branch].should eq(branch)
|
353
|
+
end
|
354
|
+
end
|
355
|
+
end
|