Sha256: 45d5ff06cf37125be86c7a2df05fa0405d57becbbec7e84ae6ed15e8a4a8d928

Contents?: true

Size: 1.76 KB

Versions: 2

Compression:

Stored size: 1.76 KB

Contents

module ProbeDockProbe
  class TestResult
    attr_reader :key, :fingerprint, :name, :category, :tags, :tickets, :data, :duration, :message

    def initialize project, options = {}

      if !options[:fingerprint]
        raise Error, "The :fingerprint option is required (unique identifier for the test)"
      elsif !options[:name]
        raise Error, "The :name option is required (human-friendly identifier for the test, not necessarily unique)"
      elsif !options.key?(:passed)
        raise Error, "The :passed option is required (indicates whether the test passed or not)"
      elsif !options[:duration]
        raise Error, "The :duration options is required (indicates how long it took to run the test)"
      end

      @key = options[:key]
      @fingerprint = options[:fingerprint]
      @name = options[:name].to_s

      @category = options[:category] || project.category
      @tags = (wrap(options[:tags]) + wrap(project.tags)).compact.collect(&:to_s).uniq
      @tickets = (wrap(options[:tickets]) + wrap(project.tickets)).compact.collect(&:to_s).uniq

      @passed = !!options[:passed]
      @duration = options[:duration]
      @message = options[:message]

      @data = options[:data] || {}
      @data = @data.deep_stringify_keys if @data.respond_to? :deep_stringify_keys
    end

    def passed?
      @passed
    end

    def to_h options = {}
      {
        'f' => @fingerprint,
        'p' => @passed,
        'd' => @duration
      }.tap do |h|
        h['k'] = @key if @key
        h['m'] = @message if @message
        h['n'] = @name.length > 255 ? "#{@name[0, 252]}..." : @name
        h['c'] = @category
        h['g'] = @tags
        h['t'] = @tickets
        h['a'] = @data
      end
    end

    def wrap a
      a.kind_of?(Array) ? a : [ a ]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
probedock-ruby-0.1.4 lib/probe_dock_ruby/test_result.rb
probedock-ruby-0.1.3 lib/probe_dock_ruby/test_result.rb