Sha256: d46d2921bad276c53ce62468f9fcdfafae980396f22e17c654f54dcabcc15152

Contents?: true

Size: 1.57 KB

Versions: 35

Compression:

Stored size: 1.57 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

  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 query[:sql] =~ IGNORED_QUERIES_PATTERN

    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 ||= begin
      if example.execution_result.is_a?(Hash)
        OpenStruct.new(example.execution_result)
      else
        example.execution_result
      end
    end
  end
end
end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
rspeckled-1.3.0 lib/rspeckled/reporting/example.rb
rspeckled-1.2.1 lib/rspeckled/reporting/example.rb
rspeckled-1.2.0 lib/rspeckled/reporting/example.rb
rspeckled-1.1.3 lib/rspeckled/reporting/example.rb
rspeckled-1.1.2 lib/rspeckled/reporting/example.rb
rspeckled-1.1.1 lib/rspeckled/reporting/example.rb
rspeckled-1.1.0 lib/rspeckled/reporting/example.rb
rspeckled-1.0.5 lib/rspeckled/reporting/example.rb
rspeckled-1.0.4 lib/rspeckled/reporting/example.rb
rspeckled-1.0.3 lib/rspeckled/reporting/example.rb
rspeckled-1.0.2 lib/rspeckled/reporting/example.rb
rspeckled-1.0.1 lib/rspeckled/reporting/example.rb
rspeckled-1.0.0 lib/rspeckled/reporting/example.rb
rspeckled-0.0.64 lib/rspeckled/reporting/example.rb
rspeckled-0.0.63 lib/rspeckled/reporting/example.rb
rspeckled-0.0.62 lib/rspeckled/reporting/example.rb
rspeckled-0.0.61 lib/rspeckled/reporting/example.rb
rspeckled-0.0.60 lib/rspeckled/reporting/example.rb
rspeckled-0.0.59 lib/rspeckled/reporting/example.rb
rspeckled-0.0.58 lib/rspeckled/reporting/example.rb