puppet-retrospec 0.9.1 → 0.10.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: 3461b3345064309ba4d62c62b0393ed4f4223ba6
4
- data.tar.gz: 57deba94c2c1d0e62c85263bbedf9771f4b5f213
3
+ metadata.gz: cbc49b480678daffff061e656b863bd070e751aa
4
+ data.tar.gz: 664b47744df42f5fa4df4121ac631a443c578818
5
5
  SHA512:
6
- metadata.gz: 81efc82dbb22d30e873dbb1e9a1ddf4fc10b065f31174cfce7a4959876019a0e6e183ce2eed64e2e54264e82834bea2e85c695075195ce1f83326ed3cc73694d
7
- data.tar.gz: c1e46dea03222cfd8a7ee237bbde5e54937dc6223cfcacaeeb3b2b863b4fa4e9e023634de458ad91125ae55dbd43b6d07aaf615dd3b62c9e660b036f4f96c068
6
+ metadata.gz: 3c933d5fb7ee82ea64ab460dfe40f4b6e8a79d690785ece5422109323aedf9998112f27f0d0b949a89e2dfae0edf7b28314ef5c0f6b43442a2c1dfb112575b31
7
+ data.tar.gz: 8df5426ac543a838444891ca1a4cbca589d9dc228344e589975da6fab5d16eaee44674f8489e02d1325cf9b9f66938a79fdebad7013c2725b6028681bc1f06a1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.10.0
2
+ * refactor cli options to use retrospec 0.4.0 specifications
3
+ * gh-32 - add ability to create new module
4
+ * fix pinning of module to use 0.x.0 instead of 0.x
5
+ * pin to version 0.4.x
1
6
  ## 0.9.0
2
7
  * convert to retrospec plugin
3
8
  This is a big change in how you run puppet-retrospec please see the readme for changes.
data/Gemfile CHANGED
@@ -1,25 +1,15 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # while retrospec does not use facter or hiera,
4
- # we vendor the puppet gem 3.7.3 which also requires facter and hiera
5
- #gem 'facter', '< 3', '> 1.6'
6
- #gem 'hiera', '~> 1.0'
7
-
8
3
  gem 'trollop'
9
- gem 'retrospec', "~> 0.3"
4
+ gem 'retrospec', "~> 0.4.0"
10
5
  # Include everything needed to run rake, tests, features, etc.
11
6
  group :development do
12
7
  gem "rspec", "~> 3.2"
13
8
  gem 'puppet', '3.7.3', :path => 'vendor/gems/puppet-3.7.3'
14
- #gem 'facter', '< 3', '> 1.6'
15
- #gem 'hiera', '~> 1.0'
16
9
  gem "yard", "~> 0.7"
17
10
  gem "rdoc", "~> 3.12"
18
11
  gem "bundler", "~> 1.0"
19
12
  gem "jeweler"
20
13
  gem 'pry'
21
14
  gem "fakefs", :require => "fakefs/safe"
22
- gem 'pry-rescue'
23
- gem 'pry-stack_explorer'
24
- gem 'pry-coolline'
25
15
  end
data/Gemfile.lock CHANGED
@@ -11,13 +11,8 @@ GEM
11
11
  specs:
12
12
  CFPropertyList (2.2.8)
13
13
  addressable (2.3.8)
14
- binding_of_caller (0.7.2)
15
- debug_inspector (>= 0.0.1)
16
14
  builder (3.2.2)
17
15
  coderay (1.1.0)
18
- coolline (0.5.0)
19
- unicode_utils (~> 1.4)
20
- debug_inspector (0.0.2)
21
16
  descendants_tracker (0.0.4)
22
17
  thread_safe (~> 0.3, >= 0.3.1)
23
18
  diff-lcs (1.2.5)
@@ -39,7 +34,6 @@ GEM
39
34
  hiera (1.3.4)
40
35
  json_pure
41
36
  highline (1.7.7)
42
- interception (0.5)
43
37
  jeweler (2.0.1)
44
38
  builder
45
39
  bundler (>= 1.0)
@@ -69,19 +63,11 @@ GEM
69
63
  coderay (~> 1.1.0)
70
64
  method_source (~> 0.8.1)
71
65
  slop (~> 3.4)
72
- pry-coolline (0.2.5)
73
- coolline (~> 0.5)
74
- pry-rescue (1.4.2)
75
- interception (>= 0.5)
76
- pry
77
- pry-stack_explorer (0.4.9.2)
78
- binding_of_caller (>= 0.7)
79
- pry (>= 0.9.11)
80
66
  rack (1.6.4)
81
67
  rake (10.4.2)
82
68
  rdoc (3.12.2)
83
69
  json (~> 1.4)
84
- retrospec (0.3.0)
70
+ retrospec (0.4.0)
85
71
  trollop
86
72
  rspec (3.3.0)
87
73
  rspec-core (~> 3.3.0)
@@ -99,7 +85,6 @@ GEM
99
85
  slop (3.6.0)
100
86
  thread_safe (0.3.5)
