puppet-retrospec 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +17 -0
  3. data/CHANGELOG.md +11 -0
  4. data/DEVELOPMENT.md +3 -0
  5. data/Gemfile +10 -9
  6. data/Gemfile.lock +2 -0
  7. data/README.md +211 -273
  8. data/Rakefile +8 -8
  9. data/VERSION +1 -1
  10. data/lib/retrospec-puppet.rb +3 -3
  11. data/lib/retrospec/plugins/v1/plugin/conditional.rb +5 -6
  12. data/lib/retrospec/plugins/v1/plugin/exceptions.rb +17 -0
  13. data/lib/retrospec/plugins/v1/plugin/generators.rb +7 -0
  14. data/lib/retrospec/plugins/v1/plugin/generators/fact_generator.rb +18 -10
  15. data/lib/retrospec/plugins/v1/plugin/generators/function_generator.rb +187 -0
  16. data/lib/retrospec/plugins/v1/plugin/generators/module_generator.rb +25 -26
  17. data/lib/retrospec/plugins/v1/plugin/generators/{facter.rb → parsers/facter.rb} +28 -35
  18. data/lib/retrospec/plugins/v1/plugin/generators/parsers/function.rb +91 -0
  19. data/lib/retrospec/plugins/v1/plugin/generators/parsers/type.rb +79 -0
  20. data/lib/retrospec/plugins/v1/plugin/generators/provider_generator.rb +107 -0
  21. data/lib/retrospec/plugins/v1/plugin/generators/schema_generator.rb +221 -0
  22. data/lib/retrospec/plugins/v1/plugin/generators/type_generator.rb +118 -0
  23. data/lib/retrospec/plugins/v1/plugin/helpers.rb +3 -7
  24. data/lib/retrospec/plugins/v1/plugin/puppet.rb +141 -60
  25. data/lib/retrospec/plugins/v1/plugin/puppet_module.rb +29 -26
  26. data/lib/retrospec/plugins/v1/plugin/resource.rb +6 -7
  27. data/lib/retrospec/plugins/v1/plugin/spec_object.rb +5 -8
  28. data/lib/retrospec/plugins/v1/plugin/template_helpers.rb +9 -10
  29. data/lib/retrospec/plugins/v1/plugin/templates/clone-hook +15 -8
  30. data/lib/retrospec/plugins/v1/plugin/type_code.rb +4 -4
  31. data/lib/retrospec/plugins/v1/plugin/variable_store.rb +26 -30
  32. data/lib/retrospec/plugins/v1/plugin/version.rb +1 -1
  33. data/puppet-retrospec.gemspec +43 -4
  34. data/spec/fixtures/facts/oracle_controls.rb +38 -0
  35. data/spec/fixtures/fixture_modules/required_parameters/manifests/init.pp +8 -0
  36. data/spec/fixtures/fixture_modules/sample_module/lib/facter/fix_installed.rb +11 -0
  37. data/spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/awesome_parser.rb +13 -0
  38. data/spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/reduce.rb +31 -0
  39. data/spec/fixtures/fixture_modules/sample_module/lib/puppet/parser/functions/bad_sha1.rb +6 -0
  40. data/spec/fixtures/fixture_modules/sample_module/lib/puppet/parser/functions/defined.rb +94 -0
  41. data/spec/fixtures/fixture_modules/sample_module/lib/puppet/parser/functions/sha1.rb +6 -0
  42. data/spec/fixtures/fixture_modules/sample_module/spec/unit/facter/fix_installed_spec.rb +21 -0
  43. data/spec/fixtures/modules/tomcat/files/.gitkeep +0 -0
  44. data/spec/fixtures/modules/tomcat/templates/.gitkeep +0 -0
  45. data/spec/fixtures/modules/tomcat/tests/.gitkeep +0 -0
  46. data/spec/fixtures/providers/bmc/ipmitool.rb +188 -0
  47. data/spec/fixtures/providers/bmcuser/ipmitool.rb +140 -0
  48. data/spec/fixtures/types/bmc.rb +102 -0
  49. data/spec/fixtures/types/bmcuser.rb +46 -0
  50. data/spec/fixtures/types/db_opatch.rb +93 -0
  51. data/spec/integration/retrospec_spec.rb +1 -3
  52. data/spec/spec_helper.rb +33 -6
  53. data/spec/unit/conditional_spec.rb +12 -15
  54. data/spec/unit/generators/fact_generater_spec.rb +49 -17
  55. data/spec/unit/generators/function_generator_spec.rb +301 -0
  56. data/spec/unit/generators/function_spec.rb +67 -0
  57. data/spec/unit/generators/parsers/fact_spec.rb +62 -0
  58. data/spec/unit/generators/parsers/provider_spec.rb +44 -0
  59. data/spec/unit/generators/parsers/type_spec.rb +93 -0
  60. data/spec/unit/generators/provider_generator_spec.rb +120 -0
  61. data/spec/unit/generators/schema_generator_spec.rb +122 -0
  62. data/spec/unit/generators/type_generator_spec.rb +173 -0
  63. data/spec/unit/module_spec.rb +7 -10
  64. data/spec/unit/plugin_spec.rb +213 -15
  65. data/spec/unit/puppet-retrospec_spec.rb +81 -100
  66. data/spec/unit/resource_spec.rb +16 -17
  67. data/spec/unit/spec_object_spec.rb +46 -0
  68. data/spec/unit/type_code_spec.rb +9 -11
  69. data/spec/unit/variable_store_spec.rb +41 -43
  70. metadata +54 -4
  71. data/spec/unit/generators/fact_spec.rb +0 -58
