class RSpec::Core::Formatters::APIFormatter

Attributes

output_hash[R]
yaml_hash[R]

Public Class Methods

new(output) click to toggle source
Calls superclass method
# File lib/g5kchecks/rspec/core/formatters/api_formatter.rb, line 12
def initialize(output)
  super
  @output_hash = {}
  @yaml_hash = Hash.new
end

Public Instance Methods

add_to_yaml_hash(array, value, hash) click to toggle source
# File lib/g5kchecks/rspec/core/formatters/api_formatter.rb, line 55
def add_to_yaml_hash(array, value, hash)
  value = value.encode(Encoding.default_external)
  if array.size == 1
    tmp = array[0].encode(Encoding.default_external)
    hash[tmp] = Utils.string_to_object(value)
    return hash
  else
    tmp = Utils.string_to_object(array.delete_at(0).encode(Encoding.default_external))
    if hash[tmp]
      add_to_yaml_hash(array,value, hash[tmp])
    else
      hash[tmp] = add_to_yaml_hash(array,value, Hash.new)
      return hash
    end
  end
end
close() click to toggle source
# File lib/g5kchecks/rspec/core/formatters/api_formatter.rb, line 46
def close
  File.open(File.join("/tmp/",RSpec.configuration.node.hostname + ".yaml"), 'w' ) { |f|
    f.puts @yaml_hash.to_yaml
  }
  File.open(File.join("/tmp/",RSpec.configuration.node.hostname + ".json"), 'w' ) { |f|
    f.puts @yaml_hash.to_json
  }
end
message(message) click to toggle source
# File lib/g5kchecks/rspec/core/formatters/api_formatter.rb, line 18
def message(message)
  (@output_hash[:messages] ||= []) << message
end
stop() click to toggle source
Calls superclass method
# File lib/g5kchecks/rspec/core/formatters/api_formatter.rb, line 22
def stop
  super
  @output_hash[:examples] = examples.each do |example|
    if e=example.exception
      array = e.message.split("\n")[0].split(', ')
      if array.size > 1
        index_empty_position = array.index("")
        if index_empty_position.nil?
          index_empty_position = array.index("0")
        end
        if not index_empty_position.nil?
          value_str = array.slice(0, index_empty_position).join(" ")
          path = array.slice(index_empty_position + 1, array.length)
          if path[0] == ""
            # Remove an empty string from the path
            path.delete_at(0)
          end
          add_to_yaml_hash(path, value_str, @yaml_hash)
        end
      end
    end
  end
end