title: RSpec Stubbing out Date.today in order to test a method
body: <p>I want to test a method that follows one path if the <em>current date</em> is between Jan 1st - Aug 1st, or it follows another path if the <em>current date</em> is between Aug 2nd - December 31st. example:</p>
  
  <pre><code>def return_something_based_on_current_date
    if date_between_jan_1_and_aug_1?
      return "foo"
    else 
      return "bar"
    end
  end
  
  private
  
  def date_between_jan_1_and_aug_1?
    date_range = build_date_range_jan_1_through_aug_1
    date_range === Date.today
  end
  
  def build_date_range_jan_1_through_aug_1
    Date.today.beginning_of_year..Date.new(Date.today.year, 8, 1)
  end
  </code></pre>
  
  <p>As you can see: <code>return_something_based_on_current_date</code> depends heavily upon <code>Date.today</code>, as does the private methods it invokes.  This is making it difficult to test both paths within this method since <code>Date.today</code> dynamically returns the current date.  </p>
  
  <p>For testing purposes: I need <code>Date.today</code> to return a static date that I want it to so that I can test that each path is working correctly.</p>
  
  <ul>
  <li>I need to test that the path works correctly if the current date is between Jan 1 - Aug 1</li>
  <li>I need to test that the path works correctly if the current date is after Aug 1st.</li>
  </ul>
  
  <p><strong>Question</strong>: Is there a way that I can make <code>Date.today</code> return a value that I make up within my spec?  After the specs that test the <code>return_something_based_on_current_date</code>: I want the dynamic implementation of <code>Date.today</code> to go back to its usual implementation.  I just need control over <code>Date.today</code> to test this method. </p>