class QUnited::QUnitTestResult

Contains results data from a QUnit JavaScript test. Useful for passing data to formatters.

Attributes

data[RW]

Public Class Methods

from_json(json) click to toggle source
# File lib/qunited/qunit_test_result.rb, line 38
def self.from_json(json)
  self.new clean_up_result(::YAML.load(json))
end
new(test_data) click to toggle source
# File lib/qunited/qunit_test_result.rb, line 44
def initialize(test_data)
  @data = test_data
end

Private Class Methods

clean_up_result(test_result) click to toggle source

Turn String keys into Symbols and convert Strings representing dates and numbers into their appropriate objects.

# File lib/qunited/qunit_test_result.rb, line 74
def self.clean_up_result(test_result)
  test_result = symbolize_keys(test_result)
  test_result[:start] = DateTime.parse(test_result[:start])
  test_result
end
symbolize_keys(obj) click to toggle source
# File lib/qunited/qunit_test_result.rb, line 80
def self.symbolize_keys(obj)
  case obj
  when Hash
    obj.inject({}) do |new_hash, (key, value)|
      new_hash[key.to_sym] = symbolize_keys(value)
      new_hash
    end
  when Array
    obj.map { |x| symbolize_keys(x) }
  else
    obj
  end
end

Public Instance Methods

assertions() click to toggle source
# File lib/qunited/qunit_test_result.rb, line 60
def assertions
  @assertions ||= data[:assertion_data].map { |assertion_data| AssertionResult.new assertion_data }
end
error?() click to toggle source
# File lib/qunited/qunit_test_result.rb, line 50
def error?;  result == :error end
failed?() click to toggle source
# File lib/qunited/qunit_test_result.rb, line 49
def failed?; result == :failed end
passed?() click to toggle source
# File lib/qunited/qunit_test_result.rb, line 48
def passed?; result == :passed end
result() click to toggle source
# File lib/qunited/qunit_test_result.rb, line 52
def result
  @result ||= if assertions.find { |a| a.error? }
    :error
  else
    assertions.find { |a| a.failed? } ? :failed : :passed
  end
end