sidekiq-amigo 1.13.0 → 1.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70bb0febcaf8c1a36e19fc4dd56fb766be4fa046c941b1f2aa66b7dcf5372872
4
- data.tar.gz: 620b2c3a6bf664931eb8a6e84cc7d8762597f4aae91aa17765bc1d1fb0b432ad
3
+ metadata.gz: c75430ea4c493cfee46c6de0daf1e64b8a6bea0e17017524dc2bc540bf7f30b2
4
+ data.tar.gz: 3bd32447b4f3d52f3512570bb3af6d5cab2643619bc83c9e95c17c0fa66418a3
5
5
  SHA512:
6
- metadata.gz: 20bcdab3b140069cd0eeb6a559032e8e4d986ffdc6bdd7ed03030a45b5b83a50600bb7d465736a0a7dcdd2e369a2a054bb2f968a77111ec5cef807876d19d8f0
7
- data.tar.gz: ddbb6ac910db1687c6e5f471f965d2b5f2dc78b650564f28c24153e8ce1d1d7b350f03da4b0571673084865ac8c9c5f9a27453e090ad94f6b12f9507649dde6d
6
+ metadata.gz: 6fa8f511ead61d4a89473fdf3eef6ed58299219e98d8172098beddbda6b73ba19822c777536f924986940bac0787382b3752f1fd921405793f14dc8307ce9897
7
+ data.tar.gz: ca0f43716e1067f606956d14b3db8457115e57d1732c181d0006491c979b440058c8d256e3d0da5f242c99409d14392169d3d78717c6544dc8423cf3bfe94cf2
@@ -72,7 +72,7 @@ module Amigo
72
72
  true
73
73
  end
74
74
 
75
- def matches?(given_proc)
75
+ def matches?(given_proc, negative_expectation=false)
76
76
  unless given_proc.respond_to?(:call)
77
77
  warn "publish matcher used with non-proc object #{given_proc.inspect}"
78
78
  return false
@@ -88,24 +88,41 @@ module Amigo
88
88
  given_proc.call
89
89
  end
90
90
 
91
- self.match_expected_events
91
+ self.match_expected_events(negative_expectation)
92
92
 
93
93
  return @error.nil? && @missing.empty?
94
94
  end
95
95
 
96
+ # rubocop:disable Naming/PredicatePrefix
97
+ def does_not_match?(given_proc)
98
+ !matches?(given_proc, true)
99
+ end
100
+ # rubocop:enable Naming/PredicatePrefix
101
+
96
102
  def on_publish_error(err)
97
103
  @error = err
98
104
  end
99
105
 
100
- def match_expected_events
106
+ def match_expected_events(negative_expectation)
101
107
  @expected_events.each do |expected_event, expected_payload|
108
+ if expected_event.nil? && !negative_expectation
109
+ RSpec::Expectations.configuration.false_positives_handler.call(
110
+ "Using the `publish` matcher without providing a specific " \
111
+ "event name risks false positives, since `publish` " \
112
+ "will match any event. Instead, provide the name " \
113
+ "of the event you are matching against."\
114
+ "This message can be suppressed by setting: " \
115
+ "`RSpec::Expectations.configuration.on_potential_false" \
116
+ "_positives = :nothing`",
117
+ )
118
+ end
102
119
  match = @recorded_events.find do |recorded|
103
120
  self.event_names_match?(expected_event, recorded.name) &&
104
121
  self.payloads_match?(expected_payload, recorded.payload)
105
122
  end
106
123
 
107
124
  if match
108
- self.add_matched(expected_event, expected_payload)
125
+ self.add_matched(expected_event, expected_payload, match)
109
126
  else
110
127
  self.add_missing(expected_event, expected_payload)
111
128
  end
@@ -113,6 +130,7 @@ module Amigo
113
130
  end
114
131
 
115
132
  def event_names_match?(expected, actual)
133
+ return true if expected.nil?
116
134
  return expected.matches?(actual) if expected.respond_to?(:matches?)
117
135
  return expected.match?(actual) if expected.respond_to?(:match?)
118
136
  return expected == actual
@@ -123,8 +141,8 @@ module Amigo
123
141
  return expected.nil? || expected.empty? || expected == actual
124
142
  end
125
143
 
126
- def add_matched(event, payload)
127
- @matched << [event, payload]
144
+ def add_matched(topic, payload, event)
145
+ @matched << [topic, payload, event]
128
146
  end
129
147
 
130
148
  def add_missing(event, payload)
@@ -156,10 +174,12 @@ module Amigo
156
174
 
157
175
  def failure_message_when_negated
158
176
  messages = []
159
- @matched.each do |event, _payload|
160
- message = "expected a '%s' event not to be fired" % [event]
161
- message << (" with a payload of %p" % [@expected_payload]) if @expected_payload
162
- message << " but one was."
177
+ @matched.each do |topic, payload, event|
178
+ message = "expected a '#{topic || event.name}' event not to be fired"
179
+ message << " with a payload of #{payload.inspect}" if payload
180
+ message << " but one was"
181
+ event.payload.any? && message << ": #{event.payload.inspect}"
182
+ message << "."
163
183
  messages << message
164
184
  end
165
185
 
data/lib/amigo/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Amigo
4
- VERSION = "1.13.0"
4
+ VERSION = "1.13.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-amigo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.0
4
+ version: 1.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lithic Technology