RUBYLIB环境路径 [英] RUBYLIB Environment Path
问题描述
export RUBYLIB = / home / git / project /应用程序/帮助者
我正在尝试运行带有
$ b $的规范的rspec b require'output_helper'
该文件位于helpers目录中。我的问题是,当我将出口线更改为:
export RUBYLIB = / home / git / project /
它不再找到帮助文件。我以为ruby应该搜索我提供的整个路径,而不只是最外层的目录提供?这是正确的思考方式吗?如果没有,我该怎么做,所以RUBY将搜索所有子目录及其子目录等?
谢谢,
Robin
正如buruzaemon所提到的,Ruby不会搜索子目录,所以你需要包含你想要的所有目录在您的搜索路径。但是,您可能想要做的是:
require'app / helpers / output_helper'
这样你不会依赖于 RUBYLIB
环境变量设置一定办法。当您将代码部署到生产或与他人协作时,这些小的依赖关系可能会导致烦人的调试会话。
另外作为附注,您可以指定。
作为搜索路径,而不是使用机器特定的绝对路径。
So currently I have included the following in my .bashrc file.
export RUBYLIB=/home/git/project/app/helpers
I am trying to run rspec with a spec that has
require 'output_helper'
This file is in the helpers directory. My question is that when I change the export line to:
export RUBYLIB=/home/git/project/
It no longer finds the helper file. I thought that ruby should search the entire path I supply, and not just the outermost directory supplied? Is this the correct way to think about it? And if not, how can I make it so RUBY will search through all subdirectories and their subdirectories, etc?
Thanks,
Robin
As buruzaemon mentions, Ruby does not search subdirectories, so you need to include all the directories you want in your search path. However, what you probably want to do is:
require 'app/helpers/output_helper'
This way you aren't depending on the RUBYLIB
environment variable being set a certain way. When you're deploying code to production, or collaborating with others, these little dependencies can make for annoying debugging sessions.
Also as a side note, you can specify .
as a search path, rather than using machine-specific absolute paths.
这篇关于RUBYLIB环境路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!