gpt4 book ai didi

ruby-on-rails - 名称错误 : uninitialized constant

转载 作者:数据小太阳 更新时间:2023-10-29 07:30:53 26 4
gpt4 key购买 nike

我在 Rails 中进行单元测试......这是我的代码位于 test\unit\sample_test.rb

require 'test_helper'
require 'test/unit'
require 'sample'

class SampleTest < ActiveSupport::TestCase
test "student details" do
student = Student.new
student.Date_of_joining = DateTime.now
student.id = "123"
assert_student student
end
end

我的 app\models\sample.rb 包含以下内容..,

class Sample     
def assert_student(student)
#assert_equal "123", student.external_reference
"#{student_id}"
end
end

当我运行“rake test:units”时,它显示了以下错误

 test_student_details(SampleTest):
NameError: uninitialized constant SampleTest::Student
test/unit/sample_test.rb:7:in `block in <class:SampleTest>'

我该如何解决这个问题?

最佳答案

您必须要求您的 SampleTest::Student 所在的文件进行测试。

关于ruby-on-rails - 名称错误 : uninitialized constant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8700605/

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