rspec-puppet-utils 3.2.2 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f89a0b9d1954d53efa11f7127b7a0b074eac63b0
4
- data.tar.gz: 8b952e545404d63e1b2824c8ec54ba0ab292ca9f
3
+ metadata.gz: 9889ff4f04abf064cb1bb613d08cc43ab297dddc
4
+ data.tar.gz: 5962bbdd9291625f70a65b53d3cdb17ccb513efd
5
5
  SHA512:
6
- metadata.gz: 79e5d9f74540f16112126eff2572e5221c97dc9ce8a51047a8c136bd68a873e0f6b60d632ded9d6481c40032dcf2a2d2be97f803dab904d60280b43a804a819d
7
- data.tar.gz: 620b9073ef83624615d028d929a2c8df9a2aa182a16b5db8e848b0093f8710aeda35ef1751a25a226a8d0d1844fac54f8b0a28435c2c040ba6e8125eca871d1a
6
+ metadata.gz: d51415db60d4fcac48d2b1710550e8fc1e7ee7c6251d7645eb6699ba6a2b3eabf2a125b45800692c6d621d1b64d125606d405f1ef93034f68c7719aa7c1d1aa3
7
+ data.tar.gz: 0184e3591aeb8c9bb8f4719ec5b731189d1a651492ab32a9f4761b5d681e7215c7ef42d4e5b9d4b24c69f11241dfc17660ce2eeb1378d06728049af582f89b7c
@@ -8,12 +8,12 @@ module Rake
8
8
 
9
9
  class Puppet
10
10
 
11
- attr_accessor :module_path, :excluded_modules
11
+ attr_accessor :module_dirs, :excluded_modules
12
12
  attr_accessor :package_dir, :package_files, :package_version, :package_versioning
13
13
 
14
- @module_path # (string) The directory containing all the modules to test
15
- @excluded_dirs # (string[]) Directories excluded from rspec search
16
- @excluded_modules # (string[]) Modules excluded from rspec testing
14
+ @module_dirs # (string[]) The directories containing modules to test
15
+ @excluded_dirs # (string[]) Directories excluded from spec search
16
+ @excluded_modules # (string[]) Modules excluded from spec testing
17
17
  @package_dir # (string) Where the puppet zip package will be created
18
18
  @package_files # (string[]) Files and directories to include in the package
19
19
  @package_name # (string) Name of the package
@@ -23,11 +23,11 @@ module Rake
23
23
  def initialize
24
24
  extend Rake::DSL # makes 'namespace' and 'task' methods available to instance
25
25
 
26
- @module_path = 'modules' # Deliberately excludes modules-lib dir
26
+ @module_dirs = ['lib', 'site'] # Deliberately excludes 'modules' dir
27
27
  @excluded_dirs = ['.', '..']
28
28
  @excluded_modules = []
29
29
  @package_dir = 'pkg'
30
- @package_files = ['modules', 'modules-lib', 'environment.conf']
30
+ @package_files = @module_dirs + ['modules', 'hieradata', 'environment.conf']
31
31
  @package_name = 'puppet'
32
32
  @package_version = nil
33
33
  @package_versioning = true
@@ -39,23 +39,29 @@ module Rake
39
39
  end
40
40
 
41
41
  def testable_modules
42
- raise ArgumentError, 'Excluded modules must be an array' unless @excluded_modules.is_a? Array
43
- module_dirs = Dir.entries(@module_path) - @excluded_dirs - @excluded_modules
44
- filter_modules module_dirs
42
+ raise ArgumentError, 'module_paths must be an array' unless @module_dirs.is_a? Array
43
+ raise ArgumentError, 'excluded_modules must be an array' unless @excluded_modules.is_a? Array
44
+ modules = []
45
+ @module_dirs.each { |module_dir|
46
+ raise ArgumentError, "Module path #{module_dir} could not be found" unless Dir.exist?(module_dir)
47
+ entries = Dir.entries(module_dir) - @excluded_dirs - @excluded_modules
48
+ modules.concat entries.collect { |entry| "#{module_dir}/#{entry}" }
49
+ }
50
+ filter_modules modules
45
51
  end
46
52
 
47
- def filter_modules(module_dirs)
48
- module_dirs.select! { |m| module_has_specs?(m) and module_has_rakefile?(m) }
49
- module_dirs
53
+ def filter_modules(modules)
54
+ modules.select! { |m| module_has_specs?(m) and module_has_rakefile?(m) }
55
+ modules
50
56
  end
51
57
 
52
58
  def module_has_specs?(module_dir)