@@ -1,38 +1,42 @@
1
1
  require 'spec_helper'
2
2
  require 'fakefs/safe'
3
3
 
4
- describe "puppet-retrospec" do
4
+ describe 'puppet-retrospec' do
5
5
  after :all do
6
6
  # enabling the removal slows down tests, but from time to time we may need to
7
7
  FileUtils.rm_rf(fixture_modules_path) if ENV['RETROSPEC_CLEAN_UP_TEST_MODULES'] =~ /true/
8
8
  end
9
9
 
10
+ let(:template_dir) do
11
+ retrospec_templates_path
12
+ end
13
+
10
14
  let(:global_config) do
11
- {'author' => 'Corey Osman'}
15
+ { 'author' => 'Corey Osman' }
12
16
  end
13
17
 
14
18
  let(:plugin_config) do
15
19
  {
16
- # 'plugins::puppet::template_dir' => '/Users',
17
- # 'plugins::puppet::templates::url' => '',
18
- # 'plugins::puppet::templates::ref' => '',
19
- # 'plugins::puppet::enable_future_parser' => '',
20
- # 'plugins::puppet::enable_beaker_tests' => '',
21
- # 'plugins::puppet::namespace' => '',
22
- # 'plugins::puppet::auto_create' => '',
20
+ # 'plugins::puppet::template_dir' => '/Users',
21
+ # 'plugins::puppet::templates::url' => '',
22
+ # 'plugins::puppet::templates::ref' => '',
23
+ # 'plugins::puppet::enable_future_parser' => '',
24
+ # 'plugins::puppet::enable_beaker_tests' => '',
25
+ # 'plugins::puppet::namespace' => '',
26
+ # 'plugins::puppet::auto_create' => '',
23
27
  }
24
28
  end
25
29
 
26
30
  let(:global_opts) do
27
- {:module_path => File.join(fixture_modules_path, 'tomcat')}
31
+ { :module_path => File.join(fixture_modules_path, 'tomcat') }
28
32
  end
29
33
 
30
34
  let(:plugin_opts) do
31
- {}
35
+ {}
32
36
  end
33
37
 
34
38
  before :all do
35
- #enabling the removal of real modules slows down tests, but from time to time we may need to
39
+ # enabling the removal of real modules slows down tests, but from time to time we may need to
36
40
  FileUtils.rm_rf(fixture_modules_path) if ENV['RETROSPEC_CLEAN_UP_TEST_MODULES'] =~ /true/
37
41
  install_module('puppetlabs-tomcat')
