gbarillot
gbarillot

Reputation: 329

Fixtures not loaded using minitest to test services

I have added an /app/services directory in my Rails app where I put some business logic that is not related to a specific DB table and/or that may call some external APIs.

I also added this to my Rakefile :

namespace :test do
  desc "Test tests/services/* code"
  Rails::TestTask.new(:services) do |t|
    t.pattern = 'test/services/**/*_test.rb'
  end
end

Rake::Task['test:run'].enhance ["test:services"]

As you can see, my tests are located inside "/test/services".

Now all tests can be performed using "spring rake test", except that fixtures aren't loaded at all for services. Worst, if I try adding "fixtures :all" at the top of a service test Class, I get a "undefined method `fixture' for #

Do you have an idea about how I can load fixtures for tests located in a non regular directory ?

Upvotes: 2

Views: 1929

Answers (1)

gbarillot
gbarillot

Reputation: 329

Yeah, thanks Chris Kottom you've got the answer ! The trick was just to use this :

require 'test_helper'

class VatTest < ActiveSupport::TestCase

    # My test code

end

Instead of this :

require 'test_helper'

describe Vat do

    # My test code

end

Although the latest way for writing the test works, this does not load fixtures.

Upvotes: 3

Related Questions