title: How to overwrite ruby method's local variable while writing rspec test cases?
body: <p>Existing Ruby Code:</p>
  
  <pre><code>def book_details
    book_count = Book.count
    while (book_count &gt; 1)
      # Do something
    end
  end
  </code></pre>
  
  <p>I want to write rspec test case which sets the book_count value in the book_details function. Is it possible? If yes, how?</p>
  
  <p>So far, what I have tried is:</p>
  
  <pre><code>it 'Should return 1 book details only' do
    allow(Model).to receive(book_count).and_return(1)
    # Do something
  end
  </code></pre>
  
  <p>But this is giving error 'undefined local variable or method `book_count' for #</p>