Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails/minitest don't load fixtures for select tests

My tests are written using fixtures and I am slowly refactoring them to use factories instead.

Once I've refactored a test class to not use fixtures I want to not load fixtures for that class. Is there a way to do this? Or am I stuck with either loading them for everything or nothing?

For context, here is how my fixtures are set up now:

class ActiveSupport::TestCase
   Rake::Task["db:fixtures:load"].execute
   ...
end
like image 794
stoebelj Avatar asked Nov 22 '16 19:11

stoebelj


1 Answers

Put fixtures in test/fixtures/users.yml

Then you are able to include them where you need, for example in spec_helper

# spec_helper.rb
fixtures :all   # include all fixtures
fixtures :users # include only specific fixtures

Doc: fixtures method

P.S. it works well together with FactoryBot gem (ex. FactoryGirl)

like image 91
itsnikolay Avatar answered Sep 21 '22 23:09

itsnikolay