Class: Sidekiq::Sorbet::RSpec::Matchers::RejectArgs
- Inherits:
-
Object
- Object
- Sidekiq::Sorbet::RSpec::Matchers::RejectArgs
- Defined in:
- lib/sidekiq/sorbet/rspec/matchers.rb
Overview
Matcher for validating that a worker rejects invalid arguments
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(args) ⇒ RejectArgs
constructor
A new instance of RejectArgs.
- #matches?(worker_class) ⇒ Boolean
-
#with_error(error_class, message_pattern = nil) ⇒ RejectArgs
Chain to specify the expected error class and optional message pattern.
Constructor Details
#initialize(args) ⇒ RejectArgs
Returns a new instance of RejectArgs.
219 220 221 222 223 |
# File 'lib/sidekiq/sorbet/rspec/matchers.rb', line 219 def initialize(args) @args = args @expected_error = nil @expected_message = nil end |
Instance Method Details
#description ⇒ Object
272 273 274 275 276 277 |
# File 'lib/sidekiq/sorbet/rspec/matchers.rb', line 272 def description desc = "reject arguments #{@args.inspect}" desc += " with #{@expected_error}" if @expected_error desc += " matching #{@expected_message.inspect}" if @expected_message desc end |
#failure_message ⇒ Object
254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/sidekiq/sorbet/rspec/matchers.rb', line 254 def if @accepted "expected #{@actual} to reject arguments #{@args.inspect}, but it accepted them" elsif @expected_error && @raised_error && !@raised_error.is_a?(@expected_error) "expected #{@actual} to raise #{@expected_error}, but raised #{@raised_error.class}" elsif @expected_message && @raised_error "expected error message to match #{@expected_message.inspect}, " \ "but was #{@raised_error..inspect}" else "unexpected state in reject_args matcher" end end |
#failure_message_when_negated ⇒ Object
267 268 269 270 |
# File 'lib/sidekiq/sorbet/rspec/matchers.rb', line 267 def "expected #{@actual} not to reject arguments #{@args.inspect}, " \ "but it raised #{@raised_error.class}" end |
#matches?(worker_class) ⇒ Boolean
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/sidekiq/sorbet/rspec/matchers.rb', line 236 def matches?(worker_class) @actual = worker_class begin worker_class.send(:build_args, **@args) @accepted = true false rescue StandardError => e @raised_error = e return false if @expected_error && !e.is_a?(@expected_error) return false if @expected_message && @raised_error. !~ @expected_message true end end |
#with_error(error_class, message_pattern = nil) ⇒ RejectArgs
Chain to specify the expected error class and optional message pattern
230 231 232 233 234 |
# File 'lib/sidekiq/sorbet/rspec/matchers.rb', line 230 def with_error(error_class, = nil) @expected_error = error_class @expected_message = self end |