38
42
  @path = File.join(fixture_modules_path, 'tomcat')
@@ -40,8 +44,8 @@ describe "puppet-retrospec" do
40
44
 
41
45
  before :each do
42
46
  clean_up_spec_dir(@path)
43
- @opts = {:module_path => @path, :enable_beaker_tests => false, :name => 'name-test123',
44
- :enable_user_templates => false, :template_dir => '/tmp/.retrospec_templates' }
47
+ @opts = { :module_path => @path, :enable_beaker_tests => false, :name => 'name-test123',
48
+ :enable_user_templates => false, :template_dir => template_dir }
45
49
  end
46
50
 
47
51
  it 'should run without errors using new' do
@@ -50,45 +54,24 @@ describe "puppet-retrospec" do
50
54
  end
51
55
 
52
56
  it 'should set the parser to future' do
53
- opts = {:module_path => @path, :enable_beaker_tests => false,
54
- :enable_user_templates => false, :template_dir => nil, :enable_future_parser => true }
57
+ opts = { :module_path => @path, :enable_beaker_tests => false,
58
+ :enable_user_templates => false, :template_dir => nil, :enable_future_parser => true }
55
59
  tomcat = Retrospec::Plugins::V1::Puppet.new(opts[:module_path], opts)
56
60
  tomcat.post_init
57
61
  expect(tomcat.context.instance.future_parser).to eq(true)
58
62
  end
59
- describe 'new module' do
60
- after :each do
61
- FileUtils.rm_rf('/tmp/new_module')
62
- end
63
- it 'should create a module when it does not exist' do
64
- opts = {'plugins::puppet::author' => 'test_name', :module_path => '/tmp/new_module', :create => true,
65
- :namespace => 'retrospec', :enable_beaker_tests => false,
66
- :enable_user_templates => false, :name => 'moduletest',
67
- :template_dir => File.expand_path(File.join(ENV['HOME'], '.retrospec', 'repos', 'retrospec-puppet-templates')),
68
- :enable_future_parser => true }
69
- ENV['RETROSPEC_PUPPET_AUTO_GENERATE'] = 'true'
70
- new_module = Retrospec::Plugins::V1::Puppet.new(opts[:module_path], opts)
71
- allow(new_module).to receive(:gets).and_return("y\n")
72
- new_module.new_module(opts)
73
- new_module.post_init
74
- new_module.run
75
- expect(File.exists?(File.join(new_module.manifest_dir, 'init.pp'))).to eq(true)
76
- expect(File.exists?(File.join(new_module.module_path, 'metadata.json'))).to eq(true)
77
- expect(JSON.parse(File.read(File.join(new_module.module_path, 'metadata.json')))['author']).to eq('test_name')
78
- end
79
- end
80
63
 
81
64
  it 'should create files without error' do
82
65
  tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], @opts)
83
66
  tomcat.post_init
84
67
  tomcat.create_files
85
- expect(File.exists?(File.join(@path, 'Gemfile'))).to eq(true)
86
- expect(File.exists?(File.join(@path, 'Rakefile'))).to eq(true)
87
- expect(File.exists?(File.join(@path, 'spec','spec_helper.rb'))).to eq(true)
88
- expect(File.exists?(File.join(@path, '.travis.yml'))).to eq(true)
89
- expect(File.exists?(File.join(@path, 'spec', 'shared_contexts.rb'))).to eq(true)
90
- expect(File.exists?(File.join(@path, '.fixtures.yml'))).to eq(true)
91
- expect(File.exists?(File.join(@path, 'spec','classes','tomcat_spec.rb'))).to eq(true)
68
+ expect(File.exist?(File.join(@path, 'Gemfile'))).to eq(true)
69
+ expect(File.exist?(File.join(@path, 'Rakefile'))).to eq(true)
70
+ expect(File.exist?(File.join(@path, 'spec', 'spec_helper.rb'))).to eq(true)
71
+ expect(File.exist?(File.join(@path, '.travis.yml'))).to eq(true)
72
+ expect(File.exist?(File.join(@path, 'spec', 'shared_contexts.rb'))).to eq(true)
73
+ expect(File.exist?(File.join(@path, '.fixtures.yml'))).to eq(true)
74
+ expect(File.exist?(File.join(@path, 'spec', 'classes', 'tomcat_spec.rb'))).to eq(true)
92
75
  end
93
76
 
94
77
  it 'should create acceptance test files' do
@@ -97,12 +80,11 @@ describe "puppet-retrospec" do
97
80
  tomcat.post_init
98
81
  spec_path = File.expand_path(File.join(@path, 'spec'))
99
82
  tomcat.create_files
100
- expect(File.exists?(File.join(spec_path, 'spec_helper_acceptance.rb'))).to eq(true)
101
- expect(File.exists?(File.join(spec_path, 'acceptance'))).to eq(true)
102
- expect(File.exists?(File.join(spec_path, 'acceptance', 'classes', 'tomcat_spec.rb'))).to eq(true)
103
- expect(File.exists?(File.join(spec_path, 'acceptance', 'nodesets'))).to eq(true)
104
- expect(File.exists?(File.join(spec_path, 'acceptance', 'nodesets', 'default.yml'))).to eq(true)
105
-
83
+ expect(File.exist?(File.join(spec_path, 'spec_helper_acceptance.rb'))).to eq(true)
84
+ expect(File.exist?(File.join(spec_path, 'acceptance'))).to eq(true)
85
+ expect(File.exist?(File.join(spec_path, 'acceptance', 'classes', 'tomcat_spec.rb'))).to eq(true)
86
+ expect(File.exist?(File.join(spec_path, 'acceptance', 'nodesets'))).to eq(true)
87
+ expect(File.exist?(File.join(spec_path, 'acceptance', 'nodesets', 'default.yml'))).to eq(true)
106
88
  end
107
89
 
108
90
  it 'should not create acceptance test files' do
@@ -112,11 +94,11 @@ describe "puppet-retrospec" do
112
94
  tomcat.post_init
113
95
  spec_path = File.expand_path(File.join(@path, 'spec'))
114
96
  tomcat.create_files
115
- expect(File.exists?(File.join(spec_path, 'spec_helper_acceptance.rb'))).to eq(false)
116
- expect(File.exists?(File.join(spec_path, 'acceptance'))).to eq(true)
117
- expect(File.exists?(File.join(spec_path, 'acceptance', 'classes', 'tomcat_spec.rb'))).to eq(false)
118
- expect(File.exists?(File.join(spec_path, 'acceptance', 'nodesets'))).to eq(false)
119
- expect(File.exists?(File.join(spec_path, 'acceptance', 'nodesets', 'default.yml'))).to eq(false)
97
+ expect(File.exist?(File.join(spec_path, 'spec_helper_acceptance.rb'))).to eq(false)
98
+ expect(File.exist?(File.join(spec_path, 'acceptance'))).to eq(true)
99
+ expect(File.exist?(File.join(spec_path, 'acceptance', 'classes', 'tomcat_spec.rb'))).to eq(false)
100
+ expect(File.exist?(File.join(spec_path, 'acceptance', 'nodesets'))).to eq(false)
101
+ expect(File.exist?(File.join(spec_path, 'acceptance', 'nodesets', 'default.yml'))).to eq(false)
120
102
  end
121
103
 
122
104
  it 'should create proper spec helper file' do
@@ -125,7 +107,7 @@ describe "puppet-retrospec" do
125
107
  filepath = File.expand_path(File.join(@path, 'spec', 'spec_helper.rb'))
126
108
  tomcat.safe_create_module_files
127
109
  path = tomcat.module_path
128
- expect(File.exists?(filepath)).to eq(true)
110
+ expect(File.exist?(filepath)).to eq(true)
129
111
  end
130
112
 
131
113
  it 'should create proper shared context file' do
@@ -133,7 +115,7 @@ describe "puppet-retrospec" do
133
115
  tomcat.post_init
134
116
  filepath = File.expand_path(File.join(@path, 'spec', 'shared_contexts.rb'))
135
117
  tomcat.safe_create_module_files
