Using Minitest, error loading minitest_helper required

I am testing Minitest :: Spec as an alternative to RSpec, but I have an unpleasant problem that I cannot answer:

I set some basic specifications in spec/models/*_spec.rb There is minitest-rails in my rails application, and I installed my rake file as follows:

 Rake::TestTask.new do |t| t.libs.push "lib" t.test_files = FileList['spec/**/*_spec.rb'] t.verbose = true end task :default => :test 

Now, if I write my specification files as follows:

 require 'minitest_helper' describe User do ... end 

... and run rake test , I get:

 user_spec.rb:1:in `require': cannot load such file -- minitest_helper (LoadError) 

however, if I change the require string to

 require_relative '../minitest_helper' 

Then it works. So this is functional, but it seems that every example of people using mini-tests that I find on the Internet just calls require 'minitest_helper' and not require_relative . So, what am I missing that allows others to work, but not in my situation?

One last piece of information, my supporting file is as follows:

 # spec/minitest_helper.rb ENV["RAILS_ENV"] = "test" require File.expand_path('../../config/environment', __FILE__) require "minitest/autorun" require "minitest/rails" # Uncomment if you want Capybara in accceptance/integration tests # require "minitest/rails/capybara" # Uncomment if you want awesome colorful output # require "minitest/pride" class MiniTest::Rails::ActiveSupport::TestCase # Add more helper methods to be used by all tests here... end 

Nothing unusual. Thanks for the help!

+6
source share
2 answers

Your tests do not find the help file because you did not tell your tests to see where it is. try changing your rake task to this:

 Rake::TestTask.new do |t| t.libs << "lib" t.libs << "spec" t.test_files = FileList['spec/**/*_spec.rb'] t.verbose = true end task :default => :test 
+7
source

In Ruby 1.9, the working directory is not included in the Ruby download path. You can add it if you want:

 $: << "." 

... or you can add any other directories you want from require Ruby files.

If you see other people who write simply:

 require 'minitest_helper' 

... then, of course, they did something for their download path (or Rails / Rake did it for them). You can try p $: inside your Rakefile to find out what Rails / Rake does from the download path (if any).

+1
source

Source: https://habr.com/ru/post/926055/


All Articles