mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Allow passing predefined stubs in as keyword args
This commit is contained in:
parent
c1195ef687
commit
9c1357da3f
4 changed files with 31 additions and 1 deletions
|
@ -208,6 +208,16 @@ Spectator.describe "Double DSL" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "predefined method stubs" do
|
||||||
|
double(:test8, foo: 42)
|
||||||
|
|
||||||
|
let(dbl) { double(:test8, foo: 7) }
|
||||||
|
|
||||||
|
it "overrides the original value" do
|
||||||
|
expect(dbl.foo).to eq(7)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "scope" do
|
describe "scope" do
|
||||||
double(:outer, scope: :outer)
|
double(:outer, scope: :outer)
|
||||||
double(:scope, scope: :outer)
|
double(:scope, scope: :outer)
|
||||||
|
|
|
@ -176,4 +176,14 @@ Spectator.describe "Null double DSL" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "predefined method stubs" do
|
||||||
|
double(:test8, foo: 42)
|
||||||
|
|
||||||
|
let(dbl) { double(:test8, foo: 7).as_null_object }
|
||||||
|
|
||||||
|
it "overrides the original value" do
|
||||||
|
expect(dbl.foo).to eq(7)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -95,7 +95,7 @@ module Spectator::DSL
|
||||||
found_tuple = found_tuples.last %}
|
found_tuple = found_tuples.last %}
|
||||||
|
|
||||||
{% if found_tuple %}
|
{% if found_tuple %}
|
||||||
{{found_tuple[2].id}}.new
|
{{found_tuple[2].id}}.new({{**value_methods}})
|
||||||
{% else %}
|
{% else %}
|
||||||
::Spectator::LazyDouble.new({{name}}, {{**value_methods}})
|
::Spectator::LazyDouble.new({{name}}, {{**value_methods}})
|
||||||
{% end %}
|
{% end %}
|
||||||
|
|
|
@ -4,6 +4,7 @@ require "./stub"
|
||||||
require "./stubbable"
|
require "./stubbable"
|
||||||
require "./stubbed_name"
|
require "./stubbed_name"
|
||||||
require "./unexpected_message"
|
require "./unexpected_message"
|
||||||
|
require "./value_stub"
|
||||||
|
|
||||||
module Spectator
|
module Spectator
|
||||||
# Stands in for an object for testing that a SUT calls expected methods.
|
# 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)
|
def initialize(@stubs : Array(Stub) = [] of Stub)
|
||||||
end
|
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.
|
# Compares against another object.
|
||||||
#
|
#
|
||||||
# Always returns false.
|
# Always returns false.
|
||||||
|
|
Loading…
Reference in a new issue