jasmine-headless-webkit/lib/jasmine/headless/report.rb

57 lines
1.1 KiB
Ruby
Raw Normal View History

require 'forwardable'
module Jasmine::Headless
class Report
extend Forwardable
def_delegators :report, :length, :[]
2011-09-03 11:54:52 +00:00
def_delegators :last_total, :total, :failed, :time
class << self
def load(file)
new(file).process
end
end
attr_reader :file, :report
def initialize(file)
@file = file
end
def process
@report = File.readlines(file).collect do |line|
type, *parts = line.split('||')
Jasmine::Headless::ReportMessage.const_get(
Jasmine::Headless::ReportMessage.constants.find { |k| k.to_s.downcase == type.downcase }
).new_from_parts(parts)
end
self
end
def has_used_console?
@report.any? { |entry| entry.class == Jasmine::Headless::ReportMessage::Console }
end
def has_failed_on?(statement)
@report.any? { |entry|
if entry.class == Jasmine::Headless::ReportMessage::Fail
entry.statement == statement
end
}
end
2011-09-03 11:54:52 +00:00
def valid?
last_total != nil
end
private
def last_total
@report.reverse.find { |entry| entry.respond_to?(:total) }
end
end
end