require 'helper' class View include SimpleCalendar::ViewHelpers include ActionView::Helpers include ActionView::Context def raw(argument) argument end end describe "SimpleCalendar" do subject { View.new } before do subject.stub(:params => {:year => 2013, :month => 5}) end describe "#calendar" do context "with invalid arguments" do it "should raise an error" do expect { subject.calendar("foo") }.to raise_error(StandardError, /block/) end end context "with valid arguments" do it "should draw a calendar" do subject.should_receive(:draw_calendar) subject.calendar("foo") { "test" } end it "should not overwrite passed in arguments" do subject.should_receive(:build_range).and_return([2,2,3]) subject.should_receive(:draw_calendar) subject.calendar("foo") { "test" } end end end describe "#build_range" do it "should return an array representing the days of the month" do selected_month = Date.new(2013, 1) options = {:start_day => :tuesday} result = subject.send(:build_range, selected_month, options) result.class.should == Array result.first.class.should == Date result.last.class.should == Date end end describe "#draw_calendar" do it "should render a calendar table" do #TODO: refactor draw_calendar to not require so much build up subject.should_receive(:month_header) selected_month = Date.new(2013, 1) month = [] current_date = Date.new(2013, 1, 14) events = {} options = {:start_day => :monday} block = Proc.new {} subject.send(:draw_calendar, selected_month, month, current_date, events, options, block).should match(/^