53
- File.directory?("#{@module_path}/#{module_dir}/spec")
59
+ File.directory? "#{module_dir}/spec"
54
60
  end
55
61
 
56
62
  def module_has_rakefile?(module_dir)
57
63
  rakefiles = ['rakefile', 'rakefile.rb']
58
- entries = Dir.entries("#{@module_path}/#{module_dir}")
64
+ entries = Dir.entries module_dir
59
65
  entries.collect! { |f| f.downcase }
60
66
  rakefiles.each { |rf| return true if entries.include? rf }
61
67
  false
@@ -63,27 +69,25 @@ module Rake
63
69
 
64
70
  def load_module_tasks
65
71
 
66
- modules = testable_modules
67
- spec_tasks = modules.collect { |m| "#{m}:#{:spec}" }
68
- # lint_tasks = modules.collect { |m| "#{m}:#{:lint}" }
72
+ modules = testable_modules
73
+ module_names = testable_modules.collect { |m| m.split('/')[1] }
74
+ spec_tasks = module_names.collect { |mn| "#{mn}:#{:spec}" }
75
+
76
+ modules.each_with_index { |module_path, i|
69
77
 
70
- modules.each { |puppet_module|
71
- namespace puppet_module do
78
+ module_name = module_names[i]
72
79
 
73
- desc "Run #{puppet_module} module specs"
80
+ namespace module_name do
81
+ desc "Run #{module_name} module specs"
74
82
  task :spec do
75
- Dir.chdir "#{@module_path}/#{puppet_module}" do
83
+ Dir.chdir module_path do
76
84
  success = system('rake spec') # This isn't perfect but ...
77
85
  exit 1 unless success
78
86
  end
79
87
  end
80
-
81
88
  end
82
89
  }
83
90
 
84
- # desc 'Run lint checks for all modules'
85
- # task :lint => lint_tasks
86
-
87
91
  desc 'Run specs in all modules'
88
92
  task :spec => spec_tasks
89
93
  task :default => :spec
@@ -109,7 +113,7 @@ module Rake
109
113
 
110
114
  task :package => [:prep] do
111
115
  # Exclude all the spec code as it's not needed once deployed
112
- exclude_patterns = ['modules/\*/spec/\*', 'modules-lib/\*/spec/\*']
116
+ exclude_patterns = ['\*/\*/spec/\*']
113
117
  exclude_string = "-x #{exclude_patterns.join(' ')}"
114
118
  include_string = @package_files.join(' ')
115
119
  cmd = "zip -qr #{package_path} #{include_string} #{exclude_string}"
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |gem|
3
3
  gem.name = 'rspec-puppet-utils'
4
- gem.version = '3.2.2'
4
+ gem.version = '3.3.0'
5
5
  gem.description = 'Helper classes for mock/stub functions, templates and hieradata'
6
6
  gem.summary = ''
7
7
  gem.author = 'Tom Poulton'
@@ -3,10 +3,10 @@ require 'lib/rspec_puppet_utils/rake/project_tasks'
3
3
 
4
4
  describe Rake::Puppet do
5
5
 
6
- module_path = 'modules'
7
- testable_modules = [ 'core', 'base' ]
8
- modules_dir_list = [ 'core', 'base', 'role', 'profiles' ]
9
- rakefile_names = ['Rakefile', 'rakefile', 'Rakefile.rb', 'rakefile.rb']
6
+ testable_module_names = [ 'core', 'base' ]
7
+ testable_modules = [ 'lib/core', 'lib/base' ]
8
+ sample_modules = [ 'lib/core', 'lib/base', 'site/role', 'site/profile' ]
9
+ rakefile_names = [ 'Rakefile', 'rakefile', 'Rakefile.rb', 'rakefile.rb' ]
10
10
 
11
11
  let(:puppet) { Rake::Puppet.new }
12
12
 
@@ -30,7 +30,7 @@ describe Rake::Puppet do
30
30
 
31
31
  it 'creates a task for each module' do
32
32
  puppet.load_module_tasks
33
- testable_modules.each { |mod|
33
+ testable_module_names.each { |mod|
34
34
  expect(Rake::Task.task_defined?("#{mod}:spec")).to eq true
35
35
  }
36
36
  end
@@ -40,6 +40,13 @@ describe Rake::Puppet do
40
40
  expect(Rake::Task.task_defined?(:spec)).to eq true
41
41
  end
42
42
 
43
+ it 'makes module spec tasks prerequisites of main spec task' do
44
+ puppet.load_module_tasks
45
+ task_names = testable_module_names.collect { |mn| "#{mn}:spec" }
46
+ prerequisites = Rake::Task[:spec].prerequisites
47
+ expect(prerequisites).to match_array task_names
48
+ end
49
+
43
50
  end
44
51
 
45
52
  describe 'load_build_tasks' do
@@ -105,9 +112,9 @@ describe Rake::Puppet do
105
112
  Dir.stubs(:entries).returns rakefile_names # bypass Rakefile filter
106
113
 
107
114
  File.stubs(:directory?).returns false
108
- File.stubs(:directory?).with(regexp_matches( /(#{testable_modules.join '|'})\/spec$/ )).returns(true)
115
+ File.stubs(:directory?).with(regexp_matches( /^(#{testable_modules.join '|'})\/spec$/ )).returns(true)
109
116
 
110
- result = puppet.filter_modules modules_dir_list
117
+ result = puppet.filter_modules sample_modules
111
118
  expect(result).to match_array testable_modules
112
119
  end
113
120
 
@@ -115,9 +122,9 @@ describe Rake::Puppet do
115
122
  it 'filters modules with a Rakefile' do
116
123
  File.stubs(:directory?).returns true # bypass spec dir filter
117
124
 
118
- Dir.stubs(:entries).with(regexp_matches( /#{testable_modules.join '|'}/ )).returns([filename])
125
+ Dir.stubs(:entries).with(regexp_matches( /^#{testable_modules.join '|'}/ )).returns([filename])
119
126
 
120
- result = puppet.filter_modules modules_dir_list
127
+ result = puppet.filter_modules sample_modules
121
128
  expect(result).to match_array testable_modules
122
129
  end
123
130
  }
@@ -131,35 +138,46 @@ describe Rake::Puppet do
131
138
  def puppet.filter_modules(_modules)
132
139
  _modules
133
140
  end
141
+
142
+ Dir.stubs(:exist?).returns true
143
+ Dir.stubs(:entries).with('lib').returns(['one', 'two'])
144
+ Dir.stubs(:entries).with('site').returns(['three', 'four'])
145
+ Dir.stubs(:entries).with('extra').returns(['five', 'six'])
134
146
  end
135
147
 
136
- it 'ignores excluded directories' do
137
- Dir.stubs(:entries).with(module_path).returns testable_modules + ['.', '..']
148
+ it 'finds modules in all paths' do
149
+ puppet.module_dirs << 'extra'
150
+ modules = ['lib/one', 'lib/two', 'site/three', 'site/four', 'extra/five', 'extra/six']
151
+ expect(puppet.testable_modules).to match_array modules
152
+ end
138
153
 
139
- result = puppet.testable_modules
140
- expect(result).to match_array testable_modules
154
+ it 'ignores excluded directories' do
155
+ Dir.stubs(:entries).with('lib').returns(['.', '..', 'one', 'two'])
156
+ modules = ['lib/one', 'lib/two', 'site/three', 'site/four']
157
+ expect(puppet.testable_modules).to match_array modules
141
158
  end
142
159
 
143
160
  it 'ignores excluded modules' do
144
- Dir.stubs(:entries).with(module_path).returns testable_modules + ['exclude_me']
161
+ puppet.excluded_modules = ['two', 'four']
162
+ modules = ['lib/one', 'site/three']
163
+ expect(puppet.testable_modules).to match_array modules
164
+ end
145
165
 
146
- puppet.excluded_modules = ['exclude_me']
147
- result = puppet.testable_modules
148
- expect(result).to match_array testable_modules
166
+ it 'raises an error if module_paths is not an array' do
167
+ puppet.module_dirs = 'not an array'
168
+ expect { puppet.testable_modules }.to raise_error(ArgumentError, /must be an array/)
149
169
  end
150
170
 
151
- it 'throws error if excluded modules is not an array' do
171
+ it 'raises an error if excluded modules is not an array' do
152
172
  puppet.excluded_modules = 'not an array'
153
173
  expect { puppet.testable_modules }.to raise_error(ArgumentError, /must be an array/)
154
174
  end
155
175
 
156
- it 'finds modules within module_path' do
157
- alt_module_path = 'modules-alt'
158
-
159
- Dir.expects(:entries).with(alt_module_path).returns modules_dir_list
160
-
161
- puppet.module_path = alt_module_path
162
- puppet.testable_modules
176
+ it 'raises an error if a path directory does not exist' do
177
+ Dir.stubs(:exist?).with('lib').returns false
178
+ expect {
179
+ puppet.testable_modules
180
+ }.to raise_error(ArgumentError, /lib could not be found/)
163
181
  end
164
182
 
165
183
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-puppet-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.2
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Poulton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-17 00:00:00.000000000 Z
11
+ date: 2017-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet