puppet-retrospec 0.3.0 → 0.4.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: 2a2f8b465a1d2884cfff1f96f1d46214c891d27f
4
- data.tar.gz: b3458e26b5ccdab19bd1fa05c841eb7eb7e3952c
3
+ metadata.gz: 4fd53d7dc8e523b7ab53a2b04244836e7b0b972d
4
+ data.tar.gz: 5e4d3517dc4b7b34172ff914b6334b8fd59ff7c9
5
5
  SHA512:
6
- metadata.gz: 9d65c5dfb1eb72b5dae00bf6ef11089f08ea9a2100c9641b82d0dab74d288288ecdda6f5fbba0db50c8fbf734692a44853959dfaf6c00ed432e81bce409bb24c
7
- data.tar.gz: a517170cfcdad5f652805d205f22cae24e06b5db385ea5b2e567af8e23f563a736bd0e3af5c7e9f2b2b647691a5d95fa5db4337bcc369f4202a4c26dc213ddeb
6
+ metadata.gz: d1d577bb42dbcf4b39a8c0e458d5875615f1318dded5348c4d19ba81b2f5c6e957a469ad24eba172aaebf4e53fc48b321ea5e24d423188c68deb763b397610ce
7
+ data.tar.gz: 8feb4bab90ce38a5b9cdf4a60b479901af24f0443c01e4ad814bd26d983fdab725d1baa1153ee42eb4d9e5d7705e1183987b472422bc0417034175e604a94a3c
data/README.md CHANGED
@@ -20,24 +20,14 @@ Install
20
20
 
21
21
  How to use
22
22
  =============
23
- Run from a rake task
24
- ```
25
- require 'puppet-retrospec'
26
-
27
- desc "Scans the module directory and automatically creates basic spec tests"
28
- task :retrospec do
29
- Retrospec.run
30
- end
31
-
32
- ```
33
-
34
23
  Run from the command line
35
24
  ```
36
25
  $ retrospec -h
37
- Options:
38
- --module-path, -m <s>: destination directory to create spec tests in (Defaults to current directory)
26
+ Options:
27
+ --module-path, -m <s>: The path (relative or absolute) to the module directory (Defaults to current directory)
39
28
  --template-dir, -t <s>: Path to templates directory (only for overriding Retrospec templates)
40
- --enable-user-templates, -e: Use Retrospec templates from /Users/cosman/.puppet_retrospec_templates
29
+ --enable-user-templates, -e: Use Retrospec templates from ~/.puppet_retrospec_templates
30
+ --enable-beaker-tests, -n: Enable the creation of beaker tests
41
31
  --help, -h: Show this message
42
32
 
43
33
  retrospec -m ~/projects/puppet_modules/apache
@@ -141,29 +131,42 @@ your puppet module with unit tests.
141
131
  Overriding the templates
142
132
  =======================
143
133
  There may be a time when you want to override the default templates used to generate the rspec related files.
144
- To override these templates just set **one** of the following environment variables.
134
+ To override these templates just set **one** of the following cli options.
145
135
 
146
136
  ```shell
147
- RETROSPEC_ENABLE_LOCAL_TEMPLATES=true
148
- RETROSPEC_TEMPLATES_PATH=~/my_templates
137
+ --template-dir, -t <s>: Path to templates directory (only for overriding Retrospec templates)
138
+ --enable-user-templates, -e: Use Retrospec templates from ~/.puppet_retrospec_templates
149
139
 
