Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 对于新手:使用方法在模型中使用rspec进行测试_Ruby On Rails_Rspec - Fatal编程技术网

Ruby on rails 对于新手:使用方法在模型中使用rspec进行测试

Ruby on rails 对于新手:使用方法在模型中使用rspec进行测试,ruby-on-rails,rspec,Ruby On Rails,Rspec,我有一个所有权模型,它有一个开始日期和一个结束日期,在我的模型中,我有以下代码: def电流? self.start\u date.present?&&self.end_date.nil? 结束 现在我想测试所有权。当前? 我该怎么做?这里是我尝试的,使用expect 描述“当拥有和给予日期为零”时 在做之前 @所有权。同意=true @所有权。保存 @所有权。更新属性(开始日期:nil,结束日期:nil) 结束 它{应该是有效的} 期望(@ownership.current?)为假 描述“那

我有一个
所有权
模型,它有一个
开始日期
和一个
结束日期
,在我的模型中,我有以下代码:

def电流?
self.start\u date.present?&&self.end_date.nil?
结束
现在我想测试
所有权。当前?

我该怎么做?这里是我尝试的,使用expect

描述“当拥有和给予日期为零”时
在做之前
@所有权。同意=true
@所有权。保存
@所有权。更新属性(开始日期:nil,结束日期:nil)
结束
它{应该是有效的}
期望(@ownership.current?)为假
描述“那么产品是自有的”吗
在{@ownership.update_属性之前(开始日期:1.day.ago)}
它{应该是有效的}
期望(@ownership.current?)为真
描述“然后产品被给予”做什么
在{@ownership.update_属性之前(结束日期:1.hour.ago)}
它{应该是有效的}
期望(@ownership.current?)为假
结束
结束
结束
。。。但它不起作用。我试图用
@ownership.current?)替换
expect(@ownership.current?)。是否为_false
?{应该是_false}
,但也没有成功


你知道怎么做吗?

我现在只测试这两个结果

描述所有权
它“#current?返回false”do
所有权。当前?应为\u false
结束
上下文“何时开始但尚未结束”是否
它“#current?返回true”do
ownership.start\u date=date.today
ownership.end_date=nil
所有权。当前?应为真
结束
结束
结束