Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot load such file -- test_helper if test case run using 'ruby' instead of 'rake test'

If I run test case:

ruby test/models/chat_bot/option_test.rb

I get error:

/home/anuja/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- test_helper (LoadError)

and it works if I run test as follow:

rake test test/models/chat_bot/option_test.rb
like image 476
Anuja Avatar asked Sep 20 '16 15:09

Anuja


3 Answers

You need to add your test directory to Ruby's load path. Otherwise Ruby doesn't know where to look to find test_helper. To add to the load path, use the -I option:

ruby -Itest test/models/chat_bot/option_test.rb
like image 117
Matt Brictson Avatar answered Nov 18 '22 19:11

Matt Brictson


It is fixed by adding absolute path:

require './test/test_helper'

instead of:

require 'test_helper'

wherever we require the same. And then I can run test case without any parameter:

ruby test/models/xyz/option_test.rb
like image 23
Anuja Avatar answered Nov 18 '22 20:11

Anuja


Somehow running rails test <test_file_path> from my project's root solves the issue.

like image 2
Marat Avatar answered Nov 18 '22 19:11

Marat