warning_signs 0.1.0 → 0.3.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
  SHA256:
3
- metadata.gz: f982e2333c10256fd6056e6cf26208949d18721a98d5fbb1bdf7c7de19092856
4
- data.tar.gz: ab14c9f2b8116c49c5b711d5dfc651285cccd004c11b82acef60505505412ca3
3
+ metadata.gz: d5dd43f86a3822293460f2d79efb2c2e98a5cb6a86ca5b85a3d762b4e9b82a8e
4
+ data.tar.gz: 9dd3da0dbd012564356f1c477038f9cd5b00652149c064aea4006224b408940f
5
5
  SHA512:
6
- metadata.gz: 11ea7552143006ab573fa74211b7306eedd136f7a738887a8ff16f51965d4c1778f2e7af8a2f152d1787b05644a684848e0f3efe6fdd600baeed20a0e1d9f6d4
7
- data.tar.gz: 3536a9efdbc5ce68a0fa6243c456df00c8cfba30e8d523614173aa97a98c2bea6d4e7078f4b541ac2fa32ea925c09aac224dcd95f5d5ed9eeca63944a7b3432b
6
+ metadata.gz: 4e73a2bc35a1283b56061fad2717c6b0c9ce19f91c34b81645bf57c9e4c09eee2f93f727529c107a54c2e47fa6a8d88b9958af522b3a12929d18f505924b734f
7
+ data.tar.gz: eb2050074df9f17103a57ebbf506cba97a9f0a4b17d82db8b968c359751edbb8787033c708d19b5bb2e2b57b49346f138576f9cd98552cca80f12578d4ce908a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 0.3.0
2
+
3
+ * Allow multiple behaviors in a single environment
4
+ * Allow only and except matchers to be regular expressions
5
+
6
+ ## 0.2.0
7
+
8
+ * Test for "other environment"
9
+
1
10
  ## 0.1.0
2
11
 
3
12
  * Smarter caller information for Ruby warnings
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- warning_signs (0.1.0)
4
+ warning_signs (0.3.0)
5
5
  awesome_print
6
6
  railties
7
7
 
data/README.md CHANGED
@@ -83,6 +83,21 @@ handlers:
83
83
  behavior: ignore
84
84
  ```
85
85
 
86
+ A single environment can have multiple behaviors. This is helpful if you are,
87
+ say dealing with end-to-end specs that swallow exceptions:
88
+
89
+ ```yaml
90
+ handlers:
91
+ - environment: all
92
+ behaviors:
93
+ - raise
94
+ - log
95
+ ```
96
+
97
+ No matter what order you have the behaviors in, a `raise` behavior will be
98
+ executed last so that the other behaviors happen before the exception is
99
+ invoked.
100
+
86
101
  A common pattern is to focus only on specific deprecations and ignore others.
87
102
  For example, this setting file would raise on Ruby keyword argument
88
103
  deprecations and ignore other ruby deprecations
@@ -99,7 +114,22 @@ handlers:
99
114
  ```
100
115
 
101
116
  Patterns are matched if the deprecation message contains the pattern as a
102
- substring
117
+ substring.
118
+
119
+ The pattern can be a regular expression, denoted by using regular expression
120
+ syntax _inside_ the string in the YAML:
121
+
122
+ ```yaml
123
+ handlers:
124
+ - source: ruby
125
+ only:
126
+ - "/Using .* argument/"
127
+ environment: all
128
+ behavior: log
129
+ ```
130
+
131
+ The pattern inside the slashes is converted to a Ruby `Regexp` and patterns
132
+ are matched if the regexp and the deprecation warning message match.
103
133
 
104
134
  Another pattern is to have a list of ignored deprecations and then remove
105
135
  messages one by one and manage them individually.
@@ -11,18 +11,23 @@ module WarningSigns
11
11
  World.instance.handler_for(self)
12
12
  end
13
13
 
14
- def behavior
15
- handler&.environment&.behavior
14
+ # force raise to be the last element if it is present
15
+ def behaviors
16
+ result = (handler&.environment&.behaviors || []).inquiry
17
+ return result if !result.raise?
18
+ (result - ["raise"]) << "raise"
16
19
  end
17
20
 
18
21
  def invoke
19
- case behavior
20
- when "raise"
21
- raise UnhandledDeprecationError, message
22
- when "log"
23
- Rails.logger.warn(message)
24
- when "stderr"
25
- $stderr.puts(message) # standard:disable Style/StderrPuts
22
+ behaviors.each do |behavior|
23
+ case behavior
24
+ when "raise"
25
+ raise UnhandledDeprecationError, message
26
+ when "log"
27
+ Rails.logger.warn(message)
28
+ when "stderr"
29
+ $stderr.puts(message) # standard:disable Style/StderrPuts
30
+ end
26
31
  end
27
32
  end
28
33
  end
