Class: Gruf::Rspec::ErrorMatcher
- Inherits:
-
Object
- Object
- Gruf::Rspec::ErrorMatcher
- Defined in:
- lib/gruf/rspec/error_matcher.rb
Overview
Match errors and properly handle validations
Instance Attribute Summary collapse
-
#serialized_block ⇒ Object
writeonly
Sets the attribute serialized_block.
-
#serialized_block_errors ⇒ Object
readonly
Returns the value of attribute serialized_block_errors.
Instance Method Summary collapse
- #error_message ⇒ String
-
#initialize(rpc_call_proc:, expected_error_class:, serialized_block:) ⇒ ErrorMatcher
constructor
A new instance of ErrorMatcher.
- #valid? ⇒ Boolean
Constructor Details
#initialize(rpc_call_proc:, expected_error_class:, serialized_block:) ⇒ ErrorMatcher
Returns a new instance of ErrorMatcher.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gruf/rspec/error_matcher.rb', line 32 def initialize(rpc_call_proc:, expected_error_class:, serialized_block:) @rpc_call_proc = rpc_call_proc @expected_error_class = expected_error_class @serialized_block = serialized_block @error_class_matched = false @error_serializer = Gruf.error_serializer @serialized_block_errors = [] end |
Instance Attribute Details
#serialized_block=(value) ⇒ Object (writeonly)
Sets the attribute serialized_block
24 25 26 |
# File 'lib/gruf/rspec/error_matcher.rb', line 24 def serialized_block=(value) @serialized_block = value end |
#serialized_block_errors ⇒ Object (readonly)
Returns the value of attribute serialized_block_errors.
25 26 27 |
# File 'lib/gruf/rspec/error_matcher.rb', line 25 def serialized_block_errors @serialized_block_errors end |
Instance Method Details
#error_message ⇒ String
56 57 58 59 60 61 62 |
# File 'lib/gruf/rspec/error_matcher.rb', line 56 def if serialized_block_errors? "Failed with serialized error validations: #{@serialized_block_errors.join("\n")}" else "Response class #{@rpc_response.class} did not match expected error class #{@expected_error_class}" end end |
#valid? ⇒ Boolean
47 48 49 50 51 |
# File 'lib/gruf/rspec/error_matcher.rb', line 47 def valid? run_rpc_call run_serialized_block error_class_matched? && !serialized_block_errors? end |