Hellboy
Hellboy

Reputation: 1239

Load fixtures in Rails

I am writing tests for a model Friends::New. My new_test.rb file looks like :

require 'test_helper'

class Friends::New < ActiveSupport::TestCase
  fixtures :news.yml
end

My news.yml is located in test/fixtures/friends/news.yml. But during running test, it tries to find news.yml in test/fixtures/. How do I tell it to search the yml file in test/fixtures/friends?

Upvotes: 2

Views: 536

Answers (1)

Arup Rakshit
Arup Rakshit

Reputation: 118261

You need to tell rails about it explicitly.

class Friends::New < ActiveSupport::TestCase
  set_fixture_class 'friends/news' => Friends::New
end

Read set_fixture_class.

Sets the model class for a fixture when the class name cannot be inferred from the fixture name.

Upvotes: 2

Related Questions