RSpec - as_null_object?

rspec2, ruby

Solution

Use a null object when you don't care about the object's behavior or interaction, and don't want to explicitly stub everything out that's needed. Calling any method with any arguments on a null object will not result in a `NoMethodError` or `ArgumentError`. See also the Wikipedia entry on the Null Object Pattern.

Problem

It's not clear to me what the purpose of `as_null_object` is and in what scenarios you would use it? According to the documentation on Relish: Use the `as_null_object` method to ignore any messages that aren't explicitly set as stubs or message expectations. Not registering with me.

Original source