150
140
  ```
151
141
 
152
- Once one of the variables is set the retrospec will copy over all the templates from the gem location to the default
142
+ Once one of the options is set, retrospec will copy over all the templates from the gem location to the default
153
143
  or specified override templates path.
154
144
  If you have already created the a erb file in the templates location, then puppet-retrospec will not overwrite the file.
155
- You can set multiple template paths if you use them for different projects so just be sure the set the correctly
156
- template path environment variable when running retrospec.
145
+ You can set multiple template paths if you use them for different projects so just be sure the set the correct
146
+ template option when running retrospec.
157
147
 
158
- Setting the `RETROSPEC_ENABLE_LOCAL_TEMPLATES=true` Environment variable will tell retrospec to use the default user template location.
148
+ Setting the `--enable-user-templates` option will tell retrospec to use the default user template location.
159
149
 
160
150
  The default location for the templates when using this variable is ~/.puppet_retrospec_templates
161
151
 
162
- If you wish to override ~/.puppet_retrospec_templates location you can use the following environment variable
163
- RETROSPEC_TEMPLATES_PATH.
164
- If you set this variable you are not required set RETROSPEC_ENABLE_LOCAL_TEMPLATES.
152
+ If you wish to override ~/.puppet_retrospec_templates location you can use the following option
153
+ `--template-dir`
154
+
155
+ If you set the `--template-dir` option you are not required to set the set `--enable-user-templates` option
156
+
157
+ Example:
158
+ `--template-dir=~/my_templates`
159
+
160
+ Beaker Testing
161
+ =================
162
+ Beaker is Puppetlabs acceptance testing framework that you use to test puppet code on real machines. Beaker is fairly new
163
+ and is subject to frequent changes. Testing patterns have not been established yet so consider beaker support in puppet-retrospec
164
+ to be experimental.
165
+
166
+ If you wish to enable the creation of beaker tests you can use the following cli option. By default these
167
+ acceptance tests are not created. However at a later time they will be enabled by default.
165
168
 
166
- `RETROSPEC_TEMPLATES_PATH=~/my_templates`
169
+ `--enable-beaker-tests`
167
170
 
168
171
  Troubleshooting
169
172
  ===============
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
data/bin/retrospec CHANGED
@@ -3,13 +3,14 @@ require 'trollop'
3
3
  require 'puppet-retrospec'
4
4
 
5
5
  opts = Trollop::options do
6
- opt :module_path, "destination directory to create spec tests in (Defaults to current directory) " ,
6
+ opt :module_path, "The path (relative or absolute) to the module directory (Defaults to current directory) " ,
7
7
  :type => :string, :required => false, :default => nil
8
8
  opt :template_dir, "Path to templates directory (only for overriding Retrospec templates)", :type => :string,
9
9
  :required => false, :default => nil
10
10
  opt :enable_user_templates, "Use Retrospec templates from #{File.expand_path('~/.puppet_retrospec_templates')}",
11
11
  :require => false, :type => :boolean
12
+ opt :enable_beaker_tests, "Enable the creation of beaker tests", :require => false, :type => :boolean
12
13
  end
13
- ENV['RETROSPEC_ENABLE_LOCAL_TEMPLATES'] = 'true' if opts[:enable_user_templates]
14
- ENV['RETROSPEC_TEMPLATES_PATH'] = opts[:template_dir] if not opts[:template_dir].nil?
15
- Retrospec.run(opts[:module_path])
14
+
15
+ retro = Retrospec.new(opts[:module_path], opts)
16
+ retro.create_files
data/lib/helpers.rb CHANGED
@@ -56,10 +56,9 @@ class Helpers
56
56
  # creates and/or copies all templates in the gem to the user templates path
57
57
  # returns: user_template_dir
58
58
  def self.sync_user_template_dir(user_template_directory)
59
- Dir.glob(File.join(gem_template_dir, "*.erb")).each do |src|
60
- filename = File.basename(src)
61
- dest = File.expand_path(File.join(user_template_directory, filename))
62
- safe_copy_file(src, dest)
59
+ Dir.glob(File.join(gem_template_dir, '**', '*')).each do |src|
60
+ dest = src.gsub(gem_template_dir, user_template_directory)
61
+ safe_copy_file(src, dest) unless File.directory?(src)
63
62
  end
64
63
  user_template_directory
65
64
  end
@@ -82,12 +81,13 @@ class Helpers
82
81
  end
83
82
 
84
83
  def self.safe_copy_file(src, dest)
85
- if File.exists?(dest)
84
+ if File.exists?(dest) and not File.zero?(dest)
86
85
  $stderr.puts "!! #{dest} already exists"
87
86
  else
88
87
  if not File.exists?(src)
89
88
  safe_touch(src)
90
89
  else
90
+ safe_mkdir(File.dirname(dest))
91
91
  FileUtils.cp(src,dest)
92
92
  end
93
93
  puts " + #{dest}"
@@ -108,7 +108,8 @@ class Helpers
108
108
  def self.safe_create_file(filename, content)
109
109
  if File.exists? filename
110
110
  old_content = File.read(filename)
111
- if old_content != content
111
+ # if we did a better comparison of content we could be smarter about when we create files
112
+ if old_content != content or not File.zero?(filename)
112
113
  $stderr.puts "!! #{filename} already exists and differs from template"
113
114
  end
114
115
  else
@@ -9,18 +9,31 @@ class Retrospec
9
9
  attr_reader :tmp_module_path
10
10
  attr_accessor :default_modules
11
11
  attr_accessor :facts_used
12
+ attr_accessor :module_name
13
+ attr_reader :template_dir
12
14
 
13
15
  # module path is the relative or absolute path to the module that should retro fitted
14
- def initialize(path=nil, default_template_dir=ENV['RETROSPEC_TEMPLATES_PATH'])
16
+ # opts hash contains additional flags and options that can be user to control the creation of the tests
17
+ # opts[:enable_user_templates]
18
+ # opts[:enable_beaker_tests]
19
+ # opts[:template_dir]
20
+ def initialize(module_path=nil,opts={})
15
21
  # user supplied a template path or user wants to use local templates
16
- if not default_template_dir.nil? or ENV['RETROSPEC_ENABLE_LOCAL_TEMPLATES'] =~ /true/i
17
- default_template_dir = Helpers.setup_user_template_dir(default_template_dir)
22
+ if opts[:template_dir] or opts[:enable_user_templates]
23
+ @template_dir = Helpers.setup_user_template_dir(opts[:template_dir])
24
+ else
25
+ # if user doesn't supply template directory we assume we should use the templates in this gem
26
+ @template_dir = Helpers.gem_template_dir
18
27
  end
19
- @module_path = validate_module_dir(path)
20
- @template_dir = default_template_dir
28
+ @enable_beaker_tests = opts[:enable_beaker_tests]
29
+ @module_path = validate_module_dir(module_path)
21
30
  tmp_module_path
22
31
  end
23
32
 
33
+ def enable_beaker_tests?
34
+ @enable_beaker_tests == true
35
+ end
36
+
24
37
  def default_modules
25
38
  @default_modules ||= ['stdlib']
26
39
  end
@@ -31,13 +44,30 @@ class Retrospec
31
44
  safe_create_gemfile
32
45
  safe_create_rakefile
33
46
  safe_make_shared_context
47
+ safe_create_acceptance_spec_helper if enable_beaker_tests?
48
+ safe_create_node_sets if enable_beaker_tests?
34
49
  types.each do |type|
35
50
  safe_create_resource_spec_files(type)
51
+ if enable_beaker_tests?
52
+ safe_create_acceptance_tests(type)
53
+ end
36
54
  end
37
55
  FileUtils.remove_entry_secure tmp_modules_dir # ensure we remove the temporary directory
38
56
  true
39
57
  end
40
58
 
59
+ def safe_create_node_sets
60
+ # copy all of the nodesets from the templates path nodesets directory
61
+ Dir.glob("#{template_dir}/nodesets/*.yml").each do |node_set_file|
62
+ dest = File.expand_path(File.join(module_path, 'spec', 'acceptance', 'nodesets', File.basename(node_set_file) ))
63
+ Helpers.safe_copy_file(node_set_file,dest)
64
+ end
65
+ end
66
+
67
+ def safe_create_acceptance_spec_helper(template='spec_helper_acceptance.rb.erb')
68
+ safe_create_template_file(File.join('spec', 'spec_helper_acceptance.rb'), template)
69
+ end
70
+
41
71
  def safe_create_rakefile(template='rakefile.erb')
42
72
  safe_create_template_file('Rakefile', template)
43
73
  end
@@ -81,15 +111,25 @@ class Retrospec
81
111
  def tmp_module_path
82
112
  if @tmp_module_path.nil?
83
113
  # create a link where source is the current repo and dest is /tmp/modules/module_name
84
- path = File.join(tmp_modules_dir, module_name)
114
+ path = File.join(tmp_modules_dir, module_dir_name)
85
115
  FileUtils.ln_s(module_path, path)
86
116
  @tmp_module_path = path
87
117
  end
88
118
  @tmp_module_path
89
119
  end
90
120
 
121
+ # the directory name of the module
122
+ # usually this is the same as the module name but it can be namespaced sometimes
123
+ def module_dir_name
124
+ @module_dir_name ||= File.basename(module_path)
125
+ end
126
+
127
+ # returns the name of the module ie. mysql::config => mysql
91
128
  def module_name
92
- @module_name ||= File.basename(module_path)
129
+ if @module_name.nil?
130
+ @module_name = types.first.name.split('::').first if types.length > 0
131
+ end
132
+ @module_name
93
133
  end
94
134
 
95
135
  # creates a tmp module directory so puppet can work correctly
@@ -103,24 +143,6 @@ class Retrospec
103
143
  @modules_dir
104
144
  end
105
145
 
106
- # pass in either the path to the module directory
107
- # or the path to a specific manifest
108
- # defaults to all manifests in the current directory
109
- # if ENV['RETROSPEC_ENABLE_LOCAL_TEMPLATES'] = 'true' the use the default user templates path
110
- # if ENV["RETROSPEC_TEMPLATES_PATH"] is set then we will override the default user template path
111
- # with the path provided
112
- # we will use the necessary templates from that directory instead of the default gem path
113
- def self.run(path=nil, template_dir=ENV['RETROSPEC_TEMPLATES_PATH'])
114
- spec = Retrospec.new(path, template_dir)
115
- spec.create_files
116
- end
117
-
118
- # if user doesn't supply template directory we assume we should use the templates in this gem
119
- def template_dir
120
- @template_dir ||= Helpers.gem_template_dir
121
- end
122
-
123
-
124
146
  def modules_included
125
147
  @modules_included ||= default_modules + referenced_modules
126
148
  end
@@ -129,25 +151,7 @@ class Retrospec
129
151
  []
130
152
  end
131
153
 
132
- # processes a directory and expands to its full path, assumes './'
133
- # returns the validated dir
134
- def validate_module_dir(dir)
135
- # first check to see if manifests directory even exists when path is nil
136
- if dir.nil?
137
- dir = '.'
138
- elsif dir.instance_of?(Array)
139
- raise "Retrospec - an array of moudule paths is not supported at this time"
140
- end
141
- dir = File.expand_path(dir)
142
- manifest_dir = File.join(dir,'manifests')
143
- if ! File.exist?(manifest_dir)
144
- raise "No manifest directory in #{manifest_dir}, cannot validate this is a module"
145
- else
146
- files = Dir.glob("#{manifest_dir}/**/*.pp")
147
- warn 'No puppet manifest files found at #' if files.length < 1
148
- end
149
- dir
150
- end
154
+
151
155
 
152
156
  # finds all the included resources so we can test and depend on in the fixtures file
153
157
  # def included_declarations(file)
@@ -175,23 +179,54 @@ class Retrospec
175
179
  # @included_declarations
176
180
  # end
177
181
 
182
+
183
+
178
184
  # Creates an associated spec file for each type and even creates the subfolders for nested classes one::two::three
179
185
  def safe_create_resource_spec_files(type,template='resource_spec_file.erb')
180
- classes_dir = 'spec/classes'
181
- defines_dir = 'spec/defines'
182
- hosts_dir = 'spec/hosts'
183
186
  @parameters = type.arguments
184
187
  @type = type
188
+ file_path = generate_file_path(type, false)
189
+ safe_create_template_file(file_path, template)
190
+ file_path
191
+ end
192
+
193
+ def safe_create_acceptance_tests(type,template='acceptance_spec_test.erb')
194
+ @parameters = type.arguments
195
+ @type = type
196
+ file_path = generate_file_path(type, true)
197
+ safe_create_template_file(file_path, template)
198
+ file_path
199
+ end
200
+
201
+ # creates a puppet environment given a module path and environment name
202
+ def puppet_environment
203
+ @puppet_environment ||= Puppet::Node::Environment.create('production', [tmp_modules_dir])
204
+ end
205
+
206
+ # generates a file path for spec tests based on the resource name. An added option
207
+ # is to generate directory names for each parent resource as a default option
208
+ # at this time acceptance tests follow this same test directory layout until best
209
+ # practices are formed.
210
+ def generate_file_path(type, is_acceptance_test)
211
+ classes_dir = 'classes'
212
+ defines_dir = 'defines'
213
+ hosts_dir = 'hosts'
214
+ acceptance_dir = 'acceptance'
185
215
  case type.type
186
216
  when :hostclass
187
217
  type_dir_name = classes_dir
188
218
  when :definition
189
219
  type_dir_name = defines_dir
190
220
  else
191
- raise "#{type.type} is not a supported resource type yet"
221
+ raise "#{type.type} retrospec does not support this resource type yet"
192
222
  end
223
+ if is_acceptance_test
224
+ type_dir_name = File.join('spec',acceptance_dir, type_dir_name)
225
+ else
226
+ type_dir_name = File.join('spec', type_dir_name)
227
+ end
228
+ file_name = generate_file_name(type.name)
193
229
  tokens = type.name.split('::')
194
- file_name = tokens.pop # the last item should be the filename
195
230
  # if there are only two tokens ie. tomcat::params we dont need to create a subdirectory
196
231
  if tokens.count > 1
197
232
  # this is a deep level resource ie. tomcat::config::server::connector
@@ -200,13 +235,23 @@ class Retrospec
200
235
  tokens.delete_at(0)
201
236
  # so lets make a directory structure out of it
202
237
  dir_name = File.join(tokens) # config/server
203
- dir_name = File.join(type_dir_name,dir_name) # spec/classes/tomcat/config/server
204
- safe_create_template_file(File.join(dir_name,"#{file_name}_spec.rb"), template)
238
+ dir_name = File.join(type_dir_name,dir_name, file_name) # spec/classes/tomcat/config/server
205
239
  else
206
- safe_create_template_file(File.join(type_dir_name,"#{file_name}_spec.rb"), template)
240
+ dir_name = File.join(type_dir_name,file_name)
207
241
  end
242
+ dir_name
208
243
  end
209
244
 
245
+ # returns the filename of the type
246
+ def generate_file_name(type_name)
247
+ tokens = type_name.split('::')
248
+ file_name = tokens.pop
249
+ "#{file_name}_spec.rb"
250
+ end
251
+
252
+ private
253
+
254
+ # creates a puppet resource request to be used indirectly
210
255
  def request(key, method)
211
256
  instance = Puppet::Indirector::Indirection.instance(:resource_type)
212
257
  indirection_name = 'test'
@@ -215,15 +260,11 @@ class Retrospec
215
260
  @request
216
261
  end
217
262
 
263
+ # creates an instance of the resource type parser
218
264
  def resource_type_parser
219
265
  @resource_type_parser ||= Puppet::Indirector::ResourceType::Parser.new
220
266
  end
221
267
 
222
- # creates a puppet environment given a module path and environment name
223
- def puppet_environment
224
- @puppet_environment ||= Puppet::Node::Environment.create('production', [tmp_modules_dir])
225
- end
226
-
227
268
  # returns the resource type ofject given a resource name ie. tomcat::connector
228
269
  def find_resource(resource_name)
229
270
  request = request(resource_name, 'find')
@@ -236,4 +277,23 @@ class Retrospec
236
277
  resource_type_parser.search(request)
237
278
  end
238
279
 
280
+ # processes a directory and expands to its full path, assumes './'
281
+ # returns the validated dir
282
+ def validate_module_dir(dir)
283
+ # first check to see if manifests directory even exists when path is nil
284
+ if dir.nil?
285
+ dir = '.'
286
+ elsif dir.instance_of?(Array)
287
+ raise "Retrospec - an array of moudule paths is not supported at this time"
288
+ end
289
+ dir = File.expand_path(dir)
290
+ manifest_dir = File.join(dir,'manifests')
291
+ if ! File.exist?(manifest_dir)
292
+ raise "No manifest directory in #{manifest_dir}, cannot validate this is a module"
293
+ else
294
+ files = Dir.glob("#{manifest_dir}/**/*.pp")
295
+ warn 'No puppet manifest files found at #' if files.length < 1
296
+ end
297
+ dir
298
+ end
239
299
  end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper_acceptance'
2
+
3
+ describe '<%= @type.name -%> <%= @type.type %>' do
4
+ describe 'running puppet code' do
5
+ it 'should work with no errors' do
6
+ pp = <<-EOS
7
+ class { '<%= @type.name %>':
8
+ <%- @parameters.each do |k,v| -%>
9
+ <%- if v.nil? -%>
10
+ <%= "#{k} => 'place_value_here'," %>
11
+ <%- else -%>
12
+ <%= "##{k} => #{v}," %>
13
+ <%- end -%>
14
+ <%- end -%>
15
+ }
16
+ EOS
17
+
18
+ # Run it twice and test for idempotency
19
+ apply_manifest(pp, :catch_failures => true)
20
+ expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
21
+ end
22
+
23
+ end
24
+ end
@@ -1,8 +1,27 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- group :development, :test do
4
- gem 'bodeco_module_helper', :git => 'https://github.com/bodeco/bodeco_module_helper.git'
5
- gem 'rspec-puppet-utils', :git => 'https://github.com/Accuity/rspec-puppet-utils.git'
6
- gem 'hiera-puppet-helper', :git => 'https://github.com/bobtfish/hiera-puppet-helper.git'
3
+ group :test do
4
+ gem "rake"
5
+ gem "puppet", ENV['PUPPET_VERSION'] || '~> 3.7.0'
6
+ gem "rspec-puppet", :git => 'https://github.com/rodjek/rspec-puppet.git'
7
+ gem "puppetlabs_spec_helper"
8
+ gem 'rspec-puppet-utils', :git => 'https://github.com/Accuity/rspec-puppet-utils.git'
9
+ gem 'hiera-puppet-helper', :git => 'https://github.com/bobtfish/hiera-puppet-helper.git'
10
+
11
+ end
12
+
13
+ group :development do
14
+ gem "travis"
15
+ gem "travis-lint"
16
+ <%- if enable_beaker_tests? -%>
17
+ gem "beaker", :git => 'https://github.com/logicminds/beaker.git', :branch => 'sshd_restart'
18
+ gem "beaker-rspec", :git => 'https://github.com/puppetlabs/beaker-rspec.git'
19
+ gem "vagrant-wrapper"
20
+ <%- end -%>
21
+ gem "puppet-blacksmith"
22
+ gem "guard-rake"
23
+ gem "metadata-json-lint"
24
+ gem 'puppet-syntax'
25
+ gem 'serverspec'
7
26
  end
8
27
 
@@ -0,0 +1,10 @@
1
+ HOSTS:
2
+ centos-59-x64:
3
+ roles:
4
+ - master
5
+ platform: el-5-x86_64
6
+ box : centos-59-x64-vbox4210-nocm
7
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-59-x64-vbox4210-nocm.box
8
+ hypervisor : vagrant
9
+ CONFIG:
10
+ type: git
@@ -0,0 +1,12 @@
1
+ HOSTS:
2
+ centos-64-x64:
3
+ roles:
4
+ - master
5
+ - database
6
+ - dashboard
7
+ platform: el-6-x86_64
8
+ box : centos-64-x64-vbox4210-nocm
9
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
10
+ hypervisor : vagrant
11
+ CONFIG:
12
+ type: pe
@@ -0,0 +1,11 @@
1
+ HOSTS:
2
+ centos-64-x64:
3
+ roles:
4
+ - master
5
+ platform: el-6-x86_64
6
+ box : centos-64-x64-vbox4210-nocm
7
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
8
+ hypervisor : vagrant
9
+ CONFIG:
10
+ log_level: debug
11
+ type: git
@@ -0,0 +1,10 @@
1
+ HOSTS:
2
+ centos-65-x64:
3
+ roles:
4
+ - master
5
+ platform: el-6-x86_64
6
+ box : centos-65-x64-vbox436-nocm
7
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box
8
+ hypervisor : vagrant
9
+ CONFIG:
10
+ type: foss
@@ -0,0 +1,11 @@
1
+ HOSTS:
2
+ debian-607-x64:
3
+ roles:
4
+ - master
5
+ platform: debian-6-amd64
6
+ box : debian-607-x64-vbox4210-nocm
7
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-607-x64-vbox4210-nocm.box
8
+ hypervisor : vagrant
9
+ CONFIG:
10
+ log_level: debug
11
+ type: git
@@ -0,0 +1,11 @@
1
+ HOSTS:
2
+ debian-70rc1-x64:
3
+ roles:
4
+ - master
5
+ platform: debian-7-amd64
6
+ box : debian-70rc1-x64-vbox4210-nocm
7
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-70rc1-x64-vbox4210-nocm.box
8
+ hypervisor : vagrant
9
+ CONFIG:
10
+ log_level: debug
11
+ type: git
@@ -0,0 +1,11 @@
1
+ HOSTS:
2
+ debian-73-i386:
3
+ roles:
4
+ - master
5
+ platform: debian-7-i386
6
+ box : debian-73-i386-virtualbox-nocm
7
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-73-i386-virtualbox-nocm.box
8
+ hypervisor : vagrant
9
+ CONFIG:
10
+ log_level: debug
11
+ type: git
@@ -0,0 +1,11 @@
1
+ HOSTS:
2
+ debian-73-x64:
3
+ roles:
4
+ - master
5
+ platform: debian-7-amd64
6
+ box : debian-73-x64-virtualbox-nocm
7
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-73-x64-virtualbox-nocm.box
8
+ hypervisor : vagrant
9
+ CONFIG:
10
+ log_level: debug
11
+ type: git
@@ -0,0 +1,11 @@
1
+ HOSTS:
2
+ centos-64-x64:
3
+ roles:
4
+ - master
5
+ platform: el-6-x86_64
6
+ box : centos-64-x64-vbox4210-nocm
7
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
8
+ hypervisor : vagrant
9
+ CONFIG:
10
+ log_level: debug
11
+ type: git
@@ -0,0 +1,11 @@
1
+ HOSTS:
2
+ fedora-18-x64:
3
+ roles:
4
+ - master
5
+ platform: fedora-18-x86_64
6
+ box : fedora-18-x64-vbox4210-nocm
7
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/fedora-18-x64-vbox4210-nocm.box
8
+ hypervisor : vagrant
9
+ CONFIG:
10
+ log_level: debug
11
+ type: git
@@ -0,0 +1,11 @@
1
+ HOSTS:
2
+ sles-11sp1-x64:
3
+ roles:
4
+ - master
5
+ platform: sles-11-x86_64
6
+ box : sles-11sp1-x64-vbox4210-nocm
7
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/sles-11sp1-x64-vbox4210-nocm.box
8
+ hypervisor : vagrant
9
+ CONFIG:
10
+ log_level: debug
11
+ type: git
@@ -0,0 +1,10 @@
1
+ HOSTS:
2
+ ubuntu-server-10044-x64:
3
+ roles:
4
+ - master
5
+ platform: ubuntu-10.04-amd64
6
+ box : ubuntu-server-10044-x64-vbox4210-nocm
7
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-10044-x64-vbox4210-nocm.box
8
+ hypervisor : vagrant
9
+ CONFIG:
10
+ type: foss
@@ -0,0 +1,10 @@
1
+ HOSTS:
2
+ ubuntu-server-12042-x64:
3
+ roles:
4
+ - master
5
+ platform: ubuntu-12.04-amd64
6
+ box : ubuntu-server-12042-x64-vbox4210-nocm
7
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box
8
+ hypervisor : vagrant
9
+ CONFIG:
10
+ type: foss
@@ -0,0 +1,11 @@
1
+ HOSTS:
2
+ ubuntu-server-1310-x64:
3
+ roles:
4
+ - master
5
+ platform: ubuntu-13.10-amd64
6
+ box : ubuntu-server-1310-x64-vbox4210-nocm
7
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-1310-x64-virtualbox-nocm.box
8
+ hypervisor : vagrant
9
+ CONFIG:
10
+ log_level : debug
11
+ type: git
@@ -0,0 +1,11 @@
1
+ HOSTS:
2
+ ubuntu-server-1404-x64:
3
+ roles:
4
+ - master
5
+ platform: ubuntu-14.04-amd64
6
+ box : puppetlabs/ubuntu-14.04-64-nocm
7
+ box_url : https://vagrantcloud.com/puppetlabs/ubuntu-14.04-64-nocm
8
+ hypervisor : vagrant
9
+ CONFIG:
10
+ log_level : debug
11
+ type: git
@@ -1 +1,41 @@
1
- require 'bodeco_module_helper/rake_tasks'
1
+ require 'puppetlabs_spec_helper/rake_tasks'
2
+ require 'puppet-lint/tasks/puppet-lint'
3
+ require 'puppet-syntax/tasks/puppet-syntax'
4
+
5
+ # These two gems aren't always present, for instance
6
+ # on Travis with --without development
7
+ begin
8
+ require 'puppet_blacksmith/rake_tasks'
9
+ rescue LoadError
10
+ end
11
+
12
+ PuppetLint.configuration.relative = true
13
+ PuppetLint.configuration.send("disable_80chars")
14
+ PuppetLint.configuration.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}"
15
+ PuppetLint.configuration.fail_on_warnings = true
16
+
17
+ # Forsake support for Puppet 2.6.2 for the benefit of cleaner code.
18
+ # http://puppet-lint.com/checks/class_parameter_defaults/
19
+ PuppetLint.configuration.send('disable_class_parameter_defaults')
20
+ # http://puppet-lint.com/checks/class_inherits_from_params_class/
21
+ PuppetLint.configuration.send('disable_class_inherits_from_params_class')
22
+
23
+ exclude_paths = [
24
+ "pkg/**/*",
25
+ "vendor/**/*",
26
+ "spec/**/*",
27
+ ]
28
+ PuppetLint.configuration.ignore_paths = exclude_paths
29
+ PuppetSyntax.exclude_paths = exclude_paths
30
+
31
+ task :metadata do
32
+ sh "metadata-json-lint metadata.json"
33
+ end
34
+
35
+ desc "Run syntax, lint, and spec tests."
36
+ task :test => [
37
+ :syntax,
38
+ :lint,
39
+ :spec,
40
+ :metadata,
41
+ ]
@@ -0,0 +1,33 @@
1
+ require 'beaker-rspec'
2
+
3
+ UNSUPPORTED_PLATFORMS = [ 'Windows', 'Solaris', 'AIX' ]
4
+
5
+ unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no'
6
+ # This will install the latest available package on el and deb based
7
+ # systems fail on windows and osx, and install via gem on other *nixes
8
+ foss_opts = { :default_action => 'gem_install' }
9
+
10
+ if default.is_pe?; then install_pe; else install_puppet( foss_opts ); end
11
+
12
+ hosts.each do |host|
13
+ on hosts, "mkdir -p #{host['distmoduledir']}"
14
+ end
15
+ end
16
+
17
+ RSpec.configure do |c|
18
+ # Project root
19
+ proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
20
+
21
+ # Readable test descriptions
22
+ c.formatter = :documentation
23
+
24
+ # Configure all nodes in nodeset
25
+ c.before :suite do
26
+ hosts.each do |host|
27
+ # Install this module
28
+ copy_module_to(host, :source => proj_root, :module_name => '<%= @module_name %>')
29
+ # List other dependencies here so they are installed on the host
30
+ on host, puppet('module','install','puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] }
31
+ end
32
+ end
33
+ end
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: puppet-retrospec 0.3.0 ruby lib
5
+ # stub: puppet-retrospec 0.4.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "puppet-retrospec"
9
- s.version = "0.3.0"
9
+ s.version = "0.4.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Corey Osman"]
14
- s.date = "2014-11-14"
14
+ s.date = "2014-11-21"
15
15
  s.description = "Retrofits and generates valid puppet rspec test code to existing modules"
16
16
  s.email = "corey@logicminds.biz"
17
17
  s.executables = ["retrospec"]
@@ -31,11 +31,28 @@ Gem::Specification.new do |s|
31
31
  "bin/retrospec",
32
32
  "lib/helpers.rb",
33
33
  "lib/puppet-retrospec.rb",
34
+ "lib/templates/acceptance_spec_test.erb",
34
35
  "lib/templates/fixtures_file.erb",
35
36
  "lib/templates/gemfile.erb",
37
+ "lib/templates/nodesets/centos-59-x64.yml",
38
+ "lib/templates/nodesets/centos-64-x64-pe.yml",
39
+ "lib/templates/nodesets/centos-64-x64.yml",
40
+ "lib/templates/nodesets/centos-65-x64.yml",
41
+ "lib/templates/nodesets/debian-607-x64.yml",
42
+ "lib/templates/nodesets/debian-70rc1-x64.yml",
43
+ "lib/templates/nodesets/debian-73-i386.yml",
44
+ "lib/templates/nodesets/debian-73-x64.yml",
45
+ "lib/templates/nodesets/default.yml",
46
+ "lib/templates/nodesets/fedora-18-x64.yml",
47
+ "lib/templates/nodesets/sles-11sp1-x64.yml",
48
+ "lib/templates/nodesets/ubuntu-server-10044-x64.yml",
49
+ "lib/templates/nodesets/ubuntu-server-12042-x64.yml",
50
+ "lib/templates/nodesets/ubuntu-server-1310-x64.yml",
51
+ "lib/templates/nodesets/ubuntu-server-1404-x64.yml",
36
52
  "lib/templates/rakefile.erb",
37
53
  "lib/templates/resource_spec_file.erb",
38
54
  "lib/templates/shared_context.erb",
55
+ "lib/templates/spec_helper_acceptance.rb.erb",
39
56
  "lib/templates/spec_helper_file.erb",
40
57
  "puppet-retrospec.gemspec",
41
58
  "spec/fixtures/fixture_modules/zero_resource_module/manifests/not_a_resource_defination.pp",
@@ -46,7 +63,7 @@ Gem::Specification.new do |s|
46
63
  ]
47
64
  s.homepage = "http://github.com/logicminds/puppet-retrospec"
48
65
  s.licenses = ["MIT"]
49
- s.rubygems_version = "2.2.2"
66
+ s.rubygems_version = "2.4.4"
50
67
  s.summary = "Generates puppet rspec test code based on the classes and defines inside the manifests directory. Aims to reduce some of the boilerplate coding with default test patterns."
51
68
 
52
69
  if s.respond_to? :specification_version then
@@ -18,22 +18,46 @@ describe "puppet-retrospec" do
18
18
  end
19
19
 
20
20
  before :each do
21
- ENV['RETROSPEC_ENABLE_LOCAL_TEMPLATES'] = nil
22
- ENV['RETROSPEC_TEMPLATES_PATH'] = nil
23
21
  clean_up_spec_dir(@path)
24
-
22
+ @opts = {:module_path => @path, :enable_beaker_tests => false,
23
+ :enable_user_templates => false, :template_dir => nil }
25
24
  end
26
25
 
27
26
  it 'should run without errors using new' do
28
- tomcat = Retrospec.new(@path)
27
+ tomcat = Retrospec.new(@opts[:module_path], @opts)
29
28
  expect(tomcat.create_files).to eq(true)
30
29
  expect(File.exists?(File.join(@path, 'Gemfile'))).to eq(true)
31
30
  expect(File.exists?(File.join(@path, '.fixtures.yml'))).to eq(true)
32
31
  expect(File.exists?(File.join(@path, 'spec','classes','tomcat_spec.rb'))).to eq(true)
33
32
  end
34
33
 
34
+ it 'should create acceptance test files' do
35
+ @opts[:enable_beaker_tests] = true
36
+ tomcat = Retrospec.new(@opts[:module_path], @opts)
37
+ spec_path = File.expand_path(File.join(@path, 'spec'))
38
+ tomcat.create_files
39
+ expect(File.exists?(File.join(spec_path, 'spec_helper_acceptance.rb'))).to eq(true)
40
+ expect(File.exists?(File.join(spec_path, 'acceptance'))).to eq(true)
41
+ expect(File.exists?(File.join(spec_path, 'acceptance', 'classes', 'tomcat_spec.rb'))).to eq(true)
42
+ expect(File.exists?(File.join(spec_path, 'acceptance', 'nodesets'))).to eq(true)
43
+ expect(File.exists?(File.join(spec_path, 'acceptance', 'nodesets', 'default.yml'))).to eq(true)
44
+
45
+ end
46
+
47
+ it 'should not create acceptance test files' do
48
+ @opts[:enable_beaker_tests] = false
49
+ tomcat = Retrospec.new(@opts[:module_path], @opts)
50
+ spec_path = File.expand_path(File.join(@path, 'spec'))
51
+ tomcat.create_files
52
+ expect(File.exists?(File.join(spec_path, 'spec_helper_acceptance.rb'))).to eq(false)
53
+ expect(File.exists?(File.join(spec_path, 'acceptance'))).to eq(false)
54
+ expect(File.exists?(File.join(spec_path, 'acceptance', 'classes', 'tomcat_spec.rb'))).to eq(false)
55
+ expect(File.exists?(File.join(spec_path, 'acceptance', 'nodesets'))).to eq(false)
56
+ expect(File.exists?(File.join(spec_path, 'acceptance', 'nodesets', 'default.yml'))).to eq(false)
57
+ end
58
+
35
59
  it 'should create a local templates directory when flag is on' do
36
- ENV['RETROSPEC_ENABLE_LOCAL_TEMPLATES'] = 'true'
60
+ @opts[:enable_user_templates] = true
37
61
  FakeFS do
38
62
  user_directory = Helpers.default_user_template_dir
39
63
  FileUtils.mkdir_p(Helpers.gem_template_dir)
@@ -42,23 +66,25 @@ describe "puppet-retrospec" do
42
66
  FileUtils.touch(File.join(Helpers.gem_template_dir, 'shared_context.erb'))
43
67
  FileUtils.touch(File.join(Helpers.gem_template_dir, 'spec_helper_file.erb'))
44
68
  FileUtils.touch(File.join(Helpers.gem_template_dir, 'gemfile.erb'))
45
-
69
+ FileUtils.mkdir_p(File.join(Helpers.gem_template_dir, 'nodesets'))
70
+ FileUtils.touch(File.join(Helpers.gem_template_dir, 'nodesets', 'default.yml'))
46
71
  FileUtils.mkdir_p('/modules/tomcat/manifests')
47
72
  FileUtils.touch('/modules/tomcat/manifests/init.pp')
48
- Retrospec.new('/modules/tomcat')
73
+ @opts[:module_path] = '/modules/tomcat'
74
+ Retrospec.new(@opts[:module_path], @opts)
49
75
  expect(File.exists?(user_directory)).to eq(true)
50
76
  expect(File.exists?(File.join(user_directory, 'gemfile.erb'))).to eq(true)
51
77
  expect(File.exists?(File.join(user_directory, 'fixtures_file.erb'))).to eq(true)
52
78
  expect(File.exists?(File.join(user_directory, 'resource_spec_file.erb'))).to eq(true)
53
79
  expect(File.exists?(File.join(user_directory, 'shared_context.erb'))).to eq(true)
54
80
  expect(File.exists?(File.join(user_directory, 'spec_helper_file.erb'))).to eq(true)
81
+ expect(File.exists?(File.join(user_directory, 'nodesets'))).to eq(true)
82
+ expect(File.exists?(File.join(user_directory, 'nodesets', 'default.yml'))).to eq(true)
55
83
  end
56
- ENV['RETROSPEC_ENABLE_LOCAL_TEMPLATES'] = nil
57
- ENV['RETROSPEC_TEMPLATES_PATH'] = nil
58
84
  end
59
85
 
60
86
  it 'should create the user supplied templates directory when variable is set' do
61
- ENV['RETROSPEC_TEMPLATES_PATH'] = '/tmp/my_templates'
87
+ @opts[:template_dir] = '/tmp/my_templates'
62
88
  FakeFS do
63
89
  FileUtils.mkdir_p(Helpers.gem_template_dir)
64
90
  FileUtils.touch(File.join(Helpers.gem_template_dir, 'fixtures_file.erb'))
@@ -66,9 +92,12 @@ describe "puppet-retrospec" do
66
92
  FileUtils.touch(File.join(Helpers.gem_template_dir, 'shared_context.erb'))
67
93
  FileUtils.touch(File.join(Helpers.gem_template_dir, 'spec_helper_file.erb'))
68
94
  FileUtils.touch(File.join(Helpers.gem_template_dir, 'gemfile.erb'))
95
+ FileUtils.mkdir_p(File.join(Helpers.gem_template_dir, 'nodesets'))
96
+ FileUtils.touch(File.join(Helpers.gem_template_dir, 'nodesets', 'default.yml'))
69
97
  FileUtils.mkdir_p('/modules/tomcat/manifests')
70
98
  FileUtils.touch('/modules/tomcat/manifests/init.pp')
71
- r = Retrospec.new('/modules/tomcat')
99
+ @opts[:module_path] = '/modules/tomcat'
100
+ r = Retrospec.new(@opts[:module_path], @opts)
72
101
  user_directory = r.template_dir
73
102
  expect(user_directory).to eq('/tmp/my_templates')
74
103
  expect(File.exists?(user_directory)).to eq(true)
@@ -77,14 +106,14 @@ describe "puppet-retrospec" do
77
106
  expect(File.exists?(File.join(user_directory, 'resource_spec_file.erb'))).to eq(true)
78
107
  expect(File.exists?(File.join(user_directory, 'shared_context.erb'))).to eq(true)
79
108
  expect(File.exists?(File.join(user_directory, 'spec_helper_file.erb'))).to eq(true)
109
+ expect(File.exists?(File.join(user_directory, 'nodesets'))).to eq(true)
110
+ expect(File.exists?(File.join(user_directory, 'nodesets', 'default.yml'))).to eq(true)
80
111
  end
81
- ENV['RETROSPEC_ENABLE_LOCAL_TEMPLATES'] = nil
82
- ENV['RETROSPEC_TEMPLATES_PATH'] = nil
83
112
 
84
113
  end
85
114
 
86
115
  it 'should create proper spec helper file' do
87
- tomcat = Retrospec.new(@path)
116
+ tomcat = Retrospec.new(@opts[:module_path], @opts)
88
117
  filepath = File.expand_path(File.join(@path, 'spec', 'spec_helper.rb'))
89
118
  path = tomcat.tmp_module_path
90
119
  tomcat.safe_create_spec_helper
@@ -92,22 +121,37 @@ describe "puppet-retrospec" do
92
121
  end
93
122
 
94
123
  it 'should create proper shared context file' do
95
- tomcat = Retrospec.new(@path)
124
+ tomcat = Retrospec.new(@opts[:module_path], @opts)
96
125
  filepath = File.expand_path(File.join(@path, 'spec', 'shared_contexts.rb'))
97
126
  path = tomcat.tmp_module_path
98
127
  tomcat.safe_make_shared_context
99
128
  expect(File.exists?(filepath)).to eq(true)
100
129
  end
101
130
 
131
+ it 'should create acceptance spec helper file' do
132
+ tomcat = Retrospec.new(@opts[:module_path], @opts)
133
+ filepath = File.expand_path(File.join(@path, 'spec', 'spec_helper_acceptance.rb'))
134
+ tomcat.safe_create_acceptance_spec_helper
135
+ expect(File.exists?(filepath)).to eq(true)
136
+ end
137
+
138
+ it 'should create 15 nodesets' do
139
+ tomcat = Retrospec.new(@opts[:module_path], @opts)
140
+ filepath = File.expand_path(File.join(@path, 'spec', 'acceptance', 'nodesets', 'default.yml'))
141
+ tomcat.safe_create_node_sets
142
+ expect(File.exists?(filepath)).to eq(true)
143
+ expect(Dir.glob(File.expand_path(File.join(@path, 'spec', 'acceptance', 'nodesets', '*.yml'))).length).to eq(15)
144
+ end
145
+
102
146
  it 'should create Gemfile file' do
103
- tomcat = Retrospec.new(@path)
147
+ tomcat = Retrospec.new(@opts[:module_path], @opts)
104
148
  filepath = File.expand_path(File.join(@path, 'Gemfile'))
105
149
  tomcat.safe_create_gemfile
106
150
  expect(File.exists?(filepath)).to eq(true)
107
151
  end
108
152
 
109
153
  it 'should create Rakefile file' do
110
- tomcat = Retrospec.new(@path)
154
+ tomcat = Retrospec.new(@opts[:module_path], @opts)
111
155
  filepath = File.expand_path(File.join(@path, 'Rakefile'))
112
156
  tomcat.safe_create_rakefile
113
157
  expect(File.exists?(filepath)).to eq(true)
@@ -116,7 +160,7 @@ describe "puppet-retrospec" do
116
160
  it 'should create proper fixtures file' do
117
161
  filepath = File.expand_path(File.join(@path,'.fixtures.yml'))
118
162
  FileUtils.rm_f(filepath) # ensure we have a clean state
119
- tomcat = Retrospec.new(@path)
163
+ tomcat = Retrospec.new(@opts[:module_path], @opts)
120
164
  tomcat.safe_create_fixtures_file
121
165
  expect(File.exists?(filepath)).to eq(true)
122
166
  end
@@ -128,13 +172,13 @@ describe "puppet-retrospec" do
128
172
  end
129
173
 
130
174
  it 'should create a temp modules dir' do
131
- tomcat = Retrospec.new(@path)
175
+ tomcat = Retrospec.new(@opts[:module_path], @opts)
132
176
  path = tomcat.tmp_modules_dir
133
177
  path.should =~ /modules/
134
178
  end
135
179
 
136
180
  it 'should create a link in the temp modules directory' do
137
- tomcat = Retrospec.new(@path)
181
+ tomcat = Retrospec.new(@opts[:module_path], @opts)
138
182
  path = tomcat.tmp_modules_dir
139
183
  tomcat.tmp_module_path
140
184
  File.exists?(tomcat.tmp_module_path).should eq(true)
@@ -142,14 +186,59 @@ describe "puppet-retrospec" do
142
186
  end
143
187
 
144
188
  it 'should create a file from a template' do
145
- tomcat = Retrospec.new(@path)
189
+ tomcat = Retrospec.new(@opts[:module_path], @opts)
146
190
  tomcat.safe_create_template_file('.fixtures.yml', 'fixtures_file.erb')
147
191
  file_path = File.join(@path,'.fixtures.yml')
148
192
  expect(File.exists?(file_path)).to eq(true)
149
193
  end
150
194
 
195
+ describe 'generate_file_path' do
196
+
197
+ describe 'classes' do
198
+ it 'should generate a acceptance test path correctly' do
199
+ type = double("type")
200
+ allow(type).to receive(:type).and_return(:hostclass)
201
+ allow(type).to receive(:name).and_return('tomcat::config::server::connector')
202
+ tomcat = Retrospec.new(@opts[:module_path], @opts)
203
+ expect(tomcat.generate_file_path(type, true)).to eq("spec/acceptance/classes/config/server/connector/connector_spec.rb")
204
+ end
205
+ it 'should generate a normal test path correctly' do
206
+ type = double("type")
207
+ allow(type).to receive(:type).and_return(:hostclass)
208
+ allow(type).to receive(:name).and_return('tomcat::config::server::connector')
209
+ tomcat = Retrospec.new(@opts[:module_path], @opts)
210
+ expect(tomcat.generate_file_path(type, false)).to eq("spec/classes/config/server/connector/connector_spec.rb")
211
+ end
212
+ end
213
+
214
+ describe 'defines' do
215
+ it 'should generate a acceptance test path correctly' do
216
+ type = double("type")
217
+ allow(type).to receive(:type).and_return(:definition)
218
+ allow(type).to receive(:name).and_return('tomcat::config::server::connector')
219
+ tomcat = Retrospec.new(@opts[:module_path], @opts)
220
+ expect(tomcat.generate_file_path(type, true)).to eq("spec/acceptance/defines/config/server/connector/connector_spec.rb")
221
+ end
222
+
223
+ it 'should generate a normal test path correctly' do
224
+ type = double("type")
225
+ allow(type).to receive(:type).and_return(:definition)
226
+ allow(type).to receive(:name).and_return('tomcat::config::server::connector')
227
+ tomcat = Retrospec.new(@opts[:module_path], @opts)
228
+ expect(tomcat.generate_file_path(type, false)).to eq("spec/defines/config/server/connector/connector_spec.rb")
229
+ end
230
+ end
231
+ end
232
+
233
+ it 'should generate a test file name correctly' do
234
+ tomcat = Retrospec.new(@opts[:module_path], @opts)
235
+ expect(tomcat.generate_file_name('tomcat::config::server::connector')).to eq('connector_spec.rb')
236
+ expect(tomcat.generate_file_name('tomcat')).to eq('tomcat_spec.rb')
237
+ expect(tomcat.generate_file_name('tomcat::config')).to eq('config_spec.rb')
238
+ end
239
+
151
240
  # it 'should contain a list of parameters in the test' do
152
- # tomcat = Retrospec.new(@path)
241
+ # tomcat = Retrospec.new(@opts[:module_path], @opts)
153
242
  # tomcat.create_files
154
243
  #
155
244
  # end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-retrospec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Osman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-14 00:00:00.000000000 Z
11
+ date: 2014-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet
@@ -156,11 +156,28 @@ files:
156
156
  - bin/retrospec
157
157
  - lib/helpers.rb
158
158
  - lib/puppet-retrospec.rb
159
+ - lib/templates/acceptance_spec_test.erb
159
160
  - lib/templates/fixtures_file.erb
160
161
  - lib/templates/gemfile.erb
162
+ - lib/templates/nodesets/centos-59-x64.yml
163
+ - lib/templates/nodesets/centos-64-x64-pe.yml
164
+ - lib/templates/nodesets/centos-64-x64.yml
165
+ - lib/templates/nodesets/centos-65-x64.yml
166
+ - lib/templates/nodesets/debian-607-x64.yml
167
+ - lib/templates/nodesets/debian-70rc1-x64.yml
168
+ - lib/templates/nodesets/debian-73-i386.yml
169
+ - lib/templates/nodesets/debian-73-x64.yml
170
+ - lib/templates/nodesets/default.yml
171
+ - lib/templates/nodesets/fedora-18-x64.yml
172
+ - lib/templates/nodesets/sles-11sp1-x64.yml
173
+ - lib/templates/nodesets/ubuntu-server-10044-x64.yml
174
+ - lib/templates/nodesets/ubuntu-server-12042-x64.yml
175
+ - lib/templates/nodesets/ubuntu-server-1310-x64.yml
176
+ - lib/templates/nodesets/ubuntu-server-1404-x64.yml
161
177
  - lib/templates/rakefile.erb
162
178
  - lib/templates/resource_spec_file.erb
163
179
  - lib/templates/shared_context.erb
180
+ - lib/templates/spec_helper_acceptance.rb.erb
164
181
  - lib/templates/spec_helper_file.erb
165
182
  - puppet-retrospec.gemspec
166
183
  - spec/fixtures/fixture_modules/zero_resource_module/manifests/not_a_resource_defination.pp
@@ -188,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
205
  version: '0'
189
206
  requirements: []
190
207
  rubyforge_project:
191
- rubygems_version: 2.2.2
208
+ rubygems_version: 2.4.4
192
209
  signing_key:
193
210
  specification_version: 4
194
211
  summary: Generates puppet rspec test code based on the classes and defines inside