diff --git a/spec/spectator/mocks/null_double_spec.cr b/spec/spectator/mocks/null_double_spec.cr index e1c0861..1aa86ca 100644 --- a/spec/spectator/mocks/null_double_spec.cr +++ b/spec/spectator/mocks/null_double_spec.cr @@ -216,12 +216,12 @@ Spectator.describe Spectator::NullDouble do expect(dbl.foo("foobar")).to eq("bar") end - it "raises self when constraint unsatisfied" do + it "raises when constraint unsatisfied" do expect { dbl.foo("baz") }.to raise_error(Spectator::UnexpectedMessage, /foo/) end - it "raises self when argument count doesn't match" do - expect { dbl.foo }.to raise_error(Spectator::UnexpectedMessage, /foo/) + it "returns self when argument count doesn't match" do + expect(dbl.foo).to be(dbl) end 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 expect { dbl._spectator_clear_stubs }.to change { dbl.foo }.from(5).to(42) 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 describe "#_spectator_calls" do diff --git a/src/spectator/mocks/null_double.cr b/src/spectator/mocks/null_double.cr index 6f89d27..978418c 100644 --- a/src/spectator/mocks/null_double.cr +++ b/src/spectator/mocks/null_double.cr @@ -58,21 +58,7 @@ module Spectator %call = ::Spectator::MethodCall.new({{call.name.symbolize}}, %args) _spectator_record_call(%call) - # Attempt to find a stub that satisfies the method call and arguments. - 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 + self end end end