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
- #owner_tag ⇒ 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.
26 27 28 29 30 31 32 |
# File 'lib/rspec_profiling/example.rb', line 26 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.
78 79 80 |
# File 'lib/rspec_profiling/example.rb', line 78 def event_counts @event_counts end |
#event_events ⇒ Object (readonly)
Returns the value of attribute event_events.
78 79 80 |
# File 'lib/rspec_profiling/example.rb', line 78 def event_events @event_events end |
#event_times ⇒ Object (readonly)
Returns the value of attribute event_times.
78 79 80 |
# File 'lib/rspec_profiling/example.rb', line 78 def event_times @event_times end |
Instance Method Details
#description ⇒ Object
42 43 44 |
# File 'lib/rspec_profiling/example.rb', line 42 def description [:full_description] end |
#exception ⇒ Object
50 51 52 |
# File 'lib/rspec_profiling/example.rb', line 50 def exception execution_result.exception end |
#file ⇒ Object
34 35 36 |
# File 'lib/rspec_profiling/example.rb', line 34 def file [:file_path] end |
#line_number ⇒ Object
38 39 40 |
# File 'lib/rspec_profiling/example.rb', line 38 def line_number [:line_number] end |
#log_event(event_name, event, start, finish) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/rspec_profiling/example.rb', line 92 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
80 81 82 83 84 85 |
# File 'lib/rspec_profiling/example.rb', line 80 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
87 88 89 90 |
# File 'lib/rspec_profiling/example.rb', line 87 def log_request(request, start, finish) counts[:request_count] += 1 counts[:request_time] += request[:view_runtime].to_f end |
#owner_tag ⇒ Object
58 59 60 |
# File 'lib/rspec_profiling/example.rb', line 58 def owner_tag ownership_for_file([:file_path]) end |
#query_count ⇒ Object
62 63 64 |
# File 'lib/rspec_profiling/example.rb', line 62 def query_count counts[:query_count] end |
#query_time ⇒ Object
66 67 68 |
# File 'lib/rspec_profiling/example.rb', line 66 def query_time counts[:query_time] end |
#request_count ⇒ Object
70 71 72 |
# File 'lib/rspec_profiling/example.rb', line 70 def request_count counts[:request_count] end |
#request_time ⇒ Object
74 75 76 |
# File 'lib/rspec_profiling/example.rb', line 74 def request_time counts[:request_time] end |
#status ⇒ Object
46 47 48 |
# File 'lib/rspec_profiling/example.rb', line 46 def status execution_result.status end |
#time ⇒ Object
54 55 56 |
# File 'lib/rspec_profiling/example.rb', line 54 def time execution_result.run_time end |