Last active
          October 8, 2019 22:21 
        
      - 
      
- 
        Save cpkenn09y/287626c8c03bcd7834f266e4ecf00fb0 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | ## 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) | |
| # Expectation of a class to receive a method | |
| expect(ClassificationSystem).to receive(:choose_record_with_special_flag_or_unclassified_fallback) | |
| # How to stub a constant within a class | |
| stub_const("Api::V1::PublicationsController::DEFAULT_PAGINATION_COUNT", 1) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Incase you see other specs that break intermittently...
It has a decently high likelihood to be due to:
self.survey_results.vs.self.survey_results.order(:id))