Skip to content

Instantly share code, notes, and snippets.

@joshski
Created May 6, 2009 06:30
Show Gist options
  • Save joshski/107391 to your computer and use it in GitHub Desktop.
Save joshski/107391 to your computer and use it in GitHub Desktop.
require 'spec'
# i have an option box that stores text ("day", "week" or "month" -
# representing the accuracy of a date) to a database that is then used
# when displaying the date (i.e. decides what accuracy to show it to).
class Event
attr_accessor :date, :accuracy
def to_s
case @accuracy
when "day"
date.strftime("%A %d %B %Y")
when "week"
date.strftime("Week %U, %Y")
when "month"
date.strftime("%B %Y")
end
end
end
describe Event do
before do
@event = Event.new
end
describe "with day accuracy" do
before do
@event.accuracy = "day"
end
it "should render string '<day> <date> <month> <year>'" do
@event.date = Date.parse("2006/01/01")
@event.to_s.should == "Sunday 01 January 2006"
end
end
describe "with week accuracy" do
before do
@event.accuracy = "week"
end
it "should render string 'Week <week>, <year>'" do
@event.date = Date.parse("2006/09/09")
@event.to_s.should == "Week 36, 2006"
end
end
describe "with month accuracy" do
before do
@event.accuracy = "month"
end
it "should render string '<month> <year>'" do
@event.date = Date.parse("2006/03/03")
@event.to_s.should == "March 2006"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment