Example #1
0
def test_absent_with_version_not_installed(monkeypatch):
    monkeypatch.setattr(
        Gem, 'run',
        build_run(fixture_subpath='gem',
                  command_mappings=[
                      CommandMapping(
                          command=['gem', 'specification', '--all', 'rails'],
                          returncode=1)
                  ]))

    gem = Gem(name='rails', version='5.1.6', state='absent', executable='gem')
    assert gem.process() == ActionResponse(changed=False)
Example #2
0
def test_present_with_version_installed(monkeypatch):
    monkeypatch.setattr(
        Gem, 'run',
        build_run(
            fixture_subpath='gem',
            command_mappings=[
                CommandMapping(
                    command=['gem', 'specification', '--all', 'rails'],
                    stdout_filename='gem_specification_all_installed.stdout')
            ]))

    gem = Gem(name='rails', version='5.2.0', state='present', executable='gem')
    assert gem.process() == ActionResponse(changed=False)
Example #3
0
def test_latest_not_installed(monkeypatch):
    monkeypatch.setattr(
        Gem, 'run',
        build_run(fixture_subpath='gem',
                  command_mappings=[
                      CommandMapping(
                          command=['gem', 'specification', '--all', 'rails'],
                          returncode=1),
                      CommandMapping(command=['gem', 'install', 'rails'])
                  ]))

    gem = Gem(name='rails', state='latest', executable='gem')
    assert gem.process() == ActionResponse(changed=True)
Example #4
0
def test_specification_output_invalid(monkeypatch):
    monkeypatch.setattr(
        Gem, 'run',
        build_run(fixture_subpath='gem',
                  command_mappings=[
                      CommandMapping(
                          command=['gem', 'specification', '--all', 'rails'],
                          stdout_filename=
                          'gem_specification_all_invalid_output.stdout')
                  ]))

    gem = Gem(name='rails', state='present', executable='gem')
    with pytest.raises(ActionError):
        gem.process()
Example #5
0
def test_absent_installed(monkeypatch):
    monkeypatch.setattr(
        Gem, 'run',
        build_run(
            fixture_subpath='gem',
            command_mappings=[
                CommandMapping(
                    command=['gem', 'specification', '--all', 'rails'],
                    stdout_filename='gem_specification_all_installed.stdout'),
                CommandMapping(command=[
                    'gem', 'uninstall', '--all', '--executables', 'rails'
                ])
            ]))

    gem = Gem(name='rails', state='absent', executable='gem')
    assert gem.process() == ActionResponse(changed=True)
Example #6
0
def test_latest_installed_and_up_to_date(monkeypatch):
    monkeypatch.setattr(
        Gem, 'run',
        build_run(
            fixture_subpath='gem',
            command_mappings=[
                CommandMapping(
                    command=['gem', 'specification', '--all', 'rails'],
                    stdout_filename='gem_specification_all_installed.stdout'),
                CommandMapping(
                    command=['gem', 'specification', '--remote', 'rails'],
                    stdout_filename='gem_specification_remote.stdout')
            ]))

    gem = Gem(name='rails', state='latest', executable='gem')
    assert gem.process() == ActionResponse(changed=False)
Example #7
0
def test_argument_state_invalid():
    with pytest.raises(ValueError):
        Gem(name='rails', state='hmmm')
Example #8
0
def test_argument_state_after_init_invalid():
    gem = Gem(name='rails', version='5.2.0')
    with pytest.raises(ValueError):
        gem.state = 'latest'
Example #9
0
def test_argument_version_state_combination_invalid():
    with pytest.raises(ValueError):
        Gem(name='rails', state='latest', version='5.2.0')