Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixture Class Not found error on simple rails testing

I am trying to set up the rails testing framework but am facing some issues. My setup is as follows

test/models/clinic_test.rb

require 'test_helper'

class ClinicTest < ActiveSupport::TestCase
  test "sample" do
    clinic = clinics(:myclinic)
    assert(clinic.name == 'Krishan')
  end
end

test/fixtures/clinics.yml

myclinic:
  name: Krishan

But when I run the clinic_test rake process I get the following error:

ActiveRecord::FixtureClassNotFound: No class attached to find
   test/models/clinic_test.rb:5:in `block in <class:ClinicTest>'

I see that the database is actually populated with the sample data from the clinics.yml file.

Where is the problem? Is this some configuration issue?

like image 226
DanMatlin Avatar asked Jun 23 '26 18:06

DanMatlin


1 Answers

Add following lines in test_helper.rb file, before fixtures :all

class ActiveSupport::TestCase
  self.use_transactional_fixtures = true
  set_fixture_class clinics: Clinic
  fixtures :all
  ...
end

clinics is the name of yml file where Clinic is the name of model.

like image 152
wasipeer Avatar answered Jun 28 '26 07:06

wasipeer