mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Prevent defining stubs on undefined methods in LazyDouble
In Crystal 1.6, a segfault would occur in the spec spec/spectator/mocks/lazy_double_spec.cr:238 I suspect this is a Crystal bug of some kind, but can't reduce it. The methods produced by `method_missing` don't have a return type including Symbol. Symbol is excluded from the union of return types (Int32 | String | Nil). The program segfaults when calling a method on the actual value, which is a symbol. It ultimately crashes when producing a failure message, which indicates the value it tested doesn't equal the expected value (a symbol of the same value). Avoid this issue by preventing stubs on undefined/untyped methods.
This commit is contained in:
parent
1998edbbb2
commit
4dfa5ccb6e
3 changed files with 15 additions and 18 deletions
|
@ -235,16 +235,9 @@ Spectator.describe Spectator::LazyDouble do
|
|||
end
|
||||
|
||||
context "with previously undefined methods" do
|
||||
it "can stub methods" do
|
||||
it "raises an error" do
|
||||
stub = Spectator::ValueStub.new(:baz, :xyz)
|
||||
dbl._spectator_define_stub(stub)
|
||||
expect(dbl.baz).to eq(:xyz)
|
||||
end
|
||||
|
||||
it "uses a stub only if an argument constraint is met" do
|
||||
stub = Spectator::ValueStub.new(:baz, :xyz, Spectator::Arguments.capture(:right))
|
||||
dbl._spectator_define_stub(stub)
|
||||
expect { dbl.baz }.to raise_error(Spectator::UnexpectedMessage, /baz/)
|
||||
expect { dbl._spectator_define_stub(stub) }.to raise_error(/stub/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -258,15 +251,6 @@ Spectator.describe Spectator::LazyDouble do
|
|||
it "removes previously defined stubs" do
|
||||
expect { dbl._spectator_clear_stubs }.to change { dbl.foo }.from(5).to(42)
|
||||
end
|
||||
|
||||
it "raises on methods without an implementation" do
|
||||
stub = Spectator::ValueStub.new(:baz, :xyz)
|
||||
dbl._spectator_define_stub(stub)
|
||||
expect(dbl.baz).to eq(:xyz)
|
||||
|
||||
dbl._spectator_clear_stubs
|
||||
expect { dbl.baz }.to raise_error(Spectator::UnexpectedMessage, /baz/)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#_spectator_calls" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue