Date と比較できるようにクラスを指定するにはどうすればよいですか?
class FolderDate
attr_reader :folder
def initialize folder
@folder = folder
end
end
class AsteriskFolderDate < FolderDate
include Comparable
attr_reader :date
def initialize folder
super
@date = get_date
end
def <=>(other)
@date <=> other
end
private
#omitted
end
Railsコンソールで...
AsteriskFolderDate.new("20130628") > Date.today-1
=> true
AsteriskFolderDate.new("20130627") > Date.today
=> false
スペックファイル...
describe "An instance of", AsteriskFolderDate do
let(:folder) { DateFolder.new(Date.today).asterisk_folder }
subject { AsteriskFolderDate.new(folder) }
#omitted
it "should compare based on @date" do
expect( Date.today-1 ).to be < subject
expect( subject ).to be > Date.today-1
end
end
テストに失敗...
Failure/Error: expect( Date.today-1 ).to be < subject
ArgumentError:
comparison of Date with AsteriskFolderDate failed
コンソール出力を見ると、動作していると思いたくなるのですが、テストは失敗しています。私は正しい方向に進んでいますか、それともコンソールに欠けている欠陥をテストが指摘していますか?