我的 gem 如何知道其存储库目录的路径?
我的 gem Semantictext 有一堆测试数据,它会读取这些数据以进行回归测试。
这是项目: http://github.com/dafydd/semantictext
这是我想要的示例测试能够直接从 gem 运行: http://github. com/dafydd/semantictext/blob/master/test/test_document.rb(查找文本“SANDBOX”)
我通常在名为“semantictext”的目录中开发它,并将环境变量 SANDBOX 设置为“semantictext”上方的目录 - 这样我就可以使用 ENV['SANDBOX'] 引用项目中的任何文件。
当 gem 作为包安装时,有没有办法让从 rake 运行的测试/单元测试可以:
1) 知道它是从 gem 运行的?
2) 知道本地 rubygems 存储库中的语义文本目录的路径吗?
我希望能够轻松地从任何 gem 安装运行所有测试。这将使我的持续集成变得更容易,并允许我编写更好的 gem。
谢谢, 达菲德
My gem semantictext has a bunch of test data that it reads for regression testing.
Here's the project: http://github.com/dafydd/semantictext
Here's an example test that I want to be able to run directly from the gem: http://github.com/dafydd/semantictext/blob/master/test/test_document.rb (look for text "SANDBOX")
I normally develop it in a directory called "semantictext" and have the environment variable SANDBOX set to the path of the directory above "semantictext" - so that I can reference any file in the project using ENV['SANDBOX'].
When the gem is installed as a package, is there a way that the test/unit test running from rake can:
1) know that it's running from a gem? and
2) know the path to it's semantictext directory within the local rubygems repository?
I want to make it effortless to be able to run all the tests from any gem installation. This would make my continuous integration a bit easier and allow me to write better gems.
Thanks,
Dafydd
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用以下方法找到当前文件的目录:
这将允许您建立您需要访问的任何文件的相对路径。
You can find out the directory of the current file using:
This will allow you to build up a relative path to whatever file you need to access.