@@ -1,10 +1,12 @@
1
1
  module WarningSigns
2
2
  class Environment
3
- attr_accessor :environment, :behavior
3
+ attr_accessor :environment, :behaviors
4
4
 
5
- def initialize(environment:, behavior:)
5
+ def initialize(environment:, behaviors: [], behavior: nil)
6
6
  @environment = environment.to_s.downcase.inquiry
7
- @behavior = behavior.to_s.downcase.inquiry
7
+ @behaviors = (behaviors + [behavior])
8
+ .compact
9
+ .map { _1.to_s.downcase.inquiry }
8
10
  end
9
11
  end
10
12
  end
@@ -1,25 +1,25 @@
1
1
  module WarningSigns
2
2
  class Handler
3
- attr_accessor :behavior, :environments, :except, :only, :source
3
+ attr_accessor :environments, :except, :only, :source
4
4
 
5
5
  def self.from_hash(hash)
6
6
  new(**hash.symbolize_keys)
7
7
  end
8
8
 
9
9
  def initialize(
10
- behavior: "ignore",
10
+ behavior: nil,
11
+ behaviors: [],
11
12
  environment: nil,
12
13
  except: [],
13
14
  only: [],
14
15
  source: "any",
15
16
  environments: []
16
17
  )
17
- @behavior = behavior.to_s.downcase.inquiry
18
- @except = except
19
- @only = only
18
+ @except = except.map { Pattern.for(_1) }
19
+ @only = only.map { Pattern.for(_1) }
20
20
  @environments = environments.map { Environment.new(**_1.symbolize_keys) }
21
21
  if environment.present?
22
- @environments << Environment.new(environment: environment, behavior: behavior)
22
+ @environments << Environment.new(environment: environment, behaviors: behaviors, behavior: behavior)
23
23
  end
24
24
  @source = source.to_s.downcase.inquiry
25
25
  raise InvalidHandlerError unless valid?
@@ -50,14 +50,14 @@ module WarningSigns
50
50
  def only_match?(message)
51
51
  return true if only.empty?
52
52
  only.any? do |only_pattern|
53
- message.include?(only_pattern)
53
+ only_pattern.match?(message)
54
54
  end
55
55
  end
56
56
 
57
57
  def except_match?(message)
58
58
  return true if except.empty?
59
- except.none? do |only_pattern|
60
- message.include?(only_pattern)
59
+ except.none? do |except_pattern|
60
+ except_pattern.match?(message)
61
61
  end
62
62
  end
63
63
 
@@ -0,0 +1,11 @@
1
+ module WarningSigns
2
+ class Pattern
3
+ def self.for(raw_pattern)
4
+ if raw_pattern.starts_with?("/") && raw_pattern.ends_with?("/")
5
+ RegexPattern.new(raw_pattern)
6
+ else
7
+ StringPattern.new(raw_pattern)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module WarningSigns
2
+ class RegexPattern
3
+ attr_accessor :pattern
4
+
5
+ def initialize(raw_pattern)
6
+ @pattern = Regexp.new(raw_pattern[1...-1])
7
+ end
8
+
9
+ def match?(message)
10
+ pattern.match?(message)
11
+ end
12
+ end
13
+ end
@@ -11,7 +11,9 @@ module WarningSigns
11
11
  def caller_location
12
12
  caller_locations.find do |location|
13
13
  !location.to_s.include?("internal:warning") &&
14
- !location.to_s.include?("warning_signs")
14
+ !location.to_s.include?("warning_signs") &&
15
+ !location.to_s.include?("rubygems") &&
16
+ !location.to_s.include?("/gems")
15
17
  end
16
18
  end
17
19
  end
@@ -0,0 +1,13 @@
1
+ module WarningSigns
2
+ class StringPattern
3
+ attr_accessor :pattern
4
+
5
+ def initialize(raw_pattern)
6
+ @pattern = raw_pattern
7
+ end
8
+
9
+ def match?(message)
10
+ message.include?(pattern)
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module WarningSigns
2
- VERSION = "0.1.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: warning_signs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noel Rappin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-04 00:00:00.000000000 Z
11
+ date: 2023-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry-byebug
@@ -173,9 +173,12 @@ files:
173
173
  - lib/warning_signs/deprecation.rb
174
174
  - lib/warning_signs/environment.rb
175
175
  - lib/warning_signs/handler.rb
176
+ - lib/warning_signs/pattern.rb
176
177
  - lib/warning_signs/rails_deprecation_catcher.rb
177
178
  - lib/warning_signs/railtie.rb
179
+ - lib/warning_signs/regex_pattern.rb
178
180
  - lib/warning_signs/ruby_deprecation_catcher.rb
181
+ - lib/warning_signs/string_pattern.rb
179
182
  - lib/warning_signs/version.rb
180
183
  - lib/warning_signs/world.rb
181
184
  - warning_signs.gemspec