Class: AndOne::RSpecHelper::CauseNPlusOne
- Inherits:
-
Object
- Object
- AndOne::RSpecHelper::CauseNPlusOne
- Defined in:
- lib/and_one/matchers.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
- #matches?(block) ⇒ Boolean
- #supports_block_expectations? ⇒ Boolean
Instance Method Details
#description ⇒ Object
109 110 111 |
# File 'lib/and_one/matchers.rb', line 109 def description "cause N+1 queries" end |
#failure_message ⇒ Object
94 95 96 |
# File 'lib/and_one/matchers.rb', line 94 def "expected the block to cause N+1 queries, but none were detected" end |
#failure_message_when_negated ⇒ Object
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/and_one/matchers.rb', line 98 def formatter = AndOne::Formatter.new( backtrace_cleaner: AndOne.backtrace_cleaner || AndOne.send(:default_backtrace_cleaner) ) detail = formatter.format(@detections) summary = @detections.map do |d| "#{d.count} queries to `#{d.table_name || "unknown"}` (expected 1)" end.join("; ") "expected no N+1 queries, but #{@detections.size} detected: #{summary}\n#{detail}" end |
#matches?(block) ⇒ Boolean
89 90 91 92 |
# File 'lib/and_one/matchers.rb', line 89 def matches?(block) @detections = scan_block(block) @detections.any? end |
#supports_block_expectations? ⇒ Boolean
85 86 87 |
# File 'lib/and_one/matchers.rb', line 85 def supports_block_expectations? true end |