B S*_*ven 4 ruby assertions rake-task ruby-on-rails-3
我想使用断言在rake任务中引发错误.
the_index = items.index(some_item)
assert_not_nil the_index, "Lookup failed for the following item: " + some_item
Run Code Online (Sandbox Code Playgroud)
我得到undefined method assert_not_nil.我可以在我的rake任务中包含断言文件吗?怎么样?
这是最佳做法,还是有更好的方法来做到这一点?
在Ruby 1.9.2中工作.
您可以在任何地方使用断言.
require "minitest/unit"
include MiniTest::Assertions # all assertions are in this module
refute_nil @ivar, "An instance variable should not be nil here!"
Run Code Online (Sandbox Code Playgroud)
但你为什么要那样做?自己提出有意义的例外.
|   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           1021 次  |  
        
|   最近记录:  |