timecop in the rescue

did committed Mar 26, 2015
commit 2d9ab0eea8fa85c19759021e1c85a34fb7b195de
Showing 4 changed files with 8 additions and 3 deletions
Gemfile +2 -0
@@ @@ -17,6 +17,8 @@ group :test do
gem 'json_spec', '~> 1.1.4'
gem 'i18n-spec', '~> 0.6.0'
+ gem 'timecop', '~> 0.7.1'
+
gem 'pry-byebug', '~> 3.0.1'
gem 'rack-test', '~> 0.6.3'
Gemfile.lock +2 -0
@@ @@ -188,6 +188,7 @@ GEM
thor (0.19.1)
thread_safe (0.3.5)
tilt (1.4.1)
+ timecop (0.7.3)
tins (1.3.4)
tzinfo (1.2.2)
thread_safe (~> 0.1)
@@ @@ -210,4 +211,5 @@ DEPENDENCIES
rake (~> 10.4.2)
rspec (~> 3.2.0)
thin
+ timecop (~> 0.7.1)
yui-compressor (~> 0.12.0)
spec/integration/server/sitemap_spec.rb +3 -3
@@ @@ -10,9 +10,9 @@ describe Locomotive::Steam::Server do
describe 'sitemap.xml' do
- subject { get '/sitemap.xml'; last_response.body }
+ let(:now) { Time.use_zone('America/Chicago') { Time.zone.local(2015, 'mar', 25, 10, 0) } }
- before { allow(Time).to receive(:now).and_return(Time.zone.parse('2015/03/25 10:00:00')) }
+ subject { Timecop.freeze(now) { get '/sitemap.xml' }; last_response.body }
it 'checks if it looks valid' do
expect(Nokogiri::XML(subject).errors.empty?).to eq true
@@ @@ -21,7 +21,7 @@ describe Locomotive::Steam::Server do
expect(subject).to match((<<-EOF
<url>
<loc>http://example.org/fr/a-notre-sujet</loc>
- <lastmod>2015-03-26</lastmod>
+ <lastmod>2015-03-25</lastmod>
<priority>0.9</priority>
</url>
EOF
spec/spec_helper.rb +1 -0
@@ @@ -25,6 +25,7 @@ require 'rubygems'
require 'bundler/setup'
require 'i18n-spec'
+ require 'timecop'
require_relative '../lib/locomotive/steam'
require_relative 'support'