spec/cal/monthly_calendar_spec.rb in cal-0.2.1 vs spec/cal/monthly_calendar_spec.rb in cal-0.3.0

- old
+ new

@@ -1,12 +1,15 @@ require 'spec_helper' describe Cal::MonthlyCalendar do - subject { described_class.new @date } + subject { described_class.new @date, @options } - before { @date = Date.new 2012, 2 } + before do + @date = Date.new 2012, 2 + @options = {} + end describe "initialize" do it "raises an error if arg can't be converted to a date" do ['Octember', Object.new, '2012'].each do |obj| expect { described_class.new obj }.to raise_error @@ -50,24 +53,58 @@ describe "month" do it { subject.month.should == Cal::Month.new(subject) } end describe "first_day" do - it "is the first viewable day on the calendar" do - @date = Date.new 2012, 2, 23 + before { @date = Date.new 2012, 2, 23 } + + [ + [:monday, [1, 30]], + [:tuesday, [1, 31]], + [:wednesday, [2, 1]], + [:thursday, [1, 26]], + [:friday, [1, 27]], + [:saturday, [1, 28]] + ].each do |weekday, month_day| + context "when the weekday is set to start on #{weekday}" do + before { @options[:start_week_on] = weekday } + it "is the first viewable day on the calendar" do + subject.first_day.should == Cal::Day.new(Date.new(2012, *month_day), subject) + end + end + end + + it "is the first viewable day on the calendar, using sunday as the default start day" do subject.first_day.should == Cal::Day.new(Date.new(2012, 1, 29), subject) end end describe "last_day" do - it "is the last viewable day on the calendar" do - @date = Date.new 2012, 2, 23 + before { @date = Date.new 2012, 2, 23 } + + [ + [:monday, [3, 4]], + [:tuesday, [3, 5]], + [:wednesday, [3, 6]], + [:thursday, [2, 29]], + [:friday, [3, 1]], + [:saturday, [3, 2]] + ].each do |weekday, month_day| + context "when the weekday is set to start on #{weekday}" do + before { @options[:start_week_on] = weekday } + it "is the last viewable day on the calendar" do + subject.last_day.should == Cal::Day.new(Date.new(2012, *month_day), subject) + end + end + end + + it "is the last viewable day on the calendar, using sunday as the default start day" do subject.last_day.should == Cal::Day.new(Date.new(2012, 3, 3), subject) end end describe "days" do - it "is a range of all the viewable days" do + it "is a range of the first day to the last day" do @date = Date.new 2012, 2, 23 first_day = Cal::Day.new Date.new(2012, 1, 29), subject last_day = Cal::Day.new Date.new(2012, 3, 3), subject subject.days.should == (first_day..last_day) end \ No newline at end of file