Literally inject stubs from double block

This commit is contained in:
Michael Miller 2022-03-19 12:28:00 -06:00
parent 5a4e95e8a2
commit 9091b8d027
No known key found for this signature in database
GPG key ID: AC78B32D30CE34A2
2 changed files with 78 additions and 24 deletions

View file

@ -34,33 +34,78 @@ Spectator.describe "Double DSL" do
end end
end end
# describe "#double with stubs in block" do context "block with stubs" do
# double(:test2) do context "one method" do
# stub def foo double(:test2) do
# "foobar" stub def foo
# end "one method"
end
end
# stub def bar subject(dbl) { double(:test2) }
# 42
# end
# end
# subject(dbl) { double(:test2) } it "defines a double with methods" do
expect(dbl.foo).to eq("one method")
end
# it "defines a double with methods" do it "compiles types without unions" do
# aggregate_failures do expect(dbl.foo).to compile_as(String)
# expect(dbl.foo).to eq("foobar") end
# expect(dbl.bar).to eq(42) end
# end
# end
# it "compiles types without unions" do context "two methods" do
# aggregate_failures do double(:test3) do
# expect(dbl.foo).to compile_as(String) stub def foo
# expect(dbl.bar).to compile_as(Int32) "two methods"
# end end
# end
# end stub def bar
42
end
end
subject(dbl) { double(:test3) }
it "defines a double with methods" do
aggregate_failures do
expect(dbl.foo).to eq("two methods")
expect(dbl.bar).to eq(42)
end
end
it "compiles types without unions" do
aggregate_failures do
expect(dbl.foo).to compile_as(String)
expect(dbl.bar).to compile_as(Int32)
end
end
end
context "empty block" do
double(:test4) do
end
subject(dbl) { double(:test4) }
it "defines a double" do
expect(dbl).to be_a(Spectator::Double)
end
end
context "stub-less method" do
double(:test5) do
def foo
"no stub"
end
end
subject(dbl) { double(:test5) }
it "defines a double with methods" do
expect(dbl.foo).to eq("no stub")
end
end
end
describe "double naming" do describe "double naming" do
double(:Name, type: :symbol) double(:Name, type: :symbol)

View file

@ -49,7 +49,16 @@ module Spectator
{{value}} {{value}}
end end
{% end %} {% end %}
{% if block %}{{block.body}}{% end %}
{% if block %}{% block.body %}
{% for expr in block.body.is_a?(Expressions) ? block.body.expressions : [block.body] %}
{% if expr.is_a?(Call) && expr.name == :stub.id %}
inject_{{expr}}
{% else %}
{{expr}}
{% end %}
{% end %}
{% end %}
end end
end end