Class: RSpec::Mocks::ErrorGenerator
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb
Direct Known Subclasses
Instance Attribute Summary collapse
Instance Method Summary collapse
- #default_error_message(expectation, expected_args, actual_args) ⇒ Object
- #describe_expectation(verb, message, expected_received_count, _actual_received_count, args) ⇒ Object
- #expectation_on_nil_message(method_name) ⇒ Object
-
#initialize(target = nil) ⇒ ErrorGenerator
constructor
A new instance of ErrorGenerator.
- #intro(unwrapped = false) ⇒ Object
- #method_call_args_description(args, generic_prefix = " with arguments: ", matcher_prefix = " with ") ⇒ Object
- #raise_already_invoked_error(message, calling_customization) ⇒ Object
- #raise_cant_constrain_count_for_negated_have_received_error(count_constraint) ⇒ Object
- #raise_double_negation_error(wrapped_expression) ⇒ Object
-
#raise_expectation_error(message, expected_received_count, argument_list_matcher, actual_received_count, expectation_count_type, args, backtrace_line = nil, source_id = nil) ⇒ Object
rubocop:disable Metrics/ParameterLists.
- #raise_expectation_on_mocked_method(method) ⇒ Object
- #raise_expectation_on_nil_error(method_name) ⇒ Object
- #raise_expectation_on_unstubbed_method(method) ⇒ Object
- #raise_expired_test_double_error ⇒ Object
- #raise_have_received_disallowed(type, reason) ⇒ Object
- #raise_invalid_arguments_error(verifier) ⇒ Object
- #raise_method_not_stubbed_error(method_name) ⇒ Object
- #raise_missing_block_error(args_to_yield) ⇒ Object
- #raise_missing_default_stub_error(expectation, args_for_multiple_calls) ⇒ Object
- #raise_non_public_error(method_name, visibility) ⇒ Object
- #raise_only_valid_on_a_partial_double(method) ⇒ Object
- #raise_out_of_order_error(message) ⇒ Object
- #raise_similar_message_args_error(expectation, args_for_multiple_calls, backtrace_line = nil) ⇒ Object
- #raise_unexpected_message_args_error(expectation, args_for_multiple_calls, source_id = nil) ⇒ Object
- #raise_unexpected_message_error(message, args) ⇒ Object
- #raise_unimplemented_error(doubled_module, method_name, object) ⇒ Object
- #raise_verifying_double_not_defined_error(ref) ⇒ Object
- #raise_wrong_arity_error(args_to_yield, signature) ⇒ Object
Constructor Details
#initialize(target = nil) ⇒ ErrorGenerator
Returns a new instance of ErrorGenerator.
39 40 41 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 39 def initialize(target=nil) @target = target end |
Instance Attribute Details
#opts ⇒ Object
44 45 46 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 44 def opts @opts ||= {} end |
Instance Method Details
#default_error_message(expectation, expected_args, actual_args) ⇒ Object
71 72 73 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 71 def (expectation, expected_args, actual_args) "#{intro} received #{expectation..inspect} #{(expected_args, actual_args)}".dup end |
#describe_expectation(verb, message, expected_received_count, _actual_received_count, args) ⇒ Object
132 133 134 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 132 def describe_expectation(verb, , expected_received_count, _actual_received_count, args) "#{verb} #{}#{format_args(args)} #{(expected_received_count)}" end |
#expectation_on_nil_message(method_name) ⇒ Object
215 216 217 218 219 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 215 def (method_name) "An expectation of `:#{method_name}` was set on `nil`. " \ "To allow expectations on `nil` and suppress this message, set `RSpec::Mocks.configuration.allow_message_expectations_on_nil` to `true`. " \ "To disallow expectations on `nil`, set `RSpec::Mocks.configuration.allow_message_expectations_on_nil` to `false`" end |
#intro(unwrapped = false) ⇒ Object
222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 222 def intro(unwrapped=false) case @target when TestDouble then TestDoubleFormatter.format(@target, unwrapped) when Class then formatted = "#{@target.inspect} (class)" return formatted if unwrapped "#<#{formatted}>" when NilClass then "nil" else @target.inspect end end |
#method_call_args_description(args, generic_prefix = " with arguments: ", matcher_prefix = " with ") ⇒ Object
235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 235 def method_call_args_description(args, generic_prefix=" with arguments: ", matcher_prefix=" with ") case args.first when ArgumentMatchers::AnyArgsMatcher then "#{matcher_prefix}any arguments" when ArgumentMatchers::NoArgsMatcher then "#{matcher_prefix}no arguments" else if yield "#{generic_prefix}#{format_args(args)}" else "" end end end |
#raise_already_invoked_error(message, calling_customization) ⇒ Object
203 204 205 206 207 208 209 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 203 def raise_already_invoked_error(, calling_customization) = "The message expectation for #{intro}.#{} has already been invoked " \ "and cannot be modified further (e.g. using `#{calling_customization}`). All message expectation " \ "customizations must be applied before it is used for the first time." notify MockExpectationAlreadyInvokedError.new() end |
#raise_cant_constrain_count_for_negated_have_received_error(count_constraint) ⇒ Object
193 194 195 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 193 def raise_cant_constrain_count_for_negated_have_received_error(count_constraint) __raise "can't use #{count_constraint} when negative" end |
#raise_double_negation_error(wrapped_expression) ⇒ Object
170 171 172 173 174 175 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 170 def raise_double_negation_error(wrapped_expression) __raise "Isn't life confusing enough? You've already set a " \ "negative message expectation and now you are trying to " \ "negate it again with `never`. What does an expression like " \ "`#{wrapped_expression}.not_to receive(:msg).never` even mean?" end |
#raise_expectation_error(message, expected_received_count, argument_list_matcher, actual_received_count, expectation_count_type, args, backtrace_line = nil, source_id = nil) ⇒ Object
rubocop:disable Metrics/ParameterLists
77 78 79 80 81 82 83 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 77 def raise_expectation_error(, expected_received_count, argument_list_matcher, actual_received_count, expectation_count_type, args, backtrace_line=nil, source_id=nil) expected_part = expected_part_of_expectation_error(expected_received_count, expectation_count_type, argument_list_matcher) received_part = received_part_of_expectation_error(actual_received_count, args) __raise "(#{intro(:unwrapped)}).#{}#{format_args(args)}\n #{expected_part}\n #{received_part}", backtrace_line, source_id end |
#raise_expectation_on_mocked_method(method) ⇒ Object
164 165 166 167 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 164 def raise_expectation_on_mocked_method(method) __raise "#{intro} expected to have received #{method}, but that " \ "method has been mocked instead of stubbed or spied." end |
#raise_expectation_on_nil_error(method_name) ⇒ Object
211 212 213 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 211 def raise_expectation_on_nil_error(method_name) __raise (method_name) end |
#raise_expectation_on_unstubbed_method(method) ⇒ Object
158 159 160 161 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 158 def raise_expectation_on_unstubbed_method(method) __raise "#{intro} expected to have received #{method}, but that " \ "object is not a spy or method has not been stubbed." end |
#raise_expired_test_double_error ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 123 def raise_expired_test_double_error raise ExpiredTestDoubleError, "#{intro} was originally created in one example but has leaked into " \ "another example and can no longer be used. rspec-mocks' doubles are " \ "designed to only last for one example, and you need to create a new " \ "one in each example you wish to use it for." end |
#raise_have_received_disallowed(type, reason) ⇒ Object
187 188 189 190 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 187 def raise_have_received_disallowed(type, reason) __raise "Using #{type}(...) with the `have_received` " \ "matcher is not supported#{reason}." end |
#raise_invalid_arguments_error(verifier) ⇒ Object
118 119 120 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 118 def raise_invalid_arguments_error(verifier) __raise verifier. end |
#raise_method_not_stubbed_error(method_name) ⇒ Object
198 199 200 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 198 def raise_method_not_stubbed_error(method_name) __raise "The method `#{method_name}` was not stubbed or was already unstubbed" end |
#raise_missing_block_error(args_to_yield) ⇒ Object
142 143 144 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 142 def raise_missing_block_error(args_to_yield) __raise "#{intro} asked to yield |#{arg_list(args_to_yield)}| but no block was passed" end |
#raise_missing_default_stub_error(expectation, args_for_multiple_calls) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 59 def raise_missing_default_stub_error(expectation, args_for_multiple_calls) __raise( (expectation, args_for_multiple_calls) + "\n Please stub a default value first if message might be received with other args as well. \n" ) end |
#raise_non_public_error(method_name, visibility) ⇒ Object
111 112 113 114 115 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 111 def raise_non_public_error(method_name, visibility) raise NoMethodError, "%s method `%s' called on %s" % [ visibility, method_name, intro ] end |
#raise_only_valid_on_a_partial_double(method) ⇒ Object
152 153 154 155 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 152 def raise_only_valid_on_a_partial_double(method) __raise "#{intro} is a pure test double. `#{method}` is only " \ "available on a partial double." end |
#raise_out_of_order_error(message) ⇒ Object
137 138 139 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 137 def raise_out_of_order_error() __raise "#{intro} received :#{} out of order" end |
#raise_similar_message_args_error(expectation, args_for_multiple_calls, backtrace_line = nil) ⇒ Object
67 68 69 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 67 def (expectation, args_for_multiple_calls, backtrace_line=nil) __raise (expectation, args_for_multiple_calls), backtrace_line end |
#raise_unexpected_message_args_error(expectation, args_for_multiple_calls, source_id = nil) ⇒ Object
54 55 56 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 54 def (expectation, args_for_multiple_calls, source_id=nil) __raise (expectation, args_for_multiple_calls), nil, source_id end |
#raise_unexpected_message_error(message, args) ⇒ Object
49 50 51 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 49 def (, args) __raise "#{intro} received unexpected message :#{} with #{format_args(args)}" end |
#raise_unimplemented_error(doubled_module, method_name, object) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 87 def raise_unimplemented_error(doubled_module, method_name, object) = case object when InstanceVerifyingDouble "the %s class does not implement the instance method: %s".dup << if ObjectMethodReference.for(doubled_module, method_name).implemented? ". Perhaps you meant to use `class_double` instead?" else "" end when ClassVerifyingDouble "the %s class does not implement the class method: %s".dup << if InstanceMethodReference.for(doubled_module, method_name).implemented? ". Perhaps you meant to use `instance_double` instead?" else "" end else "%s does not implement: %s" end __raise % [doubled_module.description, method_name] end |
#raise_verifying_double_not_defined_error(ref) ⇒ Object
178 179 180 181 182 183 184 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 178 def (ref) notify(VerifyingDoubleNotDefinedError.new( "#{ref.description.inspect} is not a defined constant. " \ "Perhaps you misspelt it? " \ "Disable check with `verify_doubled_constant_names` configuration option." )) end |
#raise_wrong_arity_error(args_to_yield, signature) ⇒ Object
147 148 149 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/error_generator.rb', line 147 def raise_wrong_arity_error(args_to_yield, signature) __raise "#{intro} yielded |#{arg_list(args_to_yield)}| to block with #{signature.description}" end |