require 'test/unit'
require 'fileutils'
require File.expand_path(File.dirname(__FILE__) + "/../lib/calendar_helper")
class CalendarHelperTest < Test::Unit::TestCase
include CalendarHelper
def test_with_output
output = "
Past Month
" + calendar_with_defaults
output << "
Current Month
" + calendar_for_this_month
write_sample "sample.html", output
end
def test_simple
assert_match %r{August}, calendar_with_defaults
end
def test_required_fields
# Year and month are required
assert_raises(ArgumentError) {
calendar
}
assert_raises(ArgumentError) {
calendar :year => 1
}
assert_raises(ArgumentError) {
calendar :month => 1
}
end
def test_default_css_classes
# :other_month_class is not implemented yet
{ :table_class => "calendar",
:month_name_class => "monthName",
:day_name_class => "dayName",
:day_class => "day"
}.each do |key, value|
assert_correct_css_class_for_default value
end
end
def test_custom_css_classes
# Uses the key name as the CSS class name
# :other_month_class is not implemented yet
[:table_class, :month_name_class, :day_name_class, :day_class].each do |key|
assert_correct_css_class_for_key key.to_s, key
end
end
def test_abbrev
assert_match %r{>Mon<}, calendar_with_defaults(:abbrev => (0..2))
assert_match %r{>M<}, calendar_with_defaults(:abbrev => (0..0))
assert_match %r{>Monday<}, calendar_with_defaults(:abbrev => (0..-1))
end
def test_block
# Even days are special
assert_match %r{class="special_day">2<}, calendar(:year => 2006, :month => 8) { |d|
if d.mday % 2 == 0
[d.mday, {:class => 'special_day'}]
end
}
end
def test_first_day_of_week
assert_match %r{
\s*
Sun}, calendar_with_defaults
# testing that if the abbrev and contracted version are the same, there should be no abbreviation.
assert_match %r{