136
- expect(File.exists?(filepath)).to eq(true)
118
+ expect(File.exist?(filepath)).to eq(true)
137
119
  end
138
120
 
139
121
  it 'should produce hiera data' do
@@ -142,47 +124,47 @@ describe "puppet-retrospec" do
142
124
  filepath = File.expand_path(File.join(@path, 'spec', 'shared_contexts.rb'))
143
125
  tomcat.safe_create_module_files
144
126
  path = tomcat.module_path
145
- expect(tomcat.context.all_hiera_data).to eq({"tomcat::catalina_home"=>nil,
146
- "tomcat::user"=>nil,
147
- "tomcat::group"=>nil,
148
- "tomcat::install_from_source"=>nil,
149
- "tomcat::purge_connectors"=>nil,
150
- "tomcat::purge_realms"=>nil,
151
- "tomcat::manage_user"=>nil,
152
- "tomcat::manage_group"=>nil}
153
- )
127
+ expect(tomcat.context.all_hiera_data).to eq('tomcat::catalina_home' => nil,
128
+ 'tomcat::user' => nil,
129
+ 'tomcat::group' => nil,
130
+ 'tomcat::install_from_source' => nil,
131
+ 'tomcat::purge_connectors' => nil,
132
+ 'tomcat::purge_realms' => nil,
133
+ 'tomcat::manage_user' => nil,
134
+ 'tomcat::manage_group' => nil
135
+ )
154
136
 
155
137
  expect(File.read(filepath)).to include('#"tomcat::catalina_home" => \'\',')
156
138
  end
157
139
 
158
140
  it 'should create acceptance spec helper file' do
159
- opts = {:module_path => @path, :enable_beaker_tests => true,
160
- :template_dir => '/tmp/my_templates' }
141
+ opts = { :module_path => @path, :enable_beaker_tests => true,
142
+ :template_dir => template_dir }
161
143
  tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], opts)
162
144
  tomcat.post_init
163
145
  filepath = File.expand_path(File.join(@path, 'spec', 'spec_helper_acceptance.rb'))
164
146
  tomcat.safe_create_module_files
165
- expect(File.exists?(filepath)).to eq(true)
147
+ expect(File.exist?(filepath)).to eq(true)
166
148
  end
167
149
 
168
150
  it 'should not create acceptance spec helper file' do
169
- opts = {:module_path => @path, :enable_beaker_tests => false,
170
- :template_dir => '/tmp/my_templates' }
151
+ opts = { :module_path => @path, :enable_beaker_tests => false,
152
+ :template_dir => template_dir }
171
153
  filepath = File.expand_path(File.join(@path, 'spec', 'spec_helper_acceptance.rb'))
172
154
  tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], opts)
173
155
  tomcat.post_init
174
156
  tomcat.safe_create_module_files
175
- expect(File.exists?(filepath)).to eq(false)
157
+ expect(File.exist?(filepath)).to eq(false)
176
158
  end
177
159
 
178
160
  it 'should create 15 nodesets' do
179
- opts = {:module_path => @path, :enable_beaker_tests => true,
180
- :template_dir => '/tmp/my_templates' }
161
+ opts = { :module_path => @path, :enable_beaker_tests => true,
162
+ :template_dir => template_dir }
181
163
  tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], opts)
182
164
  tomcat.post_init
183
165
  filepath = File.expand_path(File.join(@path, 'spec', 'acceptance', 'nodesets', 'default.yml'))
184
166
  tomcat.safe_create_module_files
185
- expect(File.exists?(filepath)).to eq(true)
167
+ expect(File.exist?(filepath)).to eq(true)
186
168
  expect(Dir.glob(File.expand_path(File.join(@path, 'spec', 'acceptance', 'nodesets', '*.yml'))).length).to eq 15
187
169
  end
188
170
 
@@ -191,7 +173,7 @@ describe "puppet-retrospec" do
191
173
  tomcat.post_init
192
174
  filepath = File.expand_path(File.join(@path, 'Gemfile'))
193
175
  tomcat.safe_create_module_files
