File: module_spec.rb

package info (click to toggle)
r10k 5.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,228 kB
  • sloc: ruby: 18,180; makefile: 10; sh: 1
file content (110 lines) | stat: -rw-r--r-- 4,282 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
require 'spec_helper'
require 'r10k/module'

describe R10K::Module do
  describe 'delegating to R10K::Module::Git' do
    [ {git: 'git url'},
      {type: 'git', source: 'git url'},
    ].each do |scenario|
      it "accepts a name matching 'test' and args #{scenario.inspect}" do
        obj = R10K::Module.new('test', '/modulepath', scenario)
        expect(obj).to be_a_kind_of(R10K::Module::Git)
        expect(obj.send(:instance_variable_get, :'@remote')).to eq('git url')
      end
    end
  end

  describe 'delegating to R10K::Module::Svn' do
    [ {svn: 'svn url'},
      {type: 'svn', source: 'svn url'},
    ].each do |scenario|
      it "accepts a name matching 'test' and args #{scenario.inspect}" do
        obj = R10K::Module.new('test', '/modulepath', scenario)
        expect(obj).to be_a_kind_of(R10K::Module::SVN)
        expect(obj.send(:instance_variable_get, :'@url')).to eq('svn url')
      end
    end
  end

  describe 'delegating to R10K::Module::Forge' do
    [ 'bar/quux',
      'bar-quux',
    ].each do |scenario|
      it "accepts a name matching #{scenario} and version nil" do
        obj = R10K::Module.new(scenario, '/modulepath', { type: 'forge', version: nil })
        expect(obj).to be_a_kind_of(R10K::Module::Forge)
      end
    end
    [ {type: 'forge', version: '8.0.0'},
    ].each do |scenario|
      it "accepts a name matching bar-quux and args #{scenario.inspect}" do
        obj = R10K::Module.new('bar-quux', '/modulepath', scenario)
        expect(obj).to be_a_kind_of(R10K::Module::Forge)
        expect(obj.send(:instance_variable_get, :'@expected_version')).to eq('8.0.0')
      end
    end

    describe 'when the module is ostensibly on disk' do
      before do
        owner = 'theowner'
        module_name = 'themodulename'
        @title = "#{owner}-#{module_name}"
        metadata = <<~METADATA
          {
            "name": "#{@title}",
            "version": "1.2.0"
          }
        METADATA
        @dirname = Dir.mktmpdir
        module_path = File.join(@dirname, module_name)
        FileUtils.mkdir(module_path)
        File.open("#{module_path}/metadata.json", 'w') do |file|
           file.write(metadata)
        end
      end

      it 'sets the expected version to what is found in the metadata' do
        obj = R10K::Module.new(@title, @dirname, {type: 'forge', version: nil})
        expect(obj.send(:instance_variable_get, :'@expected_version')).to eq('1.2.0')
      end
    end
  end

  it "raises an error if delegation fails" do
    expect {
      R10K::Module.new('bar!quux', '/modulepath', {version: ["NOPE NOPE NOPE NOPE!"]})
    }.to raise_error RuntimeError, /doesn't have an implementation/
  end

  describe 'Given a set of initialization parameters for R10K::Module' do
    [ ['name', {git: 'git url'}],
      ['name', {type: 'git', source: 'git url'}],
      ['name', {svn: 'svn url'}],
      ['name', {type: 'svn', source: 'svn url'}],
      ['namespace-name', {type: 'forge', version: '8.0.0'}]
    ].each do |(name, options)|
      it 'can handle the default_branch_override option' do
        expect {
          obj = R10K::Module.new(name, '/modulepath', options.merge({default_branch_override: 'foo'}))
          expect(obj).to be_a_kind_of(R10K::Module::Base)
        }.not_to raise_error
      end
      describe 'the exclude_spec setting' do
        it 'sets the exclude_spec instance variable to true by default' do
          obj = R10K::Module.new(name, '/modulepath', options)
          expect(obj.instance_variable_get("@exclude_spec")).to eq(true)
        end
        it 'cannot be overridden by the settings from the cli, r10k.yaml, or settings default' do
          options = options.merge({exclude_spec: false, overrides: {modules: {exclude_spec: true}}})
          obj = R10K::Module.new(name, '/modulepath', options)
          expect(obj.instance_variable_get("@exclude_spec")).to eq(false)
        end
        it 'reads the setting from the cli, r10k.yaml, or settings default when not provided directly' do
          options = options.merge({overrides: {modules: {exclude_spec: false}}})
          obj = R10K::Module.new(name, '/modulepath', options)
          expect(obj.instance_variable_get("@exclude_spec")).to eq(false)
        end
      end
    end
  end
end