Skip to content

Instantly share code, notes, and snippets.

## IMPORTANT -> The expectation must come before the invocation, so that it can catch the invocation when it happens
# Able to stub an instance's method. Will return whatever is in the block. The instance's method would have to be invoked in the RSpec.
@person.stub(:get_relevant_experts) { @collection_of_possibilities }
# Expectation of an instance that is available in the testing context to receive a particular method, choose return value
expect(@person).to receive(:get_relevant_experts).with("Medical").and_return(@collection_of_possibilities)
# Expectation of an instance to receive a method and return a result
expect_any_instance_of(Classification).to receive(:valid_matches).and_return(@collection_of_possibilities)