Allow passing predefined stubs in as keyword args

This commit is contained in:
Michael Miller 2022-03-31 18:55:12 -06:00
parent c1195ef687
commit 9c1357da3f
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF
4 changed files with 31 additions and 1 deletions

View file

@ -95,7 +95,7 @@ module Spectator::DSL
found_tuple = found_tuples.last %}
{% if found_tuple %}
{{found_tuple[2].id}}.new
{{found_tuple[2].id}}.new({{**value_methods}})
{% else %}
::Spectator::LazyDouble.new({{name}}, {{**value_methods}})
{% end %}

View file

@ -4,6 +4,7 @@ require "./stub"
require "./stubbable"
require "./stubbed_name"
require "./unexpected_message"
require "./value_stub"
module Spectator
# Stands in for an object for testing that a SUT calls expected methods.
@ -76,6 +77,15 @@ module Spectator
def initialize(@stubs : Array(Stub) = [] of Stub)
end
# Creates the double.
#
# An initial set of stubs can be provided with *value_methods*.
def initialize(**value_methods)
@stubs = value_methods.map do |key, value|
ValueStub.new(key, value).as(Stub)
end
end
# Compares against another object.
#
# Always returns false.