Skip to content

Instantly share code, notes, and snippets.

@isaacsanders
Created July 26, 2011 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacsanders/1107078 to your computer and use it in GitHub Desktop.
Save isaacsanders/1107078 to your computer and use it in GitHub Desktop.
Tim's Methods
require 'rspec'
require 'date'
describe "Tim's Methods:" do
let(:tim) { TimAffinity.new }
context "Tim is in India and" do
it "should be clear that Tim needs to get his ass back here" do
tim.do_we_want_him_back?.should be_true
end
end
context "It is Sunday night, and Tim has beer" do
it "should be clear that since you have work tomorrow, you don't want to drink, and therefore you don't want Tim back" do
mock_tim = mock('Tim Wingfield', {now: 20, today: Date.commercial(2011,28,7)})
tim = TimAffinity.new(mock_tim.now, mock_tim.today)
tim.do_we_want_him_back?.should be_false
end
end
end
class TimAffinity
attr_accessor :now, :today
def initialize(now = Time.new.hour, today = Date.today)
@now = now
@today = today
@days_gone = today.yday - Date.commercial(2011,27,4).yday
end
def do_we_want_him_back?
do_we_like_him? && do_we_remember_who_he_is?
end
private
def do_we_like_him?
does_he_have_beer? && do_you_want_to_drink?
end
def do_we_remember_who_he_is?
@days_gone < 40
end
def does_he_have_beer?
(now >= 17) # After 5pm
end
def do_you_want_to_drink?
(today.wday != 0) # Not Sunday
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment