Sha256: eef1d868789d9cff0bfca10088c03058a1baf06da3b2f3ffc98ec3ce4734b169

Contents?: true

Size: 1.55 KB

Versions: 12

Compression:

Stored size: 1.55 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(directory="spec")
    @shell_output = begin
      `export COVERAGE=true; rspec #{directory}; export COVERAGE=`
    rescue Errno::ENOENT
      "RSpec not found"
    end
    { type: directory, 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
      @shell_output =~ / 0 failures/ ? '' : @shell_output
    end

    ##
    # Gives the check codecoverage
    #
    # @return [String] Codecoverage
    def code_coverage
      if @shell_output.include?('Coverage report generated')
        @coverage = /LOC \(([\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

12 entries across 12 versions & 1 rubygems

Version Path
rake_check-0.3.5 lib/rake_check/rspec_checker.rb
rake_check-0.3.4 lib/rake_check/rspec_checker.rb
rake_check-0.3.3 lib/rake_check/rspec_checker.rb
rake_check-0.3.2 lib/rake_check/rspec_checker.rb
rake_check-0.3.1 lib/rake_check/rspec_checker.rb
rake_check-0.3.0 lib/rake_check/rspec_checker.rb
rake_check-0.2.2 lib/rake_check/rspec_checker.rb
rake_check-0.2.1 lib/rake_check/rspec_checker.rb
rake_check-0.2 lib/rake_check/rspec_checker.rb
rake_check-0.1.11 lib/rake_check/rspec_checker.rb
rake_check-0.1.10 lib/rake_check/rspec_checker.rb
rake_check-0.1.9 lib/rake_check/rspec_checker.rb