开发者

Difference between running rails tests from root and test directory

开发者 https://www.devze.com 2023-04-08 16:47 出处:网络
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..

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消