开发者

Using Assertions outside of Tests in Rails

I'd like to start putting assertions in my controllers and models, to assert runtime behavior.

How can I access all of the assertion helpers that are available in unit tests?

I.E. I'd like to do something like

class WidgetController < ApplicationController
    def index
        @widgets = Widget.all
        assert @widgets.length > 0 # using assert in a controller!
     end
end

Is开发者_JS百科 there just a file I should require?


It's simple - just require test/unit/assertions:

require 'test/unit/assertions'
include Test::Unit::Assertions
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