Module: CodeClimate::TestReporter

Defined in:
lib/code_climate/test_reporter.rb,
lib/code_climate/test_reporter/ci.rb,
lib/code_climate/test_reporter/git.rb,
lib/code_climate/test_reporter/client.rb,
lib/code_climate/test_reporter/version.rb,
lib/code_climate/test_reporter/formatter.rb,
lib/code_climate/test_reporter/post_results.rb,
lib/code_climate/test_reporter/configuration.rb,
lib/code_climate/test_reporter/calculate_blob.rb,
lib/code_climate/test_reporter/shorten_filename.rb,
lib/code_climate/test_reporter/exception_message.rb,
lib/code_climate/test_reporter/payload_validator.rb

Defined Under Namespace

Classes: CalculateBlob, Ci, Client, Configuration, ExceptionMessage, Formatter, Git, PayloadValidator, PostResults, ShortenFilename, VCRMessage, WebMockMessage

Constant Summary collapse

WARNING_MESSAGE =
<<-EOS.freeze
  This usage of the Code Climate Test Reporter is now deprecated. Since version
  1.0, we now require you to run `SimpleCov` in your test/spec helper, and then
  run the provided `codeclimate-test-reporter` binary separately to report your
  results to Code Climate.

  More information here: https://github.com/codeclimate/ruby-test-reporter/blob/master/README.md
EOS
VERSION =
"1.0.7".freeze
InvalidPayload =
Class.new(StandardError)
@@configuration =
nil

Class Method Summary collapse

Class Method Details

.ci_service_dataObject



67
68
69
# File 'lib/code_climate/test_reporter.rb', line 67

def self.ci_service_data
  Ci.service_data
end

.configurationObject



17
18
19
# File 'lib/code_climate/test_reporter/configuration.rb', line 17

def self.configuration
  @@configuration || configure
end

.configureObject



7
8
9
10
11
12
13
14
15
# File 'lib/code_climate/test_reporter/configuration.rb', line 7

def self.configure
  @@configuration = Configuration.new

  if block_given?
    yield configuration
  end

  configuration
end

.configured_branchObject



51
52
53
# File 'lib/code_climate/test_reporter.rb', line 51

def self.configured_branch
  configuration.branch
end

.current_branchObject



55
56
57
# File 'lib/code_climate/test_reporter.rb', line 55

def self.current_branch
  Git.branch_from_git_or_ci
end

.environment_variable_set?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
# File 'lib/code_climate/test_reporter.rb', line 27

def self.environment_variable_set?
  return @environment_variable_set if defined?(@environment_variable_set)

  @environment_variable_set = !!ENV["CODECLIMATE_REPO_TOKEN"]
  if @environment_variable_set
    logger.info("Reporting coverage data to Code Climate.")
  end

  @environment_variable_set
end

.loggerObject



59
60
61
# File 'lib/code_climate/test_reporter.rb', line 59

def self.logger
  CodeClimate::TestReporter.configuration.logger
end

.run(results) ⇒ Object



17
18
19
20
21
# File 'lib/code_climate/test_reporter.rb', line 17

def self.run(results)
  return unless CodeClimate::TestReporter.run?
  formatted_results = CodeClimate::TestReporter::Formatter.new.format(results)
  CodeClimate::TestReporter::PostResults.new(formatted_results).post
end

.run?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/code_climate/test_reporter.rb', line 23

def self.run?
  environment_variable_set? && run_on_current_branch?
end

.run_on_current_branch?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/code_climate/test_reporter.rb', line 38

def self.run_on_current_branch?
  return @run_on_current_branch if defined?(@run_on_current_branch)

  @run_on_current_branch = true if configured_branch.nil?
  @run_on_current_branch ||= !!(current_branch =~ /#{configured_branch}/i)

  unless @run_on_current_branch
    logger.info("Not reporting to Code Climate because #{configured_branch} is set as the reporting branch.")
  end

  @run_on_current_branch
end

.startObject



12
13
14
15
# File 'lib/code_climate/test_reporter.rb', line 12

def self.start
  logger.warn(WARNING_MESSAGE)
  exit(1)
end

.tddium?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/code_climate/test_reporter.rb', line 63

def self.tddium?
  ci_service_data && ci_service_data[:name] == "tddium"
end