What is the difference between running rails tests from the root directory and from the test directory? I’ve seen it done both ways, but I would imagine that one is preferred..
ruby test/unit/user_test.rb
vs
cd test
ruby unit/user_test.rb
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The only difference is in relative paths – any requires are relative to the directory from which you run ruby.
For instance, if your test case has
require 'test_helper.rb'in it, this will only work from the test directory (since that is where test_helper.rb is.If you want to run your tests from the root directory, you would have to change this to
require File.join(File.dirname(__FILE__), '..', 'test_helper.rb', where FILE is the path to the file that contains this line (your test case), and the rest is the path of test_helper.rb, relative to that file. This way, where you run the test from is irrelevant.