Class: RspecProfiling::Example
- Inherits:
-
Object
- Object
- RspecProfiling::Example
- 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
-
#event_counts ⇒ Object
readonly
Returns the value of attribute event_counts.
-
#event_events ⇒ Object
readonly
Returns the value of attribute event_events.
-
#event_times ⇒ Object
readonly
Returns the value of attribute event_times.
Instance Method Summary collapse
- #description ⇒ Object
- #exception ⇒ Object
- #file ⇒ Object
-
#initialize(example) ⇒ Example
constructor
A new instance of Example.
- #line_number ⇒ Object
- #log_event(event_name, event, start, finish) ⇒ Object
- #log_query(query, start, finish) ⇒ Object
- #log_request(request, start, finish) ⇒ Object
- #query_count ⇒ Object
- #query_time ⇒ Object
- #request_count ⇒ Object
- #request_time ⇒ Object
- #status ⇒ Object
- #time ⇒ Object
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_counts ⇒ Object (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_events ⇒ Object (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_times ⇒ Object (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
#description ⇒ Object
37 38 39 |
# File 'lib/rspec_profiling/example.rb', line 37 def description [:full_description] end |
#exception ⇒ Object
45 46 47 |
# File 'lib/rspec_profiling/example.rb', line 45 def exception execution_result.exception end |
#file ⇒ Object
29 30 31 |
# File 'lib/rspec_profiling/example.rb', line 29 def file [:file_path] end |
#line_number ⇒ Object
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_count ⇒ Object
53 54 55 |
# File 'lib/rspec_profiling/example.rb', line 53 def query_count counts[:query_count] end |
#query_time ⇒ Object
57 58 59 |
# File 'lib/rspec_profiling/example.rb', line 57 def query_time counts[:query_time] end |
#request_count ⇒ Object
61 62 63 |
# File 'lib/rspec_profiling/example.rb', line 61 def request_count counts[:request_count] end |
#request_time ⇒ Object
65 66 67 |
# File 'lib/rspec_profiling/example.rb', line 65 def request_time counts[:request_time] end |
#status ⇒ Object
41 42 43 |
# File 'lib/rspec_profiling/example.rb', line 41 def status execution_result.status end |
#time ⇒ Object
49 50 51 |
# File 'lib/rspec_profiling/example.rb', line 49 def time execution_result.run_time end |