Skip to content

Instantly share code, notes, and snippets.

@suzukimilanpaak
Created October 29, 2012 06:21
Show Gist options
  • Save suzukimilanpaak/3971913 to your computer and use it in GitHub Desktop.
Save suzukimilanpaak/3971913 to your computer and use it in GitHub Desktop.
Spec wiht let! and Timecop
# coding: utf-8
require 'spec_helper'
describe Time do
TIMETABLE = [Time.local(2012, 10, 26, 21), Time.local(2012, 11, 2, 21)]
describe '#now' do
let!(:now) {
now = Time.now
puts "in let! #{now}"
now
}
shared_examples "Time is?" do
it "now should depend on the datetiem Timecopped" do
puts "in example #{Time.now}"
Time.now.to_s.should eq(now.to_s)
end
end
2.times.each do |@@i|
context "Test" do
around :each do |example|
puts @@i
Timecop.travel(TIMETABLE[@@i]) do
example.run
@@i += 1
end
end
include_examples "Time is?"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment