Class: Sidekiq::Sorbet::RSpec::Matchers::HaveArgs
- Inherits:
-
Object
- Object
- Sidekiq::Sorbet::RSpec::Matchers::HaveArgs
- Defined in:
- lib/sidekiq/sorbet/rspec/matchers.rb
Overview
Matcher for validating multiple arguments at once
Instance Method Summary collapse
-
#and_arg(field_name, expected_type) ⇒ HaveArgs
Chain to add additional argument checks.
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(args_hash_or_field = nil, expected_type = nil) ⇒ HaveArgs
constructor
A new instance of HaveArgs.
- #matches?(worker_class) ⇒ Boolean
Constructor Details
#initialize(args_hash_or_field = nil, expected_type = nil) ⇒ HaveArgs
Returns a new instance of HaveArgs.
125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/sidekiq/sorbet/rspec/matchers.rb', line 125 def initialize(args_hash_or_field = nil, expected_type = nil) @args_to_check = [] if args_hash_or_field.is_a?(Hash) args_hash_or_field.each do |field_name, type| @args_to_check << [field_name, type] end elsif args_hash_or_field.is_a?(Symbol) @args_to_check << [args_hash_or_field, expected_type] end end |
Instance Method Details
#and_arg(field_name, expected_type) ⇒ HaveArgs
Chain to add additional argument checks
142 143 144 145 |
# File 'lib/sidekiq/sorbet/rspec/matchers.rb', line 142 def and_arg(field_name, expected_type) @args_to_check << [field_name, expected_type] self end |
#description ⇒ Object
169 170 171 172 |
# File 'lib/sidekiq/sorbet/rspec/matchers.rb', line 169 def description args_desc = @args_to_check.map { |name, type| "#{name}: #{type}" }.join(", ") "have arguments: #{args_desc}" end |
#failure_message ⇒ Object
161 162 163 |
# File 'lib/sidekiq/sorbet/rspec/matchers.rb', line 161 def @failure_message || "expected #{@actual} to have the specified arguments" end |
#failure_message_when_negated ⇒ Object
165 166 167 |
# File 'lib/sidekiq/sorbet/rspec/matchers.rb', line 165 def "expected #{@actual}::Args not to have the specified arguments" end |
#matches?(worker_class) ⇒ Boolean
147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/sidekiq/sorbet/rspec/matchers.rb', line 147 def matches?(worker_class) @actual = worker_class @args_to_check.each do |field_name, expected_type| matcher = HaveArg.new(field_name, expected_type) unless matcher.matches?(worker_class) @failure_message = matcher. return false end end true end |