101
87
  trollop (2.1.2)
102
- unicode_utils (1.4.0)
103
88
  yard (0.8.7.6)
104
89
 
105
90
  PLATFORMS
@@ -110,12 +95,9 @@ DEPENDENCIES
110
95
  fakefs
111
96
  jeweler
112
97
  pry
113
- pry-coolline
114
- pry-rescue
115
- pry-stack_explorer
116
98
  puppet (= 3.7.3)!
117
99
  rdoc (~> 3.12)
118
- retrospec (~> 0.3)
100
+ retrospec (~> 0.4.0)
119
101
  rspec (~> 3.2)
120
102
  trollop
121
103
  yard (~> 0.7)
data/README.md CHANGED
@@ -68,34 +68,80 @@ Installing ri documentation for puppet-retrospec-0.9.0
68
68
 
69
69
  ```
70
70
 
71
- Dependency
72
- ============
71
+ ## Dependency
73
72
  Retrospec relies heavily on the puppet 3.7.x codebase. Because of this hard dependency the puppet gem is vendored into
74
73
  the library so there should not be conflicts with your existing puppet gem.
75
74
 
76
- Install
77
- =============
75
+ ## Install
78
76
  `gem install puppet-retrospec`
79
77
 
80
78
  This will also install the retrospec framework that is required to use the plugin.
81
79
 
82
- How to use
83
- =============
84
- Run from the command line
80
+ ## How to use
81
+
82
+ Run from the command line: `retrospec puppet`
83
+
84
+ If you need to point to a directory outside the current directory you can use the `--module_path` option.
85
85
  ```
86
- retrospec puppet -h
86
+ [puppet@puppetdev ~]$ retrospec -m /tmp/test3323 puppet -h
87
87
  Generates puppet rspec test code based on the classes and defines inside the manifests directory.
