mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Store type to reduce a bit of bloat
This commit is contained in:
parent
abbd6ffd71
commit
a5e8f11e11
1 changed files with 4 additions and 3 deletions
|
@ -537,6 +537,7 @@ module Spectator
|
|||
# Get the value as-is from the stub.
|
||||
# This will be compiled as a union of all known stubbed value types.
|
||||
%value = {{stub}}.call({{call}})
|
||||
%type = {{type}}
|
||||
|
||||
# Attempt to cast the value to the method's return type.
|
||||
# If successful, which it will be in most cases, return it.
|
||||
|
@ -547,12 +548,12 @@ module Spectator
|
|||
%cast
|
||||
{% elsif fail_cast == :raise %}
|
||||
# Check if nil was returned by the stub and if its okay to return it.
|
||||
if %value.nil? && {{type}}.nilable?
|
||||
if %value.nil? && %type.nilable?
|
||||
# Value was nil and nil is allowed to be returned.
|
||||
%cast.as({{type}})
|
||||
%type.cast(%cast)
|
||||
elsif %cast.nil?
|
||||
# The stubbed value was something else entirely and cannot be cast to the return type.
|
||||
raise TypeCastError.new("#{_spectator_stubbed_name} received message #{ {{call}} } and is attempting to return a `#{%value.class}`, but returned type must be `#{ {{type}} }`.")
|
||||
raise TypeCastError.new("#{_spectator_stubbed_name} received message #{ {{call}} } and is attempting to return a `#{%value.class}`, but returned type must be `#{%type}`.")
|
||||
else
|
||||
# Types match and value can be returned as cast type.
|
||||
%cast
|
||||
|
|
Loading…
Reference in a new issue