Background
RubyMine version: 8.0.3
Created a controller in a Rail project and select Run / Run ‘All tests in projectname…’, got “cannot load such file — test_helper” exception when test/test_helper.rb does exist
Below is output from Run Tool window
/usr/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /home/username/RubyMine-8.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb Testing started at 08:02 ... Work directory: /home/username/development/rubymine/hello_mine Loading files.... ========================================= Fail to load: /home/username/development/rubymine/hello_mine/test/controllers/say_hello_controller_test.rb:1 Exception message: cannot load such file -- test_helper ["/home/username/development/rubymine/hello_mine/test/controllers/say_hello_controller_test.rb:1:in `require'", "/home/username/development/rubymine/hello_mine/test/controllers/say_hello_controller_test.rb:1:in `'", "/home/username/RubyMine-8.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:51:in `require'", "/home/username/RubyMine-8.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:51:in `block in require_all_test_scripts'", "/home/username/RubyMine-8.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:44:in `each'", "/home/username/RubyMine-8.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:44:in `require_all_test_scripts'", "/home/username/RubyMine-8.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:140:in `'", "-e:1:in `load'", "-e:1:in `'"] Fail to load: /home/username/development/rubymine/hello_mine/test/controllers/worklog_controller_test.rb:1 Exception message: cannot load such file -- test_helper ["/home/username/development/rubymine/hello_mine/test/controllers/worklog_controller_test.rb:1:in `require'", "/home/username/development/rubymine/hello_mine/test/controllers/worklog_controller_test.rb:1:in `'", "/home/username/RubyMine-8.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:51:in `require'", "/home/username/RubyMine-8.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:51:in `block in require_all_test_scripts'", "/home/username/RubyMine-8.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:44:in `each'", "/home/username/RubyMine-8.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:44:in `require_all_test_scripts'", "/home/username/RubyMine-8.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:140:in `'", "-e:1:in `load'", "-e:1:in `'"] Running via Spring preloader in process 3374 /home/username/development/rubymine/hello_mine/db/schema.rb doesn't exist yet. Run `rake db:migrate` to create it, then try again. If you do not intend to use a database, you should instead alter /home/username/development/rubymine/hello_mine/config/application.rb to limit the frameworks that will be loaded. 1. /home/username/development/rubymine/hello_mine/test/test_helper.rb:1 1 files were loaded. ========================================= Running tests... Started Finished in 0.00186s 0 tests, 0 assertions, 0 failures, 0 errors, 0 skips Process finished with exit code 0
Resolutions
As usual, I checked the stack trace and could not understand why it cannot find test_helper.rb under test. The followings are cycling through the two controller tests
"/home/username/RubyMine-8.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:51:in `require'", "/home/username/RubyMine-8.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:51:in `block in require_all_test_scripts'", "/home/username/RubyMine-8.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:44:in `each'", "/home/username/RubyMine-8.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:44:in `require_all_test_scripts'", "/home/username/RubyMine-8.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:140
So they are not relevent, The following lines
["/home/username/development/rubymine/hello_mine/test/controllers/say_hello_controller_test.rb:1:in `require'", "/home/username/development/rubymine/hello_mine/test/controllers/say_hello_controller_test.rb:1:in `'",
points to the controller test – line 1
require 'test_helper'
but the file test/test_help.rb does exist so tried rake test from command shell and pass all tests
> rake test ... Finished in 0.300035s, 6.6659 runs/s, 6.6659 assertions/s. 2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
It confirmed that there is no real issue. It appears that the test is started at wrong location/directory that resulted in not finding test/test_helper.rb but it did log the correct working directory
Work directory: /home/username/development/rubymine/hello_mine
Tried right click individual test / Run ‘Run test ‘controller_test…’ and it works. Right click the test foler / Run ‘Run All tests in test:…’ and it works too.
Go back to check the Run Tool window and found how the test is invoked
/usr/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) -Itest /home/username/RubyMine-8.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb
Notice that there is an extra option -Itest when ruby is invoked for successful tests. Check manual,
> man ruby ... -I directory Used to tell Ruby where to load the library scripts. Directory path will be added to the load-path variable ($:)
This explains why the test run from test folder and individual test works. Not sure why the option is not included when invoke test from Run menu option.
So how did you solve the issue?