194
- expect(File.exists?(filepath)).to eq(true)
176
+ expect(File.exist?(filepath)).to eq(true)
195
177
  end
196
178
 
197
179
  it 'should create Rakefile file' do
@@ -199,85 +181,84 @@ describe "puppet-retrospec" do
199
181
  tomcat.post_init
200
182
  filepath = File.expand_path(File.join(@path, 'Rakefile'))
201
183
  tomcat.safe_create_module_files
202
- expect(File.exists?(filepath)).to eq(true)
184
+ expect(File.exist?(filepath)).to eq(true)
203
185
  end
204
186
 
205
187
  it 'should create proper fixtures file' do
206
- filepath = File.expand_path(File.join(@path,'.fixtures.yml'))
207
- FileUtils.rm_f(filepath) # ensure we have a clean state
188
+ filepath = File.expand_path(File.join(@path, '.fixtures.yml'))
189
+ FileUtils.rm_f(filepath) # ensure we have a clean state
208
190
  tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], @opts)
209
191
  tomcat.post_init
210
192
  tomcat.safe_create_module_files
211
- expect(File.exists?(filepath)).to eq(true)
193
+ expect(File.exist?(filepath)).to eq(true)
212
194
  end
213
195
 
214
196
  it 'should not create any files when 0 resources exists' do
215
197
  my_path = File.expand_path(File.join('spec', 'fixtures', 'fixture_modules', 'zero_resource_module'))
216
198
  my_retro = Retrospec::Plugins::V1::Puppet.new(my_path, @opts)
217
- my_retro.should_not_receive(:safe_create_file).with(anything,'resource_spec_file.erb')
199
+ my_retro.should_not_receive(:safe_create_file).with(anything, 'resource_spec_file.erb')
218
200
  end
219
201
 
220
202
  it 'should create a file from a template' do
221
203
  tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], @opts)
222
204
  tomcat.post_init
223
- file_path = File.join(@path,'.fixtures.yml')
224
- template_file = File.join(tomcat.template_dir,'module_files','.fixtures.yml.retrospec.erb')
205
+ file_path = File.join(@path, '.fixtures.yml')
206
+ template_file = File.join(tomcat.template_dir, 'module_files', '.fixtures.yml.retrospec.erb')
225
207
  tomcat.safe_create_template_file(file_path, template_file, tomcat.context)
226
- expect(File.exists?(file_path)).to eq(true)
208
+ expect(File.exist?(file_path)).to eq(true)
227
209
  end
228
210
 
229
211
  describe 'generate_file_path' do
230
212
  describe 'classes' do
231
213
  it 'should generate a acceptance test path correctly' do
232
- type = double("type")
214
+ type = double('type')
233
215
  allow(type).to receive(:type).and_return(:hostclass)
234
216
  allow(type).to receive(:name).and_return('tomcat::config::server::connector')
235
217
  tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], @opts)
236
- expect(tomcat.generate_file_path(type, true)).to eq("spec/acceptance/classes/config/server/connector_spec.rb")
218
+ expect(tomcat.generate_file_path(type, true)).to eq('spec/acceptance/classes/config/server/connector_spec.rb')
237
219
  end
238
220
  it 'should generate a normal test path correctly' do
239
- type = double("type")
221
+ type = double('type')
240
222
  allow(type).to receive(:type).and_return(:hostclass)
241
223
  allow(type).to receive(:name).and_return('tomcat::config::server::connector')
242
224
  tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], @opts)
243
- expect(tomcat.generate_file_path(type, false)).to eq("spec/classes/config/server/connector_spec.rb")
225
+ expect(tomcat.generate_file_path(type, false)).to eq('spec/classes/config/server/connector_spec.rb')
244
226
  end
245
227
  end
246
228
 
247
229
  describe 'defines' do
248
230
  it 'should generate a acceptance test path correctly' do
249
- type = double("type")
231
+ type = double('type')
250
232
  allow(type).to receive(:type).and_return(:definition)
251
233
  allow(type).to receive(:name).and_return('tomcat::config::server::connector')
252
234
  tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], @opts)
