Sha256: 6ef14e96ee2ee8135bcfa263dc4a2a5d505430e75aee1838221a75d7933b836d

Contents?: true

Size: 1.65 KB

Versions: 2

Compression:

Stored size: 1.65 KB

Contents

module Crucible
  module Tests
    class TestResult

      attr_accessor :key
      attr_accessor :id
      attr_accessor :description
      attr_accessor :status
      attr_accessor :message
      attr_accessor :data
      attr_accessor :warnings
      attr_accessor :requires
      attr_accessor :validates
      attr_accessor :links
      attr_accessor :code

      def initialize(key, description, status, message, data)
        @key = key
        @status = status
        @description = description
        @message = message
        @data = data
      end

      def update(status, message, data)
        @status = status
        @message = message
        @data = data
        self
      end

      def passed?
        return ( (@status==true) or (@status=='passed') )
      end

      def failed?
        !self.passed?
      end

      def to_hash
        hash = {}
        hash['key'] = @key
        hash['id'] = @id || @key
        hash['description'] = force_encoding(@description)
        hash['status'] = force_encoding(@status)
        if @message.class == Array
          hash['message'] = @message.map { |m| force_encoding(m) }
        else
          hash['message'] = force_encoding(@message)
        end
        hash['data'] = force_encoding(@data) unless hash['status'] == 'pass'
        hash['warnings'] = warnings if warnings
        hash['requires'] = requires if requires
        hash['validates'] = validates if validates
        hash['links'] = links if links
        hash['code'] = @code
        hash
      end

      private

      def force_encoding(value)
        return nil if value.blank?
        value.force_encoding("UTF-8")
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
plan_executor-1.8.0 lib/test_result.rb
plan_executor-1.0.2 lib/test_result.rb