RSpec::Matchers.define:make_queries_matchingdo|matcher,expected_count=nil|supports_block_expectationsmatchdo|block|@counter=query_count(matcher,&block)ifexpected_count@counter.count==expected_countelse@counter.count>0endendfailure_message_when_negateddo|_|ifexpected_count"expected #{matcher} not to match #{expected_count} queries, got #{@counter.count} matches:\n\n#{@counter.inspect}"else"expected #{matcher} not to match any query, got #{@counter.count} matches:\n\n#{@counter.inspect}"endendfailure_messagedo|_|ifexpected_count"expected #{matcher} to match #{expected_count} queries, got #{@counter.count} matches:\n\n#{@counter.inspect}"else"expected #{matcher} to match at least one query, got #{@counter.count} matches:\n\n#{@counter.inspect}"endenddefquery_count(regex,&block)@recorder=ActiveRecord::QueryRecorder.new(&block).log@recorder.select{|q|q.match(regex)}endend