gpt4 book ai didi

ruby-on-rails - 使用 Ruby on Rails 了解 Test::Unit 中的 assert_equal

转载 作者:行者123 更新时间:2023-11-28 21:05:27 24 4
gpt4 key购买 nike

我有以下代码:

test "unique title" do
product = Product.new(title: products(:ruby).title,
description: 'yyy',
price: 1,
image_url: "fred.gif")

assert !product.save
puts product.errors[:title].join('; ')
assert_equal "has already been taken", product.errors[:title].join('; ')
end

测试通过。但我不明白为什么 assert_equal 不会触发错误。

因为“已被采用”不等于:ProductTest#test_unique_titlehas already been taken

这是 puts 语句的输出。

为什么这个测试通过了?

最佳答案

我认为您感到困惑,因为不知何故在您的输出中没有换行。 ProductTest#test_unique_title 描述了你正在运行的测试方法并且已经被采用是你的结果所以测试应该通过

关于ruby-on-rails - 使用 Ruby on Rails 了解 Test::Unit 中的 assert_equal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16952241/

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