88
- -t, --template-dir=<s> Path to templates directory (only for overriding Retrospec templates) (default: /home/puppet/.retrospec/repos/retrospec-puppet-templates)
89
- -s, --scm-url=<s> SCM url for retrospec templates (default: https://github.com/nwops/retrospec-templates)
88
+
89
+ Subcommands:
90
+ new_module
91
+ -t, --template-dir=<s> Path to templates directory (only for overriding Retrospec templates)
92
+ (default: /Users/cosman/.retrospec/repos/retrospec-puppet-templates)
93
+ -s, --scm-url=<s> SCM url for retrospec templates (default:
94
+ https://github.com/nwops/retrospec-templates)
95
+ -n, --name=<s> The name of the module you wish to create (default: test3323)
90
96
  -b, --branch=<s> Branch you want to use for the retrospec template repo (default: master)
97
+ -a, --namespace=<s> The namespace to use only when creating a new module (default: namespace)
91
98
  -e, --enable-beaker-tests Enable the creation of beaker tests
92
- -n, --enable-future-parser Enables the future parser only during validation
99
+ -l, --enable-future-parser Enables the future parser only during validation
93
100
  -v, --version Print version and exit
94
- -h, --help Show this message
101
+ -h, --help Show this message -h, --help Show this message
102
+ ```
95
103
 
96
104
 
105
+ ### Enabling the future parser
97
106
 
98
- retrospec -m ~/projects/puppet_modules/apache puppet --enable-future-parser
107
+ `retrospec -m ~/projects/puppet_modules/apache puppet --enable-future-parser`
108
+
109
+ ### Creating a new module
110
+
111
+ Creating a new module can now be done with retrospec as of 0.10.0. To do so you just need to use the sub command
112
+ `new_module`. See `retrospec puppet -h` for more options and overridable configurations.
113
+
114
+
115
+ ```
116
+ retrospec -m /tmp/new_module puppet new_module --namespace lmc --name apache2
117
+ Successfully ran hook: /Users/cosman/.retrospec/repos/retrospec-puppet-templates/clone-hook
118
+ Already up-to-date.
119
+
120
+ The module located at: /tmp/new_module does not exist, do you wish to create it? (y/n): y
121
+ + /tmp/new_module/manifests/
122
+ + /tmp/new_module/manifests/init.pp
123
+ Successfully ran hook: /Users/cosman/.retrospec/repos/retrospec-puppet-templates/pre-hook
124
+
125
+ + /tmp/new_module/.bundle/
126
+ + /tmp/new_module/.bundle/config
127
+ + /tmp/new_module/.fixtures.yml
128
+ + /tmp/new_module/.git/
129
+ + /tmp/new_module/.git/hooks/
130
+ + /tmp/new_module/.git/hooks/pre-commit
131
+ + /tmp/new_module/.gitignore
132
+ + /tmp/new_module/.puppet-lint.rc
133
+ + /tmp/new_module/.travis.yml
134
+ + /tmp/new_module/Gemfile
135
+ + /tmp/new_module/README.markdown
136
+ + /tmp/new_module/Rakefile
137
+ + /tmp/new_module/Vagrantfile
138
+ + /tmp/new_module/spec/
139
+ + /tmp/new_module/spec/acceptance/
140
+ + /tmp/new_module/spec/shared_contexts.rb
141
+ + /tmp/new_module/spec/spec_helper.rb
142
+ + /tmp/new_module/metadata.json
143
+ + /tmp/new_module/spec/classes/
144
+ + /tmp/new_module/spec/classes/apache2_spec.rb
99
145
 
100
146
  ```
101
147
 
@@ -111,15 +157,16 @@ plugins::puppet::templates::ref: master
111
157
  plugins::puppet::enable_beaker_tests: true
112
158
  plugins::puppet::enable_future_parser: true
113
159
  plugins::puppet::template_dir: /Users/username/.retrospec/repos/retrospec-puppet-templates
160
+ plugins::puppet::namespace: organization
161
+ plugins::puppet::author: your_name
114
162
  ```
115
-
116
- Note: your not require to set any of these as they can be specified on the cli and also default to
163
+ Note: your not required to set any of these as they can be specified on the cli and also default to
117
164
  sane values.
118
165
 
119
166
  Example
120
167
  ======================
121
168
 
122
- Below you can see that it creates files for every resource in the tomcat module in addition to other files
169
+ Below you can see that it creates files for every resource in the apache module in addition to other files
123
170
  that you need for unit testing puppet code. Rspec-puppet best practices says to put definitions in a defines folder
124
171
  and classes in a classes folder since it infers what kind of resource it is based on this convention. Retrospec sets up
125
172
  this scaffolding for you. Don't like the files that came with your module? Simply delete the files and re-generate them
@@ -413,9 +460,9 @@ Lets say I have three clients that each need site specific files in the module a
413
460
  don't give me everything I want. Thus I will need to override the templates for each client.
414
461
 
415
462
  ```shell
416
- retrospec --template-dir ~/retrspec_client1
417
- retrospec --template-dir ~/retrspec_client2
418
- retrospec --template-dir ~/retrspec_client3
463
+ retrospec puppet --template-dir ~/retrspec_client1
464
+ retrospec puppet --template-dir ~/retrspec_client2
465
+ retrospec puppet --template-dir ~/retrspec_client3
419
466
  touch ~/retrspec_client1/module_files/special_file_for_client1.yml
420
467
  touch ~/retrspec_client2/module_files/special_file_for_client2.yml
421
468
  touch ~/retrspec_client3/module_files/special_file_for_client3.yml
@@ -568,7 +615,7 @@ parser cannot read future code syntax. If your puppet 4 codebase is compatible
568
615
  In order to allow future parser validation please run retrospec with the following option.
569
616
 
570
617
  ```shell
571
- retrospec --enable-future-parser
618
+ retrospec puppet --enable-future-parser
572
619
 
573
620
  ```
574
621
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.1
1
+ 0.10.0
@@ -1,5 +1,6 @@
1
1
  require 'retrospec/plugins/v1/module_helpers'
2
2
  require 'retrospec/plugins/v1'
3
+ require 'retrospec/config'
3
4
  require_relative 'spec_object'
4
5
  require 'erb'
5
6
  require_relative 'template_helpers'
@@ -26,36 +27,98 @@ module Retrospec
26
27
  Utilities::PuppetModule.instance.future_parser = config_data[:enable_future_parser]
27
28
  # user supplied a template path or user wants to use local templates
28
29
  @template_dir = setup_user_template_dir(config_data[:template_dir], config_data[:scm_url], config_data[:ref])
30
+ end
31
+
32
+ def post_init
33
+ # before we validate the module directory we should ensure the module exists by creating it
29
34
  # validation also occurs when setting the module path
30
35
  Utilities::PuppetModule.instance.module_path = module_path
31
36
  Utilities::PuppetModule.create_tmp_module_path # this is required to finish initialization
37
+ # setting the context is require to make other methods below work. #TODO lazy create the context
32
38
  @context = ::Puppet::SpecObject.new(module_path, Utilities::PuppetModule.instance, config_data)
33
39
  end
34
40
 
35
- # used to display subcommand options to the cli
41
+ # if the module does not exist lets create it
42
+ # this will create the module directory, manifests directory and basic init.pp file
43
+ # if the manifest directory already exist but an init.pp file does not we do not creating
44
+ # anything since it is not mandatory
45
+ # I thought about using the the module face to perform this generation but it seems like its not
46
+ # supported at this time, and you can't specify the path to generate the module in
47
+ def new_module
48
+ unless File.exist?(manifest_dir)
49
+ init_class = File.join(manifest_dir, 'init.pp')
50
+ content = File.read(File.join(template_dir, 'manifest_file.pp'))
51
+ print "The module located at: #{module_path} does not exist, do you wish to create it? (y/n): "
52
+ answer = gets.chomp
53
+ unless answer =~ /y/i
54
+ exit 1
55
+ end
56
+ create_manifest_file(init_class, content)
57
+ end
58
+ end
59
+
60
+ # used to display subcommand options to tglobal_confighe cli
36
61
  # the global options are passed in for your usage
37
62
  # http://trollop.rubyforge.org
38
63
  # all options here are available in the config passed into the initialize code
39
- def self.cli_options(global_opts)
40
- template_dir = global_opts['plugins::puppet::template_dir'] || File.expand_path('~/.retrospec/repos/retrospec-puppet-templates')
41
- scm_url = ENV['RETROSPEC_PUPPET_SCM_URL'] || global_opts['plugins::puppet::templates::url']
42
- scm_branch = ENV['RETROSPEC_PUPPET_SCM_BRANCH'] || global_opts['plugins::puppet::templates::ref'] || 'master'
43
- future_parser = global_opts['plugins::puppet::enable_future_parser']
44
- beaker_tests = global_opts['plugins::puppet::enable_beaker_tests']
45
- Trollop::options do
64
+ # this is the only entry point into the plugin
65
+ def self.run_cli(global_opts, global_config, plugin_config, args=ARGV)
66
+ template_dir = plugin_config['plugins::puppet::template_dir'] || File.expand_path('~/.retrospec/repos/retrospec-puppet-templates')
67
+ scm_url = ENV['RETROSPEC_PUPPET_SCM_URL'] || plugin_config['plugins::puppet::templates::url']
68
+ scm_branch = ENV['RETROSPEC_PUPPET_SCM_BRANCH'] || plugin_config['plugins::puppet::templates::ref'] || 'master'
69
+ future_parser = plugin_config['plugins::puppet::enable_future_parser'] || false
70
+ beaker_tests = plugin_config['plugins::puppet::enable_beaker_tests'] || false
71
+ namespace = plugin_config['plugins::puppet::namespace'] || 'namespace'
72
+ # a list of subcommands for this plugin
73
+ sub_commands = [:new_module]
74
+ if sub_commands.count > 0
75
+ sub_command_help = "Subcommands:\n#{sub_commands.join("\n")}\n"
76
+ else
77
+ sub_command_help = ""
78
+ end
79
+ plugin_opts = Trollop::options do
46
80
  version "#{Retrospec::Puppet::VERSION} (c) Corey Osman"
47
81
  banner <<-EOS
48
- Generates puppet rspec test code based on the classes and defines inside the manifests directory.
82
+ Generates puppet rspec test code based on the classes and defines inside the manifests directory.\n
83
+ #{sub_command_help}
49
84
 
50
85
  EOS
51
86
  opt :template_dir, "Path to templates directory (only for overriding Retrospec templates)", :type => :string,
52
87
  :required => false, :default => template_dir
53
88
  opt :scm_url, "SCM url for retrospec templates", :type => :string, :required => false,
54
89
  :default => scm_url
90
+ opt :name, "The name of the module you wish to create", :type => :string, :require => :false, :short => '-n',
91
+ :default => File.basename(global_opts[:module_path])
55
92
  opt :branch, "Branch you want to use for the retrospec template repo", :type => :string, :required => false,
56
93
  :default => scm_branch
94
+ opt :namespace, "The namespace to use only when creating a new module", :default => namespace, :required => false,
95
+ :type => :string
57
96
  opt :enable_beaker_tests, "Enable the creation of beaker tests", :require => false, :type => :boolean, :default => beaker_tests
58
97
  opt :enable_future_parser, "Enables the future parser only during validation", :default => future_parser, :require => false, :type => :boolean
98
+ stop_on sub_commands
99
+ end
100
+ # the passed in options will always override the config file
101
+ plugin_data = plugin_opts.merge(global_config).merge(global_opts).merge(plugin_opts)
102
+ # define the default action to use the plugin here, the default is run
103
+ sub_command = (args.shift || :run).to_sym
104
+ # create an instance of this plugin
105
+ plugin = self.new(plugin_data[:module_path],plugin_data)
106
+ # check if the plugin supports the sub command
107
+ if plugin.respond_to?(sub_command)
108
+ case sub_command
109
+ when :new_module
110
+ plugin.send(sub_command)
111
+ plugin.post_init # finish initialization
112
+ when :run
113
+ plugin.post_init # finish initialization
114
+ else
115
+ plugin.post_init # finish initialization
116
+ plugin.send(sub_command)
117
+ end
118
+ plugin.send(:run)
119
+ else
120
+ puts "The subcommand #{sub_command} is not supported or valid"
121
+ exit 1
59
122
  end
60
123
  end
61
124
 
@@ -105,6 +168,7 @@ Generates puppet rspec test code based on the classes and defines inside the man
105
168
  def create_files
106
169
  types = context.types
107
170
  safe_create_module_files
171
+ generate_metadata_file
108
172
  # a Type is nothing more than a defined type or puppet class
109
173
  # we could have named this manifest but there could be multiple types
110
174
  # in a manifest.
@@ -239,17 +303,41 @@ Generates puppet rspec test code based on the classes and defines inside the man
239
303
  '.pp'
240
304
  end
241
305
 
242
- # # validates module directory fits the description of this plugin
243
- # def self.validate_type(dir)
244
- # if ! File.exist?(manifest_dir)
245
- # message = "No manifest directory in #{manifest_dir}, cannot validate this is a module".fatal
246
- # raise TypeValidationException message
247
- # else
248
- # manifest_files ||= Dir.glob("#{manifest_dir}/**/*.pp")
249
- # warn "No puppet manifest files found at #{manifest_dir}".warning if manifest_files.length < 1
250
- # end
251
- # true
252
- # end
306
+ def create_manifest_file(dest, content)
307
+ # replace the name in the target file with the module_name from this class
308
+ # I would have just used a template but the context does not exist yet
309
+ new_content = content.gsub('CLASS_NAME', config_data[:name])
310
+ safe_create_file(dest, new_content)
311
+ end
312
+
313
+ # generates the metadata file in the module directory
314
+ def generate_metadata_file
315
+ require 'puppet/module_tool/metadata'
316
+ # make sure the metadata file exists
317
+ metadata_file = File.join(module_path, 'metadata.json')
318
+ unless File.exists?(metadata_file)
319
+ # by default the module tool metadata checks for a namespece
320
+ if ! config_data[:name].include?('-')
321
+ name = "#{config_data[:namespace]}-#{config_data[:name]}"
322
+ else
323
+ name = config_data[:name]
324
+ end
325
+ begin
326
+ metadata = ::Puppet::ModuleTool::Metadata.new.update(
327
+ 'name' => name,
328
+ 'version' => '0.1.0',
329
+ 'author' => (config_data['plugins::puppet::author'] || nil ),
330
+ 'dependencies' => [
331
+ { 'name' => 'puppetlabs-stdlib', 'version_requirement' => '>= 1.0.0' }
332
+ ]
333
+ )
334
+ rescue ArgumentError => e
335
+ puts e.message
336
+ exit -1
337
+ end
338
+ safe_create_file(metadata_file, metadata.to_json)
339
+ end
340
+ end
253
341
  end
254
342
  end
255
343
  end
@@ -1,5 +1,5 @@
1
1
  module Retrospec
2
2
  module Puppet
3
- VERSION = '0.9.1'
3
+ VERSION = '0.10.0'
4
4
  end
5
5
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "puppet-retrospec"
8
- s.version = "0.9.1"
8
+ s.version = "0.10.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Corey Osman"]
12
- s.date = "2015-09-28"
12
+ s.date = "2015-10-12"
13
13
  s.description = "Retrofits and generates valid puppet rspec test code to existing modules"
14
14
  s.email = "corey@logicminds.biz"
15
15
  s.extra_rdoc_files = [
@@ -46,6 +46,7 @@ Gem::Specification.new do |s|
46
46
  "spec/fixtures/fixture_modules/one_resource_module/manifests/params.pp",
47
47
  "spec/fixtures/fixture_modules/zero_resource_module/manifests/empty_class.pp",
48
48
  "spec/fixtures/fixture_modules/zero_resource_module/manifests/not_a_resource_defination.pp",
49
+ "spec/fixtures/fixture_modules/zero_resource_module/metadata.json",
49
50
  "spec/fixtures/manifests/includes-class.pp",
50
51
  "spec/fixtures/manifests/includes-defines.pp",
51
52
  "spec/fixtures/modules/concat/CHANGELOG.md",
@@ -1821,7 +1822,7 @@ Gem::Specification.new do |s|
1821
1822
 
1822
1823
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
1823
1824
  s.add_runtime_dependency(%q<trollop>, [">= 0"])
1824
- s.add_runtime_dependency(%q<retrospec>, ["~> 0.3"])
1825
+ s.add_runtime_dependency(%q<retrospec>, ["~> 0.4.0"])
1825
1826
  s.add_development_dependency(%q<rspec>, ["~> 3.2"])
1826
1827
  s.add_development_dependency(%q<puppet>, ["= 3.7.3"])
1827
1828
  s.add_development_dependency(%q<yard>, ["~> 0.7"])
@@ -1830,12 +1831,9 @@ Gem::Specification.new do |s|
1830
1831
  s.add_development_dependency(%q<jeweler>, [">= 0"])
1831
1832
  s.add_development_dependency(%q<pry>, [">= 0"])
1832
1833
  s.add_development_dependency(%q<fakefs>, [">= 0"])
1833
- s.add_development_dependency(%q<pry-rescue>, [">= 0"])
1834
- s.add_development_dependency(%q<pry-stack_explorer>, [">= 0"])
1835
- s.add_development_dependency(%q<pry-coolline>, [">= 0"])
1836
1834
  else
1837
1835
  s.add_dependency(%q<trollop>, [">= 0"])
1838
- s.add_dependency(%q<retrospec>, ["~> 0.3"])
1836
+ s.add_dependency(%q<retrospec>, ["~> 0.4.0"])
1839
1837
  s.add_dependency(%q<rspec>, ["~> 3.2"])
1840
1838
  s.add_dependency(%q<puppet>, ["= 3.7.3"])
1841
1839
  s.add_dependency(%q<yard>, ["~> 0.7"])
@@ -1844,13 +1842,10 @@ Gem::Specification.new do |s|
1844
1842
  s.add_dependency(%q<jeweler>, [">= 0"])
1845
1843
  s.add_dependency(%q<pry>, [">= 0"])
1846
1844
  s.add_dependency(%q<fakefs>, [">= 0"])
1847
- s.add_dependency(%q<pry-rescue>, [">= 0"])
1848
- s.add_dependency(%q<pry-stack_explorer>, [">= 0"])
1849
- s.add_dependency(%q<pry-coolline>, [">= 0"])
1850
1845
  end
1851
1846
  else
1852
1847
  s.add_dependency(%q<trollop>, [">= 0"])
1853
- s.add_dependency(%q<retrospec>, ["~> 0.3"])
1848
+ s.add_dependency(%q<retrospec>, ["~> 0.4.0"])
1854
1849
  s.add_dependency(%q<rspec>, ["~> 3.2"])
1855
1850
  s.add_dependency(%q<puppet>, ["= 3.7.3"])
1856
1851
  s.add_dependency(%q<yard>, ["~> 0.7"])
@@ -1859,9 +1854,6 @@ Gem::Specification.new do |s|
1859
1854
  s.add_dependency(%q<jeweler>, [">= 0"])
1860
1855
  s.add_dependency(%q<pry>, [">= 0"])
1861
1856
  s.add_dependency(%q<fakefs>, [">= 0"])
1862
- s.add_dependency(%q<pry-rescue>, [">= 0"])
1863
- s.add_dependency(%q<pry-stack_explorer>, [">= 0"])
1864
- s.add_dependency(%q<pry-coolline>, [">= 0"])
1865
1857
  end
1866
1858
  end
1867
1859
 
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "name-test123",
3
+ "version": "0.1.0",
4
+ "author": "name",
5
+ "summary": null,
6
+ "license": "Apache 2.0",
7
+ "source": "",
8
+ "project_page": null,
9
+ "issues_url": null,
10
+ "dependencies": [
11
+ {"name":"puppetlabs-stdlib","version_requirement":">= 1.0.0"}
12
+ ]
13
+ }
@@ -6,16 +6,25 @@ describe "puppet" do
6
6
  Retrospec::Plugins::V1::Puppet.new('/tmp/testplugin_dir', {:name => 'testplugin', :config1 => 'test'})
7
7
  end
8
8
 
9
- it 'can show the version' do
10
- expect(Retrospec::Puppet::VERSION).to eq('0.9.0')
9
+ let(:global_opts) do
10
+ {:module_path => '/tmp/testplugin_dir'}
11
11
  end
12
12
 
13
- it 'can get cli options' do
14
- expect(Retrospec::Plugins::V1::Puppet.cli_options({})[:enable_future_parser]).to be false
13
+ before :each do
14
+ FileUtils.rm_rf('/tmp/testplugin_dir')
15
15
  end
16
16
 
17
+ it 'can show the version' do
18
+ expect(Retrospec::Puppet::VERSION).to eq('0.10.0')
19
+ end
20
+
21
+ # disabling for now until we can stub gets
22
+ xit 'can run cli and create new module' do
23
+ expect(Retrospec::Plugins::V1::Puppet.run_cli(global_opts, {},{}, ['new_module'])).to eq(nil)
24
+ end
17
25
 
18
- it 'can get cli options' do
19
- expect(Retrospec::Plugins::V1::Puppet.cli_options({'plugins::puppet::enable_future_parser' => true})[:enable_future_parser]).to be true
26
+ xit 'can run cli' do
27
+ Retrospec::Plugins::V1::Puppet.run_cli(global_opts, {},{}, ['new_module'])
28
+ expect(Retrospec::Plugins::V1::Puppet.run_cli(global_opts, {},{}, [])).to eq(nil)
20
29
  end
21
30
  end
@@ -7,6 +7,30 @@ describe "puppet-retrospec" do
7
7
  FileUtils.rm_rf(fixture_modules_path) if ENV['RETROSPEC_CLEAN_UP_TEST_MODULES'] =~ /true/
8
8
  end
9
9
 
10
+ let(:global_config) do
11
+ {'author' => 'Corey Osman'}
12
+ end
13
+
14
+ let(:plugin_config) do
15
+ {
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' => '',
23
+ }
24
+ end
25
+
26
+ let(:global_opts) do
27
+ {:module_path => File.join(fixture_modules_path, 'tomcat')}
28
+ end
29
+
30
+ let(:plugin_opts) do
31
+ {}
32
+ end
33
+
10
34
  before :all do
11
35
  #enabling the removal of real modules slows down tests, but from time to time we may need to
12
36
  FileUtils.rm_rf(fixture_modules_path) if ENV['RETROSPEC_CLEAN_UP_TEST_MODULES'] =~ /true/
@@ -16,7 +40,7 @@ describe "puppet-retrospec" do
16
40
 
17
41
  before :each do
18
42
  clean_up_spec_dir(@path)
19
- @opts = {:module_path => @path, :enable_beaker_tests => false,
43
+ @opts = {:module_path => @path, :enable_beaker_tests => false, :name => 'name-test123',
20
44
  :enable_user_templates => false, :template_dir => '/tmp/.retrospec_templates' }
21
45
  end
22
46
 
@@ -29,11 +53,31 @@ describe "puppet-retrospec" do
29
53
  opts = {:module_path => @path, :enable_beaker_tests => false,
30
54
  :enable_user_templates => false, :template_dir => nil, :enable_future_parser => true }
31
55
  tomcat = Retrospec::Plugins::V1::Puppet.new(opts[:module_path], opts)
56
+ tomcat.post_init
32
57
  expect(tomcat.context.instance.future_parser).to eq(true)
33
58
  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', :template_dir => nil, :enable_future_parser => true }
67
+ new_module = Retrospec::Plugins::V1::Puppet.new(opts[:module_path], opts)
68
+ allow(new_module).to receive(:gets).and_return("y\n")
69
+ new_module.new_module
70
+ new_module.post_init
71
+ new_module.run
72
+ expect(File.exists?(File.join(new_module.manifest_dir, 'init.pp'))).to eq(true)
73
+ expect(File.exists?(File.join(new_module.module_path, 'metadata.json'))).to eq(true)
74
+ expect(JSON.parse(File.read(File.join(new_module.module_path, 'metadata.json')))['author']).to eq('test_name')
75
+ end
76
+ end
34
77
 
35
78
  it 'should create files without error' do
36
79
  tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], @opts)
80
+ tomcat.post_init
37
81
  tomcat.create_files
38
82
  expect(File.exists?(File.join(@path, 'Gemfile'))).to eq(true)
39
83
  expect(File.exists?(File.join(@path, 'Rakefile'))).to eq(true)
@@ -47,6 +91,7 @@ describe "puppet-retrospec" do
47
91
  it 'should create acceptance test files' do
48
92
  @opts[:enable_beaker_tests] = true
49
93
  tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], @opts)
94
+ tomcat.post_init
50
95
  spec_path = File.expand_path(File.join(@path, 'spec'))
51
96
  tomcat.create_files
52
97
  expect(File.exists?(File.join(spec_path, 'spec_helper_acceptance.rb'))).to eq(true)
@@ -61,6 +106,7 @@ describe "puppet-retrospec" do
61
106
  clean_up_spec_dir(@path)
62
107
  @opts[:enable_beaker_tests] = false
63
108
  tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], @opts)
109
+ tomcat.post_init
64
110
  spec_path = File.expand_path(File.join(@path, 'spec'))
65
111
  tomcat.create_files
66
112
  expect(File.exists?(File.join(spec_path, 'spec_helper_acceptance.rb'))).to eq(false)
@@ -72,6 +118,7 @@ describe "puppet-retrospec" do
72
118
 
73
119
  it 'should create proper spec helper file' do
74
120
  tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], @opts)
121
+ tomcat.post_init
75
122
  filepath = File.expand_path(File.join(@path, 'spec', 'spec_helper.rb'))
76
123
  tomcat.safe_create_module_files
77
124
  path = tomcat.module_path
@@ -80,6 +127,7 @@ describe "puppet-retrospec" do
80
127
 
81
128
  it 'should create proper shared context file' do
82
129
  tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], @opts)
130
+ tomcat.post_init
83
131
  filepath = File.expand_path(File.join(@path, 'spec', 'shared_contexts.rb'))
84
132
  tomcat.safe_create_module_files
85
133
  expect(File.exists?(filepath)).to eq(true)
@@ -87,6 +135,7 @@ describe "puppet-retrospec" do
87
135
 
88
136
  it 'should produce hiera data' do
89
137
  tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], @opts)
138
+ tomcat.post_init
90
139
  filepath = File.expand_path(File.join(@path, 'spec', 'shared_contexts.rb'))
91
140
  tomcat.safe_create_module_files
92
141
  path = tomcat.module_path
@@ -107,6 +156,7 @@ describe "puppet-retrospec" do
107
156
  opts = {:module_path => @path, :enable_beaker_tests => true,
108
157
  :template_dir => '/tmp/my_templates' }
109
158
  tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], opts)
159
+ tomcat.post_init
110
160
  filepath = File.expand_path(File.join(@path, 'spec', 'spec_helper_acceptance.rb'))
111
161
  tomcat.safe_create_module_files
112
162
  expect(File.exists?(filepath)).to eq(true)
@@ -117,6 +167,7 @@ describe "puppet-retrospec" do
117
167
  :template_dir => '/tmp/my_templates' }
118
168
  filepath = File.expand_path(File.join(@path, 'spec', 'spec_helper_acceptance.rb'))
119
169
  tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], opts)
170
+ tomcat.post_init
120
171
  tomcat.safe_create_module_files
121
172
  expect(File.exists?(filepath)).to eq(false)
122
173
  end
@@ -125,6 +176,7 @@ describe "puppet-retrospec" do
125
176
  opts = {:module_path => @path, :enable_beaker_tests => true,
126
177
  :template_dir => '/tmp/my_templates' }
127
178
  tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], opts)
179
+ tomcat.post_init
128
180
  filepath = File.expand_path(File.join(@path, 'spec', 'acceptance', 'nodesets', 'default.yml'))
129
181
  tomcat.safe_create_module_files
130
182
  expect(File.exists?(filepath)).to eq(true)
@@ -133,6 +185,7 @@ describe "puppet-retrospec" do
133
185
 
134
186
  it 'should create Gemfile file' do
135
187
  tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], @opts)
188
+ tomcat.post_init
136
189
  filepath = File.expand_path(File.join(@path, 'Gemfile'))
137
190
  tomcat.safe_create_module_files
138
191
  expect(File.exists?(filepath)).to eq(true)
@@ -140,6 +193,7 @@ describe "puppet-retrospec" do
140
193
 
141
194
  it 'should create Rakefile file' do
142
195
  tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], @opts)
196
+ tomcat.post_init
143
197
  filepath = File.expand_path(File.join(@path, 'Rakefile'))
144
198
  tomcat.safe_create_module_files
145
199
  expect(File.exists?(filepath)).to eq(true)
@@ -149,18 +203,20 @@ describe "puppet-retrospec" do
149
203
  filepath = File.expand_path(File.join(@path,'.fixtures.yml'))
150
204
  FileUtils.rm_f(filepath) # ensure we have a clean state
151
205
  tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], @opts)
206
+ tomcat.post_init
152
207
  tomcat.safe_create_module_files
153
208
  expect(File.exists?(filepath)).to eq(true)
154
209
  end
155
210
 
156
211
  it 'should not create any files when 0 resources exists' do
157
212
  my_path = File.expand_path(File.join('spec', 'fixtures', 'fixture_modules', 'zero_resource_module'))
158
- my_retro = Retrospec::Plugins::V1::Puppet.new(my_path)
213
+ my_retro = Retrospec::Plugins::V1::Puppet.new(my_path, @opts)
159
214
  my_retro.should_not_receive(:safe_create_file).with(anything,'resource_spec_file.erb')
160
215
  end
161
216
 
162
217
  it 'should create a file from a template' do
163
218
  tomcat = Retrospec::Plugins::V1::Puppet.new(@opts[:module_path], @opts)
219
+ tomcat.post_init
164
220
  file_path = File.join(@path,'.fixtures.yml')
165
221
  template_file = File.join(tomcat.template_dir,'module_files','.fixtures.yml.retrospec.erb')
166
222
  tomcat.safe_create_template_file(file_path, template_file, tomcat.context)
@@ -220,4 +276,5 @@ describe "puppet-retrospec" do
220
276
  expect(tomcat.generate_file_name('tomcat')).to eq('tomcat_spec.rb')
221
277
  expect(tomcat.generate_file_name('tomcat::config')).to eq('config_spec.rb')
222
278
  end
279
+
223
280
  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.9.1
4
+ version: 0.10.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: 2015-09-28 00:00:00.000000000 Z
11
+ date: 2015-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trollop
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: '0.3'
33
+ version: 0.4.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: '0.3'
40
+ version: 0.4.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -150,48 +150,6 @@ dependencies:
150
150
  - - '>='
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
- - !ruby/object:Gem::Dependency
154
- name: pry-rescue
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - '>='
158
- - !ruby/object:Gem::Version
159
- version: '0'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - '>='
165
- - !ruby/object:Gem::Version
166
- version: '0'
167
- - !ruby/object:Gem::Dependency
168
- name: pry-stack_explorer
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - '>='
172
- - !ruby/object:Gem::Version
173
- version: '0'
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - '>='
179
- - !ruby/object:Gem::Version
180
- version: '0'
181
- - !ruby/object:Gem::Dependency
182
- name: pry-coolline
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - '>='
186
- - !ruby/object:Gem::Version
187
- version: '0'
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - '>='
193
- - !ruby/object:Gem::Version
194
- version: '0'
195
153
  description: Retrofits and generates valid puppet rspec test code to existing modules
196
154
  email: corey@logicminds.biz
197
155
  executables: []
@@ -229,6 +187,7 @@ files:
229
187
  - spec/fixtures/fixture_modules/one_resource_module/manifests/params.pp
230
188
  - spec/fixtures/fixture_modules/zero_resource_module/manifests/empty_class.pp
231
189
  - spec/fixtures/fixture_modules/zero_resource_module/manifests/not_a_resource_defination.pp
190
+ - spec/fixtures/fixture_modules/zero_resource_module/metadata.json
232
191
  - spec/fixtures/manifests/includes-class.pp
233
192
  - spec/fixtures/manifests/includes-defines.pp
234
193
  - spec/fixtures/modules/concat/CHANGELOG.md