253
- expect(tomcat.generate_file_path(type, true)).to eq("spec/acceptance/defines/config/server/connector_spec.rb")
235
+ expect(tomcat.generate_file_path(type, true)).to eq('spec/acceptance/defines/config/server/connector_spec.rb')
254
236
  end
255
237
 
256
238
  it 'should generate a normal test path correctly' do
257
- type = double("type")
239
+ type = double('type')
258
240
  allow(type).to receive(:type).and_return(:definition)
259
241
  allow(type).to receive(:name).and_return('tomcat::config::server::connector')
260
242
  tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], @opts)
261
- expect(tomcat.generate_file_path(type, false)).to eq("spec/defines/config/server/connector_spec.rb")
243
+ expect(tomcat.generate_file_path(type, false)).to eq('spec/defines/config/server/connector_spec.rb')
262
244
  end
263
245
  end
264
246
 
265
247
  describe 'nodes' do
266
248
  it 'should generate a normal test path correctly' do
267
- type = double("type")
249
+ type = double('type')
268
250
  allow(type).to receive(:type).and_return(:node)
269
251
  allow(type).to receive(:name).and_return('server1.example.com')
270
252
  tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], @opts)
271
- expect(tomcat.generate_file_path(type, true)).to eq("spec/acceptance/hosts/server1.example.com_spec.rb")
253
+ expect(tomcat.generate_file_path(type, true)).to eq('spec/acceptance/hosts/server1.example.com_spec.rb')
272
254
  end
273
255
  end
274
256
  end
275
257
 
276
258
  it 'should generate a test file name correctly' do
277
- tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], @opts)
278
- expect(tomcat.generate_file_name('tomcat::config::server::connector')).to eq('connector_spec.rb')
279
- expect(tomcat.generate_file_name('tomcat')).to eq('tomcat_spec.rb')
280
- expect(tomcat.generate_file_name('tomcat::config')).to eq('config_spec.rb')
259
+ tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], @opts)
260
+ expect(tomcat.generate_file_name('tomcat::config::server::connector')).to eq('connector_spec.rb')
261
+ expect(tomcat.generate_file_name('tomcat')).to eq('tomcat_spec.rb')
262
+ expect(tomcat.generate_file_name('tomcat::config')).to eq('config_spec.rb')
281
263
  end
282
-
283
- end
264
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "resource" do
3
+ describe 'resource' do
4
4
  after :all do
5
5
  # enabling the removal slows down tests, but from time to time we may need to
6
6
  FileUtils.rm_rf(fixture_modules_path) if ENV['RETROSPEC_CLEAN_UP_TEST_MODULES'] =~ /true/
@@ -17,7 +17,7 @@ describe "resource" do
17
17
  end
18
18
 
19
19
  describe 'one resource module' do
20
- let(:instance) {Utilities::PuppetModule.send :new}
20
+ let(:instance) { Utilities::PuppetModule.send :new }
21
21
  before :each do
22
22
  my_path = File.expand_path(File.join('spec', 'fixtures', 'fixture_modules', 'one_resource_module'))
23
23
  @m = instance
@@ -26,40 +26,39 @@ describe "resource" do
26
26
  end
27
27
 
28
28
  it 'should initialize with one resource' do
29
- r = Resource.all(@m.types.find {|x| x.name == 'one_resource'})
29
+ r = Resource.all(@m.types.find { |x| x.name == 'one_resource' })
30
30
  expect(r.length).to eq(1)
31
- expect(r[0].parameters).to eq({"ensure"=>"present"})
32
- expect(r[0].title).to eq("/tmp/test")
33
- expect(r[0].type).to eq("file")
31
+ expect(r[0].parameters).to eq('ensure' => 'present')
32
+ expect(r[0].title).to eq('/tmp/test')
33
+ expect(r[0].type).to eq('file')
34
34
  end
35
35
 
36
36
  it 'should initialize with two resources' do
37
- test_type = @m.types.find {|x| x.name == 'one_resource::another_resource'}
37
+ test_type = @m.types.find { |x| x.name == 'one_resource::another_resource' }
38
38
  VariableStore.populate(test_type)
