db-query-matchers 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b13241f75531009aac9480f467cf9849bdd5662e
4
- data.tar.gz: 5a376d1a5644be97711acf93e80a54ffee517b2b
3
+ metadata.gz: 925bff06ef9935be2331dd9b77a65ad752562f48
4
+ data.tar.gz: 360c88c71a9579b16962bba539feee9100deeaba
5
5
  SHA512:
6
- metadata.gz: bf6a832bb56db03a4a6d65fd4e637307511a891ddf3a0686afeb9b6383bd43bc37fd6bd64273f8e8f9c88ad9abf7356c141fab4b78a793158284a2e1386aece7
7
- data.tar.gz: bdf68f005f05a44b2b4e55777df4aff4ab7eadcdc287def9d54e9dc42e344b8d0e157732a8fd6806e63d70a98f317f19f671c8cce6654b6b4c4712cde00582ff
6
+ metadata.gz: f07ed0ee62f115735a0d446c2e5274e5104fc60987bf733ff0d45e74e3acb6d7c945e7f290bb3e86e4d72335daa9bb198fa8fefb8a5261e94089bf132adc3393
7
+ data.tar.gz: fd6999559fee12c8d1e6c1941c8e79bf3f0e29cd4ecb0f7b9ce20c2b3fdb7e895b692e50a2772554416b3c7f46d017e44ad3509c8d02ecc45a9e9e00860f7dd4
@@ -1,12 +1,14 @@
1
1
  module DBQueryMatchers
2
2
  # Configuration for the DBQueryMatcher module.
3
3
  class Configuration
4
- attr_accessor :ignores, :on_query_counted, :schemaless
4
+ attr_accessor :ignores, :on_query_counted, :schemaless, :log_backtrace, :backtrace_filter
5
5
 
6
6
  def initialize
7
7
  @ignores = []
8
8
  @on_query_counted = Proc.new { }
9
9
  @schemaless = false
10
+ @log_backtrace = false
11
+ @backtrace_filter = Proc.new { |backtrace| backtrace }
10
12
  end
11
13
  end
12
14
  end
@@ -69,8 +69,8 @@ RSpec::Matchers.define :make_database_queries do |options = {}|
69
69
 
70
70
  failure_message_when_negated do |_|
71
71
  <<-EOS
72
- expected no queries, but #{@counter.count} were made:
73
- #{@counter.log.join("\n")}
72
+ expected no queries, but #{@counter.count} were made:
73
+ #{@counter.log.join("\n")}
74
74
  EOS
75
75
  end
76
76
 
@@ -42,8 +42,10 @@ module DBQueryMatchers
42
42
  return if @matches && !any_match?(@matches, payload[:sql])
43
43
  return if any_match?(DBQueryMatchers.configuration.ignores, payload[:sql])
44
44
  return if DBQueryMatchers.configuration.schemaless && payload[:name] == "SCHEMA"
45
- @count += 1
46
- @log << payload[:sql]
45
+
46
+ count_query
47
+ log_query(payload[:sql])
48
+
47
49
  DBQueryMatchers.configuration.on_query_counted.call(payload)
48
50
  end
49
51
 
@@ -52,5 +54,21 @@ module DBQueryMatchers
52
54
  def any_match?(patterns, sql)
53
55
  patterns.any? { |pattern| sql =~ pattern }
54
56
  end
57
+
58
+ def count_query
59
+ @count += 1
60
+ end
61
+
62
+ def log_query(sql)
63
+ log_entry = sql.strip
64
+
65
+ if DBQueryMatchers.configuration.log_backtrace
66
+ raw_backtrace = caller
67
+ filtered_backtrace = DBQueryMatchers.configuration.backtrace_filter.call(raw_backtrace)
68
+ log_entry += "\n#{filtered_backtrace.join("\n")}\n"
69
+ end
70
+
71
+ @log << log_entry
72
+ end
55
73
  end
56
74
  end
@@ -1,4 +1,4 @@
1
1
  # Defines the gem version.
2
2
  module DBQueryMatchers
3
- VERSION = '0.5.0'
3
+ VERSION = '0.6.0'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db-query-matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brigade Engineering
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-05-10 00:00:00.000000000 Z
13
+ date: 2016-07-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec