lib/rspec/query_limit/matchers.rb in rspec-query-limit-0.1.0 vs lib/rspec/query_limit/matchers.rb in rspec-query-limit-0.1.1
- old
+ new
@@ -4,16 +4,26 @@
match do |block|
query_count(&block) == expected
end
- failure_message_for_should do |actual|
- "Expected to run exactly #{expected} queries, got #{@counter.query_count}"
- end
+ if self.respond_to?(:failure_message)
+ failure_message do |actual|
+ failure_text
+ end
- failure_message_for_should_not do |actual|
- "Expected to run other than #{expected} queries, got #{@counter.query_count}"
+ failure_message_when_negated do |actual|
+ failure_text_negated
+ end
+ else
+ failure_message_for_should do |actual|
+ failure_text
+ end
+
+ failure_message_for_should_not do |actual|
+ failure_text_negated
+ end
end
def query_count(&block)
@counter = ActiveRecord::QueryCounter.new
ActiveSupport::Notifications.subscribed(@counter.to_proc, 'sql.active_record', &block)
@@ -22,8 +32,15 @@
def supports_block_expectations?
true
end
+ def failure_text
+ "Expected to run exactly #{expected} queries, got #{@counter.query_count}"
+ end
+
+ def failure_text_negated
+ "Expected to run other than #{expected} queries, got #{@counter.query_count}"
+ end
end
end
end