By default, gem2deb will pull an upstream tarball from rubygems.org. Some Ruby upstreams consider Rubygems to be some kind of "binary" repository, so they don't upload the full source, which usually means not including the test files (test/*, spec/*, etc). The solution to this is usually updating debian/watch to pull source tarballs from github, and re-running dh-make-ruby so that it creates the file under debian/ (usually debian/ruby-tests.rake) that will drive the test execution, both during the build, and under autopkgtest.

Introduction to software testing

Most Ruby libraries contain code to test the functionality provided by the library and compare results with known inputs. One commonly used testing framework is RSpec, indicated by a spec directory in your gem's root folder. Other test frameworks may use a test directory.

Running tests

If the gem has tests defined (usually has a test or spec directory), make sure you run them successfully. Your package should contain one (and only one) of debian/ruby-test-file.yaml, ruby-tests.rake, or ruby-tests.rb.

1. By default, gem2deb creates debian/ruby-test-files.yaml. However, this may not always work. If your test or spec directory contains files with extentions other than .rb, this is most certainly going to fail. You can try removing non-ruby files from ruby-test-files.yaml and rebuild it. If it still does not work, try the other two methods described below.

2. You may also try ruby-tests.rake if the gem uses rspec to run the tests (in this case you have a spec/ directory with *_spec.rb files). See ruby-dataobjects-sqlite3 for an example.

3. You can try ruby-tests.rb, see ruby-warden for an example. It allows you to add custom directories to ruby library load path and you may need it if your tests fail to find files already present in 'lib' or 'test' directories.

Note: If you don't find ruby-tests.rb in debian directory, you have to create it from the sample file given above. You have to remove ruby-test-files.yaml too. Uncomment this line in ruby-tests.rb to add custom library paths.

$: << 'lib' << '.'

If it could be done with not much effort, consider instead patching the tests not to override default $LOADPATH (aka $:) variable.

Examples

Gem provide a test runner (ruby-vegas) - It has test_vegas_runner.rb, so just use it from ruby-tests.rb

require 'test/test_vegas_runner.rb'

Dealing with Bundler usage

Tips for rails testapp/dummy app or when you can't easily remove bundler usage by patching. Some libraries meant to work with rails create a dummy rails app to test their functionality with a rails app. "case six: bundle install" tells you how to avoid bundler completely. If that fails, try the steps below.

Remove Gemfile.lock (use quilt) as we can't expect debian environment to match exact versions of libraries used by the upstream developers.

Add build dependencies on bundler and rubygems-integration

Patch out Gemfile/gemspec/metadata.yml if bundler insist on a specific version of library and debian already has a newer version. Relax the dependency as ">="

Common errors

First, check for build-depencies on rubygems.org--they are listed as development (see also the commented line in debian/control produced by gem2deb). You may not need all the build dependencies listed there; the only way to be sure is to see the build errors. Many of these dependencies are required during the tests.

Case one: missing library/gem

If you see a file is missing in the error message, it may be provided by a gem not yet installed in your system. For example, if you see

no such file to load -- shoulda (LoadError),

search for shoulda, ie,

$ apt-cache search shoulda

If you find it is already packaged, install it with

# apt-get install ruby-shoulda

Note: Remember to add the build dependency you just found to Build-Depends in debian/control (edit this file)

Case five: tests failure due to interactions

Sometimes, tests may pass perfectly when they are run separately and fail when we are building it because then the tests are running together and interact with each other. To see if the tests pass individually, run the following commands inside the test directory.

RUBY=ruby1.8 ./run_tests.sh
RUBY=ruby1.9.1 ./run_tests.sh

If the tests are passing now, you may want to figure out a way and edit the debian/ruby-tests.rb file by which the tests can run without interacting with each other. One such fix made to the ruby-tests.rb file is as follows.

The new ruby-tests.rb has a loop: for every test file, call ruby with this test file, and raise an exception if the test fails this way, all the tests are run separately.

Case six: bundle install

If you get an error like this asking you to run bundle install for any gem,

Could not find gem 'rake (>= 0) ruby' in the gems available on this machine.
Run `bundle install` to install missing gems.

Then it means the package is using bundler to satisfy dependencies. Building a deb package should not require use of bundler to install dependencies, but instead all dependencies should be provided in debian/control file as "Build-Depends:" and "Depends:"

You'll have to create a patch to un-comment use of bundler or rubygems like this. (example from ruby-rack-rewrite). Use quilt to create the patch. See basic quilt for help in using quilt.

Case seven: NoMethodError

It usually means the library is using bundler to require other libraries and which are missing, see "Case six" above for details. We can add those dependencies manually by patching test_helper.rb or spec_helper.rb as is the case.

Using these as reference, we add those as require lines in the patch. If you cannot solve case six and seven, see "Dealing with Bundler usage"

Case eight: autopkgtest failure

If the tests run correctly during build, but fail in autopkgtest, it is most likely because of using relative paths in tests and gem2deb-test-runner will remove lib directory from source tree during tests. You can look at ruby-fog-rackspace as an example.

Case nine: tests missing from the upstream tarball

By default, gem2deb will pull an upstream tarball from rubygems.org. Some Ruby upstreams consider Rubygems to be some kind of "binary" repository, so they don't upload the full source, which usually means not including the test files (test/*, spec/*, etc). The solution to this is usually updating debian/watch to pull source tarballs from github, and re-running dh-make-ruby so that it creates the file under debian/ (usually debian/ruby-tests.rake) that will drive the test execution, both during the build, and under autopkgtest.