mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Allow passing default value stubs to mock initialization
This commit is contained in:
parent
225553127d
commit
3f4216a271
2 changed files with 28 additions and 1 deletions
|
@ -174,6 +174,28 @@ Spectator.describe "Mock DSL", :smoke do
|
|||
fake.method8(1, 2, 3, kwarg: 4, x: 5, y: 6, z: 7) { :block }
|
||||
expect(fake._spectator_calls).to contain_exactly(:method3, :method6, :method7, :method8)
|
||||
end
|
||||
|
||||
# Cannot test unexpected messages - will not compile due to missing methods.
|
||||
|
||||
describe "deferred default stubs" do
|
||||
mock(ConcreteClass)
|
||||
|
||||
let(fake2) do
|
||||
mock(ConcreteClass,
|
||||
method1: "stubbed",
|
||||
method3: 123,
|
||||
method4: :xyz)
|
||||
end
|
||||
|
||||
it "uses the keyword arguments as stubs" do
|
||||
aggregate_failures do
|
||||
expect(fake2.method1).to eq("stubbed")
|
||||
expect(fake2.method2).to eq(:original)
|
||||
expect(fake2.method3(42)).to eq(123)
|
||||
expect(fake2.method4 { :foo }).to eq(:xyz)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with an abstract class" do
|
||||
|
|
|
@ -178,7 +178,12 @@ module Spectator::DSL
|
|||
found_tuple = found_tuples.last %}
|
||||
|
||||
{% if found_tuple %}
|
||||
{{found_tuple[2].id}}.new({{**value_methods}})
|
||||
{{found_tuple[2].id}}.new.tap do |mock|
|
||||
{% for key, value in value_methods %}
|
||||
%stub{key} = ::Spectator::ValueStub.new({{key.id.symbolize}}, {{value}})
|
||||
mock._spectator_define_stub(%stub{key})
|
||||
{% end %}
|
||||
end
|
||||
{% else %}
|
||||
{% raise "Type `#{type.id}` must be previously mocked before attempting to instantiate." %}
|
||||
{% end %}
|
||||
|
|
Loading…
Reference in a new issue