Sha256: e75760d4bc5999fc2a7bfa15630a1e9d2d5304b1c9501a1c31ff7868cfa00237

Contents?: true

Size: 1.77 KB

Versions: 2

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: true

module Rspeckled
module Reporting
class  Example
  IGNORED_QUERIES_PATTERN = %r{
    (
      pg_table|
      pg_attribute|
      pg_namespace|
      show\stables|
      pragma|
      sqlite_master/rollback|
      ^TRUNCATE TABLE|
      ^ALTER TABLE|
      ^BEGIN|
      ^COMMIT|
      ^ROLLBACK|
      ^RELEASE|
      ^SAVEPOINT
    )
  }xi.freeze

  private_constant :IGNORED_QUERIES_PATTERN

  ExecutionResult = Struct.new('ExecutionResult', :status, :run_time, :exception)

  attr_accessor :counts,
                :example

  def initialize(example)
    self.counts  = Hash.new(0)
    self.example = example
  end

  def file
    metadata[:file_path]
  end

  def line_number
    metadata[:line_number]
  end

  def status
    execution_result.status
  end

  def time
    execution_result.run_time
  end

  def description
    metadata[:full_description]
  end

  def exception
    execution_result.exception
  end

  def query_count
    counts[:query_count]
  end

  def query_time
    counts[:query_time]
  end

  def request_count
    counts[:request_count]
  end

  def request_time
    counts[:request_time]
  end

  def log_query(query, start, finish)
    return if IGNORED_QUERIES_PATTERN.match?(query[:sql])

    counts[:query_count] += 1
    counts[:query_time]  += (finish - start)
  end

  def log_request(_request, start, finish)
    counts[:request_count] += 1
    counts[:request_time]  += (finish - start)
  end

  private

  def metadata
    example.metadata
  end

  def execution_result
    @execution_result ||= if example.execution_result.is_a?(::Hash)
                            ExecutionResult.new(example.execution_result)
                          else
                            example.execution_result
                          end
  end
end
end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rspeckled-2.1.1 lib/rspeckled/reporting/example.rb
rspeckled-2.1.0 lib/rspeckled/reporting/example.rb