Timecop with Factory_girl: factory not sequencing date attribute as expected
<p>I am using the <a href="https://rubygems.org/gems/timecop" rel="nofollow">timecop</a> gem in order to stub out dates.  I am also using <a href="https://rubygems.org/gems/factory_girl_rails" rel="nofollow">factory_girl</a> in order to make creating objects for my specs easier.</p>

<p>Here is my factory:</p>

<pre><code>FactoryGirl.define do
  factory :fiscal_year do
    start_date  {Date.today}
    end_date    {Date.today + 1.day}

    trait(:sequenced_start_date) {sequence(:start_date, Date.today.year)  {|n| Date.new(n, 10, 1) }}
    trait(:sequenced_end_date)   {sequence(:end_date,   Date.today.year + 1)  {|n| Date.new(n, 9, 30) }}


    factory :sequenced_fiscal_year, parent: :fiscal_year,
            traits: [:sequenced_start_date, :sequenced_end_date]
  end
end
</code></pre>

<p>Assume that today's <strong>actual</strong> date is 09/07/2016.</p>

<p>Here is my spec:</p>

<pre><code>RSpec.describe FiscalYear, type: :model do
  before(:example) do
    Timecop.freeze(Time.local(2010))
  end
  after do
    Timecop.return
  end

  describe "fake spec to show unexpected sequence behavior" do
    it "tests something" do
      puts "Today's frozen date thanks to Timecop: #{Date.today}"
      fiscal_year = create(:sequenced_fiscal_year)
      puts "Sequenced Date: #{fiscal_year.end_date}"
    end
  end
end
</code></pre>

<p>When the spec is run here is the output:</p>

<pre><code>Today's frozen date thanks to Timecop: 01/01/2010
Sequenced Date: 09/30/2017
</code></pre>

<p>In the first output line: Timecop works as expected when I call <code>Date.today</code>.  It has successfully frozen the time and returns that frozen time.</p>

<p>However: the second line does not work as expected.  It is clearly using the system <code>Date</code> as opposed to Timecop's frozen <code>Date</code>.  The sequenced <code>end_date</code> should sequentially add +1 year to the currently frozen Date.  Therefore: I expect the <code>end_date</code> here to be <code>09/30/2011</code>, as opposed to <code>09/30/2017</code>.  </p>

<p>How can I make it so that the sequenced <code>end_date</code> attribute goes off of Timecop's <code>Date</code> as opposed to the system's <code>Date</code>?</p>