as_null_object

it tells the double to only call the methods we tell it to expect and ignore any other methods

Example:
it “should receive sth.a”
a = double(‘model’)
model = Model.new(a)
a.should_receive(:method_a).with(sth.a)
model.start
end

def start
method_a(sth.a)
method_a(sth.b)
end

+++++++++++++++++++++++++++++++++++++
if we add another example
it “should receive sth.b”
a = double(‘model’)
model = Model.new(a)
a.should_receive(:method_a).with(sth.b)
model.start
end

Both example will be failed
+++++++++++++++++++++solution ++++++++++++++++++
change a = double(‘model’) to a = double(‘model’).as_null_object

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s