gpt4 book ai didi

ruby-on-rails - 在 Rails 中的测试之外使用断言

转载 作者:行者123 更新时间:2023-12-04 14:42:46 25 4
gpt4 key购买 nike

我想开始在我的 Controller 和模型中放置断言,以断言运行时行为。

如何访问单元测试中可用的所有断言助手?

即我想做类似的事情

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

是否只需要一个文件?

最佳答案

这很简单——只需要测试/单元/断言:

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

关于ruby-on-rails - 在 Rails 中的测试之外使用断言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5074362/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com