[DRE-commits] [SCM] gem2deb.git branch, master, updated. 7ec46a91564d286f29dcb79e6fa9bf4301ed631e

Antonio Terceiro terceiro at softwarelivre.org
Mon May 9 20:20:39 UTC 2011


The following commit has been merged in the master branch:
commit 8de3c95d1b3175fd3c8bb3e70e8e5033eef43598
Author: Antonio Terceiro <terceiro at softwarelivre.org>
Date:   Mon May 9 10:06:07 2011 -0700

    Extract method to read the supported Ruby versions
    
    Add tests

diff --git a/lib/gem2deb/dh_ruby.rb b/lib/gem2deb/dh_ruby.rb
index d199168..d70acab 100644
--- a/lib/gem2deb/dh_ruby.rb
+++ b/lib/gem2deb/dh_ruby.rb
@@ -92,22 +92,19 @@ module Gem2Deb
     def install(argv)
       puts "  Entering dh_ruby --install" if @verbose
 
+      supported_versions =
+        if all_ruby_versions_supported?
+          SUPPORTED_RUBY_VERSIONS.keys.clone
+        else
+          ruby_versions.clone
+        end
+
       package = packages.first
 
       install_files('bin', find_files('bin'), File.join(destdir_for(package), @bindir),             755) if File::directory?('bin')
 
       install_files('lib', find_files('lib'), File.join(destdir_for(package), RUBY_CODE_DIR), 644) if File::directory?('lib')
 
-      # find ruby versions to build the package for.
-      l = IO::readlines('debian/control').grep(/^XS-Ruby-Versions: /)
-      if l.empty?
-        puts "No XS-Ruby-Versions: field found in source!"
-        exit(1)
-      end
-      supported_versions = l[0].split[1..-1]
-      if supported_versions.include?('all')
-        supported_versions = SUPPORTED_RUBY_VERSIONS.keys
-      end
 
       if metadata.has_native_extensions?
         supported_versions.each do |rubyver|
@@ -353,6 +350,24 @@ module Gem2Deb
       @packages ||= `dh_listpackages`.split
     end
 
+    def ruby_versions
+      @ruby_versions ||=
+        begin
+          # find ruby versions to build the package for.
+          lines = File.readlines('debian/control').grep(/^XS-Ruby-Versions: /)
+          if lines.empty?
+            puts "No XS-Ruby-Versions: field found in source!" if @verbose
+            exit(1)
+          else
+            lines.first.split[1..-1]
+          end
+        end
+    end
+
+    def all_ruby_versions_supported?
+      ruby_versions.include?('all')
+    end
+
     def run_make_clean_on_extensions
       if metadata.has_native_extensions?
         metadata.native_extensions.each do |extension|
diff --git a/test/unit/dh_ruby_test.rb b/test/unit/dh_ruby_test.rb
index 35d78fa..3d4ee2d 100644
--- a/test/unit/dh_ruby_test.rb
+++ b/test/unit/dh_ruby_test.rb
@@ -85,6 +85,30 @@ class DhRubyTest < Gem2DebTestCase
     end
   end
 
+  context 'versions supported' do
+    setup do
+      @dh_ruby = Gem2Deb::DhRuby.new
+      @dh_ruby.verbose = false
+    end
+    should 'bail out if XS-Ruby-Versions is not found' do
+      File.expects(:readlines).with('debian/control').returns([])
+      @dh_ruby.expects(:exit).with(1)
+      @dh_ruby.send(:ruby_versions)
+    end
+    should 'read supported versions from debian/control' do
+      File.expects(:readlines).with('debian/control').returns(["XS-Ruby-Versions: all\n"])
+      assert_equal ['all'], @dh_ruby.send(:ruby_versions)
+    end
+    should 'known when all versions are supported' do
+      @dh_ruby.stubs(:ruby_versions).returns(['all'])
+      assert_equal true, @dh_ruby.send(:all_ruby_versions_supported?)
+    end
+    should 'known when not all versions are supported' do
+      @dh_ruby.stubs(:ruby_versions).returns(['ruby1.8'])
+      assert_equal false, @dh_ruby.send(:all_ruby_versions_supported?)
+    end
+  end
+
   protected
 
   def assert_installed(gem_dirname, package, path)

-- 
gem2deb.git



More information about the Pkg-ruby-extras-commits mailing list