John Gibb
John Gibb

Reputation: 10773

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 there just a file I should require?

Upvotes: 3

Views: 600

Answers (1)

John Gibb
John Gibb

Reputation: 10773

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

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

Upvotes: 4

Related Questions