开发者

Using Assertions outside of Tests in Rails

开发者 https://www.devze.com 2023-02-12 18:29 出处:网络
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'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

精彩评论

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