我正在使用
构建一个rubygemgem build $gemname.gemspec && gem install $gemname-0.0.1.gem
然而,这似乎并不是测试gem的最佳方法,因为它将它移出局部环境并进入rubygems路径。
建议使用
构建gemcd ext/$gemname && ruby extconf.rb && make
?还是有更好的做法?
答案 0 :(得分:0)
我猜测下面的Rakefile也会起作用(并且比上面的命令更容易)。但是,这对测试来说并不明显。
require 'rake/testtask'
require 'rake/clean'
NAME = 'hola'
# rule to build the extension: this says
# that the extension should be rebuilt
# after any change to the files in ext
file "lib/#{NAME}/#{NAME}.so" =>
Dir.glob("ext/#{NAME}/*{.rb,.c}") do
Dir.chdir("ext/#{NAME}") do
# this does essentially the same thing
# as what RubyGems does
ruby "extconf.rb"
sh "make"
end
cp "ext/#{NAME}/#{NAME}.so", "lib/#{NAME}"
end
# make the :test task depend on the shared
# object, so it will be built automatically
# before running the tests
task :test => "lib/#{NAME}/#{NAME}.so"
# use 'rake clean' and 'rake clobber' to
# easily delete generated files
CLEAN.include('ext/**/*{.o,.log,.so}')
CLEAN.include('ext/**/Makefile')
CLOBBER.include('lib/**/*.so')
# the same as before
Rake::TestTask.new do |t|
t.libs << 'test'
end
desc "Run tests"
task :default => :test