Add rspec skeleton
authorvarac <varacanero@zeromail.org>
Thu, 3 Nov 2016 00:13:30 +0000 (01:13 +0100)
committervarac <varacanero@zeromail.org>
Thu, 3 Nov 2016 00:22:17 +0000 (01:22 +0100)
.fixtures.yml [new file with mode: 0644]
.gitignore [new file with mode: 0644]
.gitlab-ci.yml [new file with mode: 0644]
Gemfile [new file with mode: 0644]
Rakefile [new file with mode: 0644]
spec/classes/module_dir_spec.rb [new file with mode: 0644]
spec/spec_helper.rb

diff --git a/.fixtures.yml b/.fixtures.yml
new file mode 100644 (file)
index 0000000..58545a5
--- /dev/null
@@ -0,0 +1,3 @@
+fixtures:
+  symlinks:
+    "common": "#{source_dir}"
diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..ad8ff1f
--- /dev/null
@@ -0,0 +1,10 @@
+/pkg/
+/Gemfile.lock
+/vendor/
+/spec/fixtures
+/log
+/.vagrant/
+/.bundle/
+/coverage/
+/.idea/
+*.iml
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644 (file)
index 0000000..79108a0
--- /dev/null
@@ -0,0 +1,48 @@
+image: leapcode/ruby
+before_script:
+  - "[ -d /var/cache/gitlab-runner ] || sudo mkdir /var/cache/gitlab-runner"
+  - sudo chown cirunner:cirunner -R /var/cache/gitlab-runner
+  - bundle install --jobs $(nproc) --without system_tests --path=/var/cache/gitlab-runner/ "${FLAGS[@]}"
+
+.job_template: &job_definition
+  script:
+    # don't fail on lint warnings
+    - bundle exec rake lint || /bin/true
+    - bundle exec rake syntax
+    - bundle exec rake validate
+    - bundle exec rake spec
+
+# Default debian jessie versions
+test:puppet37:
+  variables:
+    PUPPET_VERSION: "~> 3.7.2"
+    FACTER_VERSION: '~> 2.2.0'
+  <<: *job_definition
+
+test:puppet38_future_parser:
+  variables:
+    PUPPET_VERSION: '~> 3.8'
+    FACTER_VERSION: '~> 2.2.0'
+    FUTURE_PARSER:  'yes'
+  <<: *job_definition
+
+test:puppet40:
+  variables:
+    PUPPET_VERSION: "~> 4.0.0"
+    FACTER_VERSION: '~> 2.4.0'
+  <<: *job_definition
+
+# Default debia stretch versions
+test:puppet45:
+  variables:
+    PUPPET_VERSION: "~> 4.5.2"
+    FACTER_VERSION: '~> 2.4.6'
+  <<: *job_definition
+
+# Latest greatest
+test:puppet4x:
+  variables:
+    PUPPET_VERSION: "> 4"
+    FACTER_VERSION: '> 2'
+  <<: *job_definition
+
diff --git a/Gemfile b/Gemfile
new file mode 100644 (file)
index 0000000..44630f4
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,22 @@
+source "https://rubygems.org"
+
+group :development, :unit_tests do
+  gem "rake"
+  gem "rspec-puppet", "~> 2.1", :require => false
+  gem "rspec-core", "3.1.7",    :require => false
+  gem "puppetlabs_spec_helper"
+  gem "metadata-json-lint"
+  gem "rspec-puppet-facts"
+  gem "mocha"
+end
+
+group :system_tests do
+  gem 'beaker'
+  gem 'beaker-rspec'
+  gem 'beaker_spec_helper'
+  gem 'serverspec'
+end
+
+gem "puppet", ENV['PUPPET_VERSION'] || ENV['GEM_PUPPET_VERSION'] || ENV['PUPPET_GEM_VERSION'] || '~> 3.7.0'
+gem "facter", ENV['FACTER_VERSION'] || ENV['GEM_FACTER_VERSION'] || ENV['FACTER_GEM_VERSION'] || '~> 2.2.0'
+
diff --git a/Rakefile b/Rakefile
new file mode 100644 (file)
index 0000000..85326bb
--- /dev/null
+++ b/Rakefile
@@ -0,0 +1,19 @@
+require 'puppetlabs_spec_helper/rake_tasks'
+require 'puppet-lint/tasks/puppet-lint'
+PuppetLint.configuration.send('disable_80chars')
+PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"]
+
+desc "Validate manifests, templates, and ruby files"
+task :validate do
+  Dir['manifests/**/*.pp'].each do |manifest|
+    sh "puppet parser validate --noop #{manifest}"
+  end
+  Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file|
+    sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/
+  end
+  Dir['templates/**/*.erb'].each do |template|
+    sh "erb -P -x -T '-' #{template} | ruby -c"
+  end
+end
+
+task :test => [:lint, :syntax , :validate, :spec]
diff --git a/spec/classes/module_dir_spec.rb b/spec/classes/module_dir_spec.rb
new file mode 100644 (file)
index 0000000..b33afc2
--- /dev/null
@@ -0,0 +1,17 @@
+require 'spec_helper'
+
+describe 'common::moduledir', :type => :class do
+  let :pre_condition do
+    'class { "common::moduledir": }'
+  end
+  let(:facts) { {
+    :lsbdistid => 'Debian',
+    :osfamily => 'Debian',
+    :operatingsystem => 'Debian',
+    :debian_release  => 'jessie',
+    :debian_codename => 'jessie',
+    :lsbdistcodename => 'jessie',
+    :virtual         => 'physical',
+    :puppetversion   => Puppet.version, } }
+  it { is_expected.to compile.with_all_deps }
+end
index 6ba62e1..3cca63a 100644 (file)
@@ -1,16 +1,12 @@
-require 'pathname'
-dir = Pathname.new(__FILE__).parent
-$LOAD_PATH.unshift(dir, dir + 'lib', dir + '../lib')
-require 'puppet'
-gem 'rspec', '>= 1.2.9'
-require 'spec/autorun'
+# https://puppetlabs.com/blog/testing-modules-in-the-puppet-forge
+require 'puppetlabs_spec_helper/module_spec_helper'
 
-Dir[File.join(File.dirname(__FILE__), 'support', '*.rb')].each do |support_file|
-  require support_file
-end
+fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
+
+RSpec.configure do |c|
+
+  c.manifest_dir = File.join(fixture_path, 'manifests')
+  c.module_path  = File.join(fixture_path, 'modules')
 
-# We need this because the RAL uses 'should' as a method.  This
-# allows us the same behaviour but with a different method name.
-class Object
-    alias :must :should
+  c.color = true
 end