Class: PolishGeeks::DevTools::Commands::Simplecov

Inherits:
Base
  • Object
show all
Defined in:
lib/polish_geeks/dev_tools/commands/simplecov.rb

Overview

Command wrapper for Simple code coverage analysing It informs us if we didn’t reach a proper code coverage level

Constant Summary collapse

NUMBER_REGEXP =

Regexp used to match float number from coverage

/(\d+[.]\d+)/

Constants inherited from Base

Base::TYPES

Instance Attribute Summary

Attributes inherited from Base

#output, #stored_output

Instance Method Summary collapse

Methods inherited from Base

#ensure_executable!

Instance Method Details

#error_messageString

Returns message that should be printed when code coverage level is not met.

Returns:

  • (String)

    message that should be printed when code coverage level is not met



37
38
39
40
# File 'lib/polish_geeks/dev_tools/commands/simplecov.rb', line 37

def error_message
  'SimpleCov coverage level needs to be ' \
    "#{threshold}%#{threshold == limit ? '' : ' or more'}, was #{to_f}%"
end

#executeString

Executes this command

Returns:

  • (String)

    command output



22
23
24
# File 'lib/polish_geeks/dev_tools/commands/simplecov.rb', line 22

def execute
  @output = stored_output.rspec[*Validators::Simplecov::MATCH_REGEXP]
end

#labelString

Returns default label for this command.

Returns:

  • (String)

    default label for this command



32
33
34
# File 'lib/polish_geeks/dev_tools/commands/simplecov.rb', line 32

def label
  "SimpleCov covered #{to_f}%, required #{threshold}%"
end

#to_fFloat

Returns code coverage level.

Returns:

  • (Float)

    code coverage level



16
17
18
# File 'lib/polish_geeks/dev_tools/commands/simplecov.rb', line 16

def to_f
  output[*NUMBER_REGEXP].to_f
end

#valid?Boolean

Returns true if code coverage level is higher or equal to expected.

Returns:

  • (Boolean)

    true if code coverage level is higher or equal to expected



27
28
29
# File 'lib/polish_geeks/dev_tools/commands/simplecov.rb', line 27

def valid?
  to_f >= threshold
end