39
39
  r = Resource.all(test_type)
40
40
  expect(r.length).to eq(2)
41
- expect(r[0].parameters).to eq({"ensure"=>"present"})
42
- expect(r[0].title).to eq("/tmp/test2")
43
- expect(r[0].type).to eq("file")
44
- expect(r[1].parameters).to eq({"ensure"=>"present","content" => "/tmp/test3/test3183/oohhhh"})
45
- expect(r[1].title).to eq("/tmp/test3")
46
- expect(r[1].type).to eq("file")
41
+ expect(r[0].parameters).to eq('ensure' => 'present')
42
+ expect(r[0].title).to eq('/tmp/test2')
43
+ expect(r[0].type).to eq('file')
44
+ expect(r[1].parameters).to eq('ensure' => 'present', 'content' => '/tmp/test3/test3183/oohhhh')
45
+ expect(r[1].title).to eq('/tmp/test3')
46
+ expect(r[1].type).to eq('file')
47
47
  end
48
48
 
49
49
  it 'should return resources' do
50
- test_type = @m.types.find {|x| x.name == 'one_resource::another_resource'}
50
+ test_type = @m.types.find { |x| x.name == 'one_resource::another_resource' }
51
51
  expect(Resource.all(test_type.code).length).to eq(2)
52
52
  end
53
-
54
53
  end
55
54
  describe 'zero module' do
56
- let(:instance) {Utilities::PuppetModule.send :new}
55
+ let(:instance) { Utilities::PuppetModule.send :new }
57
56
  it 'can process an empty class' do
58
57
  my_path = File.expand_path(File.join('spec', 'fixtures', 'fixture_modules', 'zero_resource_module'))
59
58
  m = instance
60
59
  m.module_path = my_path
61
60
  m.create_tmp_module_path(my_path)
62
- test_type = m.types.find {|x| x.name == 'empty_class'}
61
+ test_type = m.types.find { |x| x.name == 'empty_class' }
63
62
  r = Resource.all(test_type)
64
63
  expect(r.size).to eq(0)
65
64
  end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'spec_object' do
4
+
5
+ let(:path) do
6
+ File.join(fixture_modules_path, 'tomcat')
7
+ end
8
+
9
+ let(:opts) do
10
+ { :module_path => path, :enable_beaker_tests => false, :name => 'name-test123',
11
+ :enable_user_templates => false, :template_dir => '/tmp/.retrospec_templates' }
12
+ end
13
+
14
+ let(:puppet_context) do
15
+ path = File.join(fixture_modules_path, 'tomcat')
16
+ opts = { :module_path => path, :enable_beaker_tests => false, :name => 'name-test123',
17
+ :enable_user_templates => false, :template_dir => '/tmp/.retrospec_templates' }
18
+ mod = Retrospec::Plugins::V1::Puppet.new(opts[:module_path], opts)
19
+ mod.post_init
20
+ mod.context
21
+ end
22
+
23
+ it 'should get all hiera data' do
24
+ expect(puppet_context.class_hiera_data('tomcat')).to eq({"tomcat::catalina_home" => nil,
25
+ "tomcat::group" => nil,
26
+ "tomcat::install_from_source" => nil,
27
+ "tomcat::manage_group" => nil,
28
+ "tomcat::manage_user" => nil,
29
+ "tomcat::purge_connectors" => nil,
30
+ "tomcat::purge_realms" => nil,
31
+ "tomcat::user" => nil,
32
+ })
33
+ end
34
+
35
+ it 'should get all hiera data' do
36
+ expect(puppet_context.all_hiera_data).to eq({"tomcat::catalina_home" => nil,
37
+ "tomcat::group" => nil,
38
+ "tomcat::install_from_source" => nil,
39
+ "tomcat::manage_group" => nil,
40
+ "tomcat::manage_user" => nil,
41
+ "tomcat::purge_connectors" => nil,
42
+ "tomcat::purge_realms" => nil,
43
+ "tomcat::user" => nil,
44
+ })
45
+ end
46
+ end