我有一个Ownership模型,它有一个start_date和一个end_date,在我的模型中,我有以下代码:
def current?
self.start_date.present? && self.end_date.nil?
end现在我想测试一下ownership.current?
我该怎么做呢?下面是我所尝试的,使用expect...
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..。但它并没有起作用。我试图用@ownership.current? { should be_false }替换expect(@ownership.current?).to be_false,但也没有成功。
你知道怎么做吗?
发布于 2013-07-23 15:40:07
我只会测试当前的两个结果?
describe OwnerShip do
it "#current? returns false" do
ownership.current?.should be_false
end
context "when started and not yet ended" do
it "#current? returns true" do
ownership.start_date = Date.today
ownership.end_date = nil
ownership.current?.should be_true
end
end
endhttps://stackoverflow.com/questions/17803767
复制相似问题