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/configuration.rb,
lib/code_climate/test_reporter/calculate_blob.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, VCRMessage, WebMockMessage

Constant Summary collapse

VERSION =
"0.6.0".freeze
InvalidPayload =
Class.new(StandardError)
@@configuration =
nil

Class Method Summary collapse

Class Method Details

.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



42
43
44
# File 'lib/code_climate/test_reporter.rb', line 42

def self.configured_branch
  configuration.branch
end

.current_branchObject



46
47
48
# File 'lib/code_climate/test_reporter.rb', line 46

def self.current_branch
  Git.branch_from_git_or_ci
end

.environment_variable_set?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
# File 'lib/code_climate/test_reporter.rb', line 18

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



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

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

.run?Boolean

Returns:

  • (Boolean)


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

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

.run_on_current_branch?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/code_climate/test_reporter.rb', line 29

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



3
4
5
6
7
8
9
10
11
12
# File 'lib/code_climate/test_reporter.rb', line 3

def self.start
  if run?
    require "simplecov"
    ::SimpleCov.add_filter "vendor"
    ::SimpleCov.formatter = Formatter
    ::SimpleCov.start(configuration.profile) do
      skip_token CodeClimate::TestReporter.configuration.skip_token
    end
  end
end