Skip to content

Instantly share code, notes, and snippets.

@olistik
Created September 26, 2014 19:43
Show Gist options
  • Save olistik/17f1bcecbac6d9389eaf to your computer and use it in GitHub Desktop.
Save olistik/17f1bcecbac6d9389eaf to your computer and use it in GitHub Desktop.
require 'rspec'
require 'date'
require 'ostruct'
class Person < OpenStruct
def age
now.year - birthday.year
end
def now
@now ||= DateTime.now
end
end
describe Person do
let(:ju) { Person.new(birthday: Date.new(1986)) }
context "test like it's 2014" do
describe '#age' do
it 'returns its age' do
ju.now = Date.new(2014)
expect(ju.age).to eq(28)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment