mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Move spectator stub retrieval to abstract getter
This commit is contained in:
parent
d74bc76687
commit
8d14be6c67
2 changed files with 16 additions and 13 deletions
|
@ -12,25 +12,13 @@ module Spectator
|
|||
include ::Spectator::Mocked
|
||||
|
||||
{% begin %}
|
||||
@_spectator_stubs = [
|
||||
private getter _spectator_stubs = [
|
||||
{% for key, value in value_methods %}
|
||||
::Spectator::ValueStub.new({{key.id.symbolize}}, {{value}}),
|
||||
{% end %}
|
||||
] of ::Spectator::Stub
|
||||
{% end %}
|
||||
|
||||
def _spectator_define_stub(stub : ::Spectator::Stub) : Nil
|
||||
@_spectator_stubs.unshift(stub)
|
||||
end
|
||||
|
||||
private def _spectator_find_stub(call : ::Spectator::MethodCall) : ::Spectator::Stub?
|
||||
@_spectator_stubs.find &.===(call)
|
||||
end
|
||||
|
||||
private def _spectator_stub_for_method?(method : Symbol) : Bool
|
||||
@_spectator_stubs.any? { |stub| stub.method == method }
|
||||
end
|
||||
|
||||
# Returns the mock's name formatted for user output.
|
||||
private def _spectator_stubbed_name : String
|
||||
\{% if anno = @type.annotation(::Spectator::StubbedName) %}
|
||||
|
|
|
@ -5,6 +5,21 @@ module Spectator
|
|||
module Mocked
|
||||
include Stubbable
|
||||
|
||||
# Retrieves an enumerable collection of stubs.
|
||||
abstract def _spectator_stubs
|
||||
|
||||
def _spectator_define_stub(stub : ::Spectator::Stub) : Nil
|
||||
_spectator_stubs.unshift(stub)
|
||||
end
|
||||
|
||||
private def _spectator_find_stub(call : ::Spectator::MethodCall) : ::Spectator::Stub?
|
||||
_spectator_stubs.find &.===(call)
|
||||
end
|
||||
|
||||
private def _spectator_stub_for_method?(method : Symbol) : Bool
|
||||
_spectator_stubs.any? { |stub| stub.method == method }
|
||||
end
|
||||
|
||||
# Method called when a stub isn't found.
|
||||
#
|
||||
# The received message is captured in *call*.
|
||||
|
|
Loading…
Reference in a new issue