mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Disallow stubs for undefined methods in null double
Any method_missing invocation should return self.
This commit is contained in:
parent
7dd77a2096
commit
827b69483b
2 changed files with 4 additions and 27 deletions
|
@ -216,12 +216,12 @@ Spectator.describe Spectator::NullDouble do
|
||||||
expect(dbl.foo("foobar")).to eq("bar")
|
expect(dbl.foo("foobar")).to eq("bar")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises self when constraint unsatisfied" do
|
it "raises when constraint unsatisfied" do
|
||||||
expect { dbl.foo("baz") }.to raise_error(Spectator::UnexpectedMessage, /foo/)
|
expect { dbl.foo("baz") }.to raise_error(Spectator::UnexpectedMessage, /foo/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises self when argument count doesn't match" do
|
it "returns self when argument count doesn't match" do
|
||||||
expect { dbl.foo }.to raise_error(Spectator::UnexpectedMessage, /foo/)
|
expect(dbl.foo).to be(dbl)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "ignores the block argument if not in the constraint" do
|
it "ignores the block argument if not in the constraint" do
|
||||||
|
@ -406,15 +406,6 @@ Spectator.describe Spectator::NullDouble do
|
||||||
it "removes previously defined stubs" do
|
it "removes previously defined stubs" do
|
||||||
expect { dbl._spectator_clear_stubs }.to change { dbl.foo }.from(5).to(42)
|
expect { dbl._spectator_clear_stubs }.to change { dbl.foo }.from(5).to(42)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "defaults to returning itself for methods with no 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 be(dbl)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#_spectator_calls" do
|
describe "#_spectator_calls" do
|
||||||
|
|
|
@ -58,21 +58,7 @@ module Spectator
|
||||||
%call = ::Spectator::MethodCall.new({{call.name.symbolize}}, %args)
|
%call = ::Spectator::MethodCall.new({{call.name.symbolize}}, %args)
|
||||||
_spectator_record_call(%call)
|
_spectator_record_call(%call)
|
||||||
|
|
||||||
# Attempt to find a stub that satisfies the method call and arguments.
|
self
|
||||||
if %stub = _spectator_find_stub(%call)
|
|
||||||
# A method that was not defined during initialization was stubbed.
|
|
||||||
# Even though all stubs will have a #call method, the compiler doesn't seem to agree.
|
|
||||||
# Assert that it will (this should never fail).
|
|
||||||
raise TypeCastError.new("Stub has no value") unless %stub.responds_to?(:call)
|
|
||||||
|
|
||||||
# Return the value of the stub as-is.
|
|
||||||
# Might want to give a warning here, as this may produce a "bloated" union of all known stub types.
|
|
||||||
%stub.call(%call)
|
|
||||||
else
|
|
||||||
# A stub wasn't found, invoke the fallback logic.
|
|
||||||
# Message received for a methods that isn't stubbed nor defined when initialized.
|
|
||||||
_spectator_abstract_stub_fallback(%call)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue