Sha256: 8a9a25a9ee0cd955908d8c405d6cc08a530db625bb4ef94c0fd8b79f113f5d93

Contents?: true

Size: 1.34 KB

Versions: 5

Compression:

Stored size: 1.34 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 2>&1`
    rescue Errno::ENOENT
      "Konacha not found"
    end
    if @shell_output.include?("Don't know how to build task 'konacha:run'")
      { type: :konacha, check_output: '', status: 'Not found'.green }
    else
      { type: :konacha, check_output: output, status: status }
    end
  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

5 entries across 5 versions & 1 rubygems

Version Path
rake_check-0.3.5 lib/rake_check/konacha_checker.rb
rake_check-0.3.4 lib/rake_check/konacha_checker.rb
rake_check-0.3.3 lib/rake_check/konacha_checker.rb
rake_check-0.3.2 lib/rake_check/konacha_checker.rb
rake_check-0.3.1 lib/rake_check/konacha_checker.rb