Sha256: 422c318df39c282db9ede314f0079fc1d79c16b49c44b71f01cd19174b1463cb

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

require 'colored'
##
# Check the Output of rspec and simplecov
#
# @author dmasur
class RspecChecker
  ##
  # Gives the Result Hash
  #
  # @return [Hash] Checkresult
  # @author dmasur
  def result
    @shell_output = `export COVERAGE=true; rspec spec spec_no_rails; export COVERAGE=`
    {:type => :rspec, :status => status + code_coverage, :check_output => output}
  end

  private
    ##
    # Gives the Check Status
    #
    # @return [String] Checkstatus
    # @author dmasur
    def status
      case @shell_output
      when / 0 failures/
        'OK'.green
      when /failures?/
        /\d+ failures?/.match(@shell_output)[0].red
      else 'N/A'
      end
    end

    ##
    # Gives the check output
    #
    # @return [String] Output
    # @author dmasur
    def output
      case @shell_output
      when / 0 failures/ then ''
      else @shell_output
      end
    end

    ##
    # Gives the check codecoverage
    #
    # @return [String] Codecoverage
    def code_coverage
      if @shell_output.include?('Coverage report generated')
        @coverage = /LOC \((\d+\.\d+)%\) covered/.match(@shell_output)[1].to_f
        color_coverage
        " with #{@coverage} Code Coverage"
      else
        ""
      end
    end

    ##
    # Calculate the Codecoverage
    #
    # @return [String] Colored Codecoverage
    def color_coverage
      @coverage = case @coverage
      when 0..60 then "#{@coverage}%".red
      when 60..90 then "#{@coverage}%".yellow
      when 90..100 then "#{@coverage}%".green
      end
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rake_check-0.1.1 lib/rake_check/rspec_checker.rb