Commit f5597f66 authored by Léo-Paul Géneau's avatar Léo-Paul Géneau 👾 Committed by Julien Muchembled

Fix undefined rubygems version

Traceback (most recent call last):
  ...
    recipe.install()
  File "rubygemsrecipe/rubygems.py", line 347, in install
    gem_executable):
  File "rubygemsrecipe/rubygems.py", line 300, in get_dependency_list
    if self.version[0] < '3':
TypeError: 'NoneType' object has no attribute '__getitem__'

The test that was added in 60b10788 is adapted due to the call to subprocess.checkout .

See merge request !7
parent 60b10788
Pipeline #17306 running with stage
in 0 seconds
......@@ -293,6 +293,11 @@ class Recipe(object):
gem_executable = glob.glob(gem_executable + '*')
if gem_executable:
if not self.version:
self.version = self.run([
gem_executable[0],
'--version',
])
return gem_executable[0]
def get_dependency_list(self, gem_dict, gem_executable):
......
......@@ -17,6 +17,8 @@ import zc.buildout
import rubygems
RUBYGEMS_DEFAULT_VERSION = '2.0.0'
def touch(path):
with path.open('w') as f:
......@@ -24,7 +26,7 @@ def touch(path):
class fixture(object):
def __init__(self, options=None, version='2.0.0'):
def __init__(self, options=None, version=RUBYGEMS_DEFAULT_VERSION):
self.options = options or {}
self.version = version
......@@ -61,7 +63,9 @@ class fixture(object):
('download', 'rubygems.Download'),
))
self.patches['urlopen'].return_value = BytesIO(
b'https://rubygems.org/rubygems/rubygems-2.0.0.zip'
bytes(('https://rubygems.org/rubygems/rubygems-%s.zip'
% RUBYGEMS_DEFAULT_VERSION
).encode('utf-8'))
)
self.makedirs((
......@@ -108,8 +112,9 @@ class RubyGemsTestCase(unittest.TestCase):
args = patches['download'].mock_calls[0][1]
self.assertEqual(args[2], {
'url': 'https://rubygems.org/rubygems/rubygems-2.0.0.zip',
'destination': str(path / 'rubygems-2.0.0'),
'url': 'https://rubygems.org/rubygems/rubygems-%s.zip'
% RUBYGEMS_DEFAULT_VERSION,
'destination': str(path / ('rubygems-' + RUBYGEMS_DEFAULT_VERSION)),
})
expected_install_arg_list_list.insert(0, [
......@@ -193,13 +198,14 @@ class RubyGemsDefaultTestCase(RubyGemsTestCase):
@fixture({'recipe': {
'gems': 'sass',
'url': 'https://rubygems.org/rubygems/rubygems-2.0.0.zip',
'url': 'https://rubygems.org/rubygems/rubygems-%s.zip'
% RUBYGEMS_DEFAULT_VERSION,
}})
def test_version_from_url(self, path, patches, buildout, name, options, version):
recipe = rubygems.Recipe(buildout, name, options)
recipe.install()
@fixture({'recipe': {'gems': 'sass'}, 'version': '2.0.0'})
@fixture({'recipe': {'gems': 'sass'}, 'version': RUBYGEMS_DEFAULT_VERSION})
def test_version(self, path, patches, buildout, name, options, version):
recipe = rubygems.Recipe(buildout, name, options)
recipe.install()
......@@ -236,7 +242,7 @@ class RubyGemsDefaultTestCase(RubyGemsTestCase):
touch(path / 'rubygems/bin/gem')
recipe.install()
args = patches['check_output'].mock_calls[0][1]
args = patches['check_output'].mock_calls[1][1]
for arg in args[0]:
matched = re.search('^--version.*$', arg)
if matched:
......@@ -303,9 +309,13 @@ class RubyGemsDeploymentTestCase(RubyGemsTestCase):
path, patches, expected_install_arg_list_list)
@deployment_fixture({'recipe': {'gems': 'hashie==0.3.1'}})
@mock.patch('rubygems.Recipe.get_gem_executable')
def test_already_installed_rubygems(
self, path, patches, buildout, name, options, version):
self, path, patches, buildout, name, options, version, get_gem_exe):
touch(path / 'rubygems/bin/gem')
def mocked_get_gem_exe(_):
self.version = RUBYGEMS_DEFAULT_VERSION
get_gem_exe.side_effect = mocked_get_gem_exe
self.deployment_install_test(
buildout, name, path, patches, options, version)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment