Initial code for StubbedType

This commit is contained in:
Michael Miller 2022-07-03 13:40:29 -06:00
parent 20c9da75a8
commit cecd2464de
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF
3 changed files with 103 additions and 0 deletions

View file

@ -270,6 +270,35 @@ Spectator.describe Spectator::Double do
end
end
context "class method stubs" do
Spectator::Double.define(ClassDouble) do
stub def self.foo
:stub
end
stub def self.bar(arg)
arg
end
stub def self.baz
yield
end
end
subject(dbl) { ClassDouble }
let(foo_stub) { Spectator::ValueStub.new(:foo, :override) }
after_each { dbl._spectator_clear_stubs }
it "overrides an existing method" do
expect { dbl._spectator_define_stub(foo_stub) }.to change { dbl.foo }.from(:stub).to(:override)
end
it "doesn't affect other methods" do
expect { dbl._spectator_define_stub(foo_stub) }.to_not change { dbl.bar(42) }
end
end
describe "#_spectator_define_stub" do
subject(dbl) { FooBarDouble.new }
let(stub3) { Spectator::ValueStub.new(:foo, 3) }