I work with unit test in Rails..,
Here is my code located in 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
And my app\models\sample.rb contains the following..,
class Sample
def assert_student(student)
#assert_equal "123", student.external_reference
"#{student_id}"
end
end
when i am running “rake test:units” it shows an following error
test_student_details(SampleTest):
NameError: uninitialized constant SampleTest::Student
test/unit/sample_test.rb:7:in `block in <class:SampleTest>'
How can i fix this?
You have to require the file where your SampleTest::Student is to test it.