What is the difference between running rails tests from the root director开发者_开发知识库y 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
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.
精彩评论