Sha256: b859e4b462c3bbdaa4eaf943fee72eb674461ebafe01f8b1f9f251e497d562c9

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

class RSpecTask
 
  def initialize(rspec)
    @rspec = rspec
  end
  
  def run(files)
    all_files = files[:all]
    modified_files = files[:filtered]
    
    return nil if (!@rspec.is_configured? all_files) 
    return nil if (!@rspec.should_run? modified_files)

    detail = @rspec.execute()
    
    state, summary, first = parse_result(detail)

    return {
        :state => state,
        :title => 'RSpec',
        :summary => summary,
        :first => first,
        :detail => detail
      }
  end
  
  # Move to parse class
  def parse_result(detail)
    summary_line = detail.grep( /\d+ examples?, \d+ failures?/ )[0]
    
    if summary_line.nil?
      # error
      error_info = (detail + "\nUnknown Error!").to_a[0].strip
      return :error, 'Error', error_info
    end
    
    if summary_line =~ /([1-9]+) failures?/
      num_errors = $1
      
      items = detail.split("\n\n")
      
      error_info = items[1].split("\n")[1]
      return :failure, num_errors + ' Errors', error_info
    end

    return :success, 'All specs pass', ''
    
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
karl-loris-0.0.9 lib/tasks/rspec/rspec_task.rb