Class: RspecProfiling::Example

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_profiling/example.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(example) ⇒ Example

Returns a new instance of Example.



21
22
23
24
25
26
27
# File 'lib/rspec_profiling/example.rb', line 21

def initialize(example)
  @example = example
  @counts  = Hash.new(0)
  @event_counts = Hash.new(0)
  @event_times = Hash.new(0)
  @event_events = Hash.new()
end

Instance Attribute Details

#event_countsObject (readonly)

Returns the value of attribute event_counts.



69
70
71
# File 'lib/rspec_profiling/example.rb', line 69

def event_counts
  @event_counts
end

#event_eventsObject (readonly)

Returns the value of attribute event_events.



69
70
71
# File 'lib/rspec_profiling/example.rb', line 69

def event_events
  @event_events
end

#event_timesObject (readonly)

Returns the value of attribute event_times.



69
70
71
# File 'lib/rspec_profiling/example.rb', line 69

def event_times
  @event_times
end

Instance Method Details

#descriptionObject



37
38
39
# File 'lib/rspec_profiling/example.rb', line 37

def description
  [:full_description]
end

#exceptionObject



45
46
47
# File 'lib/rspec_profiling/example.rb', line 45

def exception
  execution_result.exception
end

#fileObject



29
30
31
# File 'lib/rspec_profiling/example.rb', line 29

def file
  [:file_path]
end

#line_numberObject



33
34
35
# File 'lib/rspec_profiling/example.rb', line 33

def line_number
  [:line_number]
end

#log_event(event_name, event, start, finish) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rspec_profiling/example.rb', line 83

def log_event(event_name, event, start, finish)
  event_counts[event_name] += 1
  event_times[event_name] += (finish - start)
  event_events[event_name] ||= []
  if verbose_record_event?(event_name)
    begin
      event_events[event_name] << event.as_json
    rescue => e
      # no op
    end
  end
end

#log_query(query, start, finish) ⇒ Object



71
72
73
74
75
76
# File 'lib/rspec_profiling/example.rb', line 71

def log_query(query, start, finish)
  unless query[:sql] =~ IGNORED_QUERIES_PATTERN
    counts[:query_count] += 1
    counts[:query_time] += (finish - start)
  end
end

#log_request(request, start, finish) ⇒ Object



78
79
80
81
# File 'lib/rspec_profiling/example.rb', line 78

def log_request(request, start, finish)
  counts[:request_count] += 1
  counts[:request_time] += request[:view_runtime].to_f
end

#query_countObject



53
54
55
# File 'lib/rspec_profiling/example.rb', line 53

def query_count
  counts[:query_count]
end

#query_timeObject



57
58
59
# File 'lib/rspec_profiling/example.rb', line 57

def query_time
  counts[:query_time]
end

#request_countObject



61
62
63
# File 'lib/rspec_profiling/example.rb', line 61

def request_count
  counts[:request_count]
end

#request_timeObject



65
66
67
# File 'lib/rspec_profiling/example.rb', line 65

def request_time
  counts[:request_time]
end

#statusObject



41
42
43
# File 'lib/rspec_profiling/example.rb', line 41

def status
  execution_result.status
end

#timeObject



49
50
51
# File 'lib/rspec_profiling/example.rb', line 49

def time
  execution_result.run_time
end