问题描述
我是开发Ruby gem的新手,但是我想尝试一下.
I am new to developing Ruby gems, but I thought I'd give it a try.
最近查看了Railscasts的最新剧集(http://railscasts.com/episodes/245-new-gem-with-bundler),我正在使用Bundler来创建我的宝石.
Recently checking out the latest episode on Railscasts (http://railscasts.com/episodes/245-new-gem-with-bundler) I'm using Bundler to create my gem.
但是我对如何测试我的宝石一无所知.
However I'm kind of clueless on how to test my gem.
我可以先运行 rake install ,然后从 irb 要求它,但这对我来说似乎是一种缓慢的工作流程.
Sure I could run rake install and then require it from irb, but this seems like a kind of slow workflow for me.
我想做的是创建一个虚拟的Rails应用程序,并通过引用它的源代码来要求gem.这可能吗?我敢肯定我在某处读过它……
What I'd like to do is create a dummy Rails app and require the gem by referencing to it's source code. Is this possible? I'm sure I've read about it somewhere…
谢谢!
推荐答案
您可以在Rakefile中包含以下行:
You can include these lines in your Rakefile:
task :console do
exec "irb -r mygem -I ./lib"
end
这将创建一个rake任务,以初始化一个新的irb会话并预加载您的库.现在,您要做的就是:
This will create a rake task to initialize a new irb session and preload your library. Now, all you have to do is:
$ rake console
这篇关于开发宝石和测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!