我有一个Ownership
模型,它有一个start_date
和一个end_date
,在我的模型中,我有以下代码:
def current?
self.start_date.present? && self.end_date.nil?
end
现在我想测试ownership.current?
我该怎么做?这是我尝试过的,使用期望...
describe "when owning and giving date are nil" do
before do
@ownership.agreed = true
@ownership.save
@ownership.update_attributes(start_date: nil, end_date: nil)
end
it { should be_valid }
expect(@ownership.current?).to be_false
describe "then product is owned" do
before { @ownership.update_attributes(start_date: 1.day.ago) }
it { should be_valid }
expect(@ownership.current?).to be_true
describe "then product is given" do
before { @ownership.update_attributes(end_date: 1.hour.ago) }
it { should be_valid }
expect(@ownership.current?).to be_false
end
end
end
......但它没有奏效。我试图用 替换expect(@ownership.current?).to be_false
,@ownership.current? { should be_false }
但也没有成功。
你知道怎么做吗?