Fix existing mock DSL macros

Initial code for mock DSL.
This commit is contained in:
Michael Miller 2022-05-28 09:18:49 -06:00
parent 6060b3cd10
commit 03754321b5
No known key found for this signature in database
GPG key ID: AC78B32D30CE34A2
2 changed files with 51 additions and 4 deletions

View file

@ -0,0 +1,38 @@
require "../../../spec_helper"
Spectator.describe "Mock DSL", :smoke do
context "with a concrete class" do
class ConcreteClass
def method1
"original"
end
def method2 : Symbol
:original
end
end
context "specifying methods as keyword args" do
mock(ConcreteClass, method1: "stubbed", method2: :stubbed)
subject(fake) { mock(ConcreteClass) }
it "defines a mock with methods" do
aggregate_failures do
expect(fake.method1).to eq("stubbed")
expect(fake.method2).to eq(:stubbed)
end
end
it "defines a subclass" do
expect(fake).to be_a(ConcreteClass)
end
it "compiles types without unions" do
aggregate_failures do
expect(fake.method1).to compile_as(String)
expect(fake.method2).to compile_as(Symbol)
end
end
end
end
end