문제

I have a test double that I'd like to be able to receive any message.

I know I can expect the double to receive a certain message and return a value like so:

foo = double()
allow(foo).to receive(:bar) { "Foobar" }

I can also allow foo to receive any message using #as_null_object like:

foo = double()
foo.as_null_object

Is there any other syntax for this? Seems I should be able to do something like:

allow(foo).to receive(:anything)
도움이 되었습니까?

해결책

allow and expect methods can be used to stub methods/set expectations on particular method. Augmenting object with null object pattern is quite different, and thus uses different method call.

Please note that you should usually not use null object in area that is tested by particular test -- it is meant to imitate some part of the system that is side effect of tested code, which cannot be stubbed easily.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top