Sha256: c093325a90e513c168880cdb3acfbaeb0a868be42838e66d0726d465b976b3aa

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

require 'colored'
##
# Konacha Checker checks for konacha Errors in you Javascripttests
#
# @author dmasur
class KonachaChecker
  ##
  # Gives the Checkresult
  #
  # @return [Hash] Checkresult
  # @author dmasur
  def result
    @shell_output = begin
      `rake konacha:run`
    rescue Errno::ENOENT
      "Konacha not found"
    end
    { type: :konacha, check_output: output, status: status }
  end

  private

  ##
  # Gives the Check Status
  #
  # @return [String] Checkstatus
  # @author dmasur
  def status
    @violations = violation_count
    if @violations > 0
      print_violations
    elsif @violations == 0
      'OK'.green
    else
      'N/A'
    end
  end

  def output
    violation_count > 0 ? @shell_output : ''
  end

  def violation_count
    @violations ||= @shell_output.scan(/(\d*) examples, (\d*) failures?/).flatten.last.to_i
  end

  def print_violations
    color_violations
    "#{@violations} Javascript Errors"
  end
  ##
  # Color Code Validation Count
  #
  # @return [String] Colored Validation Count
  # @author dmasur
  def color_violations
    color = :red
    color = :yellow if @violations.between?(1, 9)
    @violations = @violations.to_s.send color
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rake_check-0.3.0 lib/rake_check/konacha_checker.rb