0

を使用してルビジェムを構築していました

gem build $gemname.gemspec && gem install $gemname-0.0.1.gem

ただし、gem をローカル環境から ruby​​gems パスに移動するため、これは gem をテストするための最良の方法ではないようです。

を使用してgemを構築することをお勧めします

cd ext/$gemname && ruby extconf.rb && make

? または、より良いプラクティスはありますか?

4

1 に答える 1

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
于 2012-11-05T22:41:51.220 に答える