File: module_spec.rb

package info (click to toggle)
ruby-puppet-forge 5.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,196 kB
  • sloc: ruby: 2,397; makefile: 3
file content (101 lines) | stat: -rw-r--r-- 3,427 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
require 'spec_helper'

describe PuppetForge::V3::Module do
  before do
    stub_api_for(PuppetForge::V3::Base) do |stubs|
      stub_fixture(stubs, :get, '/v3/modules/puppetlabs-apache')
      stub_fixture(stubs, :get, '/v3/modules/absent-apache')
      stub_fixture(stubs, :get, '/v3/users/puppetlabs')
      stub_fixture(stubs, :get, '/v3/releases/puppetlabs-apache-0.0.1')
      stub_fixture(stubs, :get, '/v3/releases/puppetlabs-apache-0.0.2')
      stub_fixture(stubs, :get, '/v3/releases/puppetlabs-apache-0.0.3')
      stub_fixture(stubs, :get, '/v3/releases/puppetlabs-apache-0.0.4')
      stub_fixture(stubs, :get, '/v3/releases/puppetlabs-apache-0.1.1')
      stub_fixture(stubs, :get, '/v3/releases?module=puppetlabs-apache')
    end
  end

  describe '::find' do
    let(:mod) { PuppetForge::V3::Module.find('puppetlabs-apache') }
    let(:mod_stateless) { PuppetForge::V3::Module.find_stateless('puppetlabs-apache') }
    let(:missing_mod) { PuppetForge::V3::Module.find('absent-apache') }

    it 'can find modules that exist' do
      expect(mod.name).to eq('apache')
    end

    it 'can find modules that exist from a stateless call' do
      expect(mod_stateless.name).to eq('apache')
    end

    it 'raises exception for non-existent modules' do
      expect { missing_mod }.to raise_error(PuppetForge::ModuleNotFound, 'Module absent-apache not found')
    end
  end

  describe '#owner' do
    let(:mod) { PuppetForge::V3::Module.find('puppetlabs-apache') }

    it 'exposes the related module as a property' do
      expect(mod.owner).to_not be nil
    end

    it 'grants access to module attributes without an API call' do
      expect(PuppetForge::V3::User).not_to receive(:request)
      expect(mod.owner.username).to eql('puppetlabs')
    end

    it 'transparently makes API calls for other attributes' do
      expect(PuppetForge::V3::User).to receive(:request).once.and_call_original
      expect(mod.owner.created_at).to_not be nil
    end
  end

  describe '#current_release' do
    let(:mod) { PuppetForge::V3::Module.find('puppetlabs-apache') }

    it 'exposes the current_release as a property' do
      expect(mod.current_release).to_not be nil
    end

    it 'grants access to release attributes without an API call' do
      expect(PuppetForge::V3::Release).not_to receive(:request)
      expect(mod.current_release.version).to_not be nil
    end

  end

  describe '#releases' do
    let(:mod) { PuppetForge::V3::Module.find('puppetlabs-apache') }

    it 'exposes the related releases as a property' do
      expect(mod.releases).to be_an Array
    end

    it 'knows the size of the collection' do
      expect(mod.releases).to_not be_empty
    end

    it 'grants access to release attributes without an API call' do
      expect(PuppetForge::V3::Release).not_to receive(:request)
      expect(mod.releases.map(&:version)).to_not include nil
    end

    it 'loads releases lazily' do
      versions = %w[ 0.0.1 0.0.2 0.0.3 0.0.4 0.1.1 ]
      releases = mod.releases.select { |x| versions.include? x.version }

      expect(PuppetForge::V3::Base).to receive(:request).exactly(5).times.and_call_original

      expect(releases.map(&:downloads)).to_not include nil
    end
  end

  describe 'instance properies' do
    let(:mod) { PuppetForge::V3::Module.find('puppetlabs-apache') }

    example 'are easily accessible' do
      expect(mod.created_at).to_not be nil
    end
  end
end