Sha256: bd0f149960b531352b6c5dd255b222b182274e9739a29375582c527d1b97ace4

Contents?: true

Size: 783 Bytes

Versions: 4

Compression:

Stored size: 783 Bytes

Contents

class Blade::CombinedTestResults
  attr_reader :sessions, :all_test_results

  def initialize(sessions)
    @sessions = sessions
    @all_test_results = sessions.map(&:test_results)
  end

  def total
    sum(totals)
  end

  def lines(type = :results)
    sessions.flat_map do |session|
      session.test_results.send(type).map do |line|
        line.sub(/ok/, "ok [#{session}]")
      end
    end
  end

  def to_s
    lines = ["1..#{total}"] + lines(:failures) + lines(:passes)
    lines.join("\n")
  end

  def failed?
    states.include?("failed")
  end

  private
    def sum(values)
      values.inject(0) { |sum, total| sum + total }
    end

    def totals
      all_test_results.map(&:total).compact
    end

    def states
      all_test_results.map(&:state)
    end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
blade-0.4.1 lib/blade/combined_test_results.rb
blade-0.4.0 lib/blade/combined_test_results.rb
blade-0.3.2 lib/blade/combined_test_results.rb
blade-0.3.1 lib/blade/combined_test_results.rb