Browse Source

Merge pull request #39 from branan/use_spechelper_gem

Switch to using the puppetlabs_spec_helper gem for common files instead
Nan Liu 7 years ago
parent
commit
68606f6773
4 changed files with 4 additions and 123 deletions
  1. 1
    8
      .gemfile
  2. 1
    1
      .travis.yml
  3. 1
    91
      Rakefile
  4. 1
    23
      spec/spec_helper.rb

+ 1
- 8
.gemfile View File

@@ -1,12 +1,5 @@
1 1
 source :rubygems
2 2
 
3 3
 puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 2.7']
4
-
5 4
 gem 'puppet', puppetversion
6
-
7
-group :test do
8
-  gem 'rake', '>= 0.9.0'
9
-  gem 'rspec', '>= 2.8.0'
10
-  gem 'rspec-puppet', '>= 0.1.1'
11
-  gem 'mocha', '>= 0.11.0'
12
-end
5
+gem 'puppetlabs_spec_helper', '>= 0.1.0'

+ 1
- 1
.travis.yml View File

@@ -3,7 +3,7 @@ rvm:
3 3
   - 1.8.7
4 4
 before_script:
5 5
 after_script:
6
-script: "rake spec_full"
6
+script: "rake spec"
7 7
 branches:
8 8
   only:
9 9
     - master

+ 1
- 91
Rakefile View File

@@ -1,91 +1 @@
1
-require 'rake'
2
-require 'rspec/core/rake_task'
3
-require 'yaml'
4
-
5
-task :default => [:spec]
6
-
7
-desc "Run all module spec tests (Requires rspec-puppet gem)"
8
-RSpec::Core::RakeTask.new(:spec) do |t|
9
-  t.rspec_opts = ['--color']
10
-  t.pattern = 'spec/{classes,defines,unit}/**/*_spec.rb'
11
-end
12
-
13
-# This is a helper for the self-symlink entry of fixtures.yml
14
-def source_dir
15
-  File.dirname(__FILE__)
16
-end
17
-
18
-def fixtures(category)
19
-  begin
20
-    fixtures = YAML.load_file(".fixtures.yml")["fixtures"]
21
-  rescue Errno::ENOENT
22
-    return {}
23
-  end
24
-
25
-  if not fixtures
26
-    abort("malformed fixtures.yml")
27
-  end
28
-
29
-  result = {}
30
-  if fixtures.include? category
31
-    fixtures[category].each do |fixture, source|
32
-      target = "spec/fixtures/modules/#{fixture}"
33
-      real_source = eval('"'+source+'"')
34
-      result[real_source] = target
35
-    end
36
-  end
37
-  return result
38
-end
39
-
40
-desc "Create the fixtures directory"
41
-task :spec_prep do
42
-  fixtures("repositories").each do |repo, target|
43
-    File::exists?(target) || system("git clone #{repo} #{target}")
44
-  end
45
-
46
-  FileUtils::mkdir_p("spec/fixtures/modules")
47
-  fixtures("symlinks").each do |source, target|
48
-    File::exists?(target) || FileUtils::ln_s(source, target)
49
-  end
50
-end
51
-
52
-desc "Clean up the fixtures directory"
53
-task :spec_clean do
54
-  fixtures("repositories").each do |repo, target|
55
-    FileUtils::rm_rf(target)
56
-  end
57
-
58
-  fixtures("symlinks").each do |source, target|
59
-    FileUtils::rm(target)
60
-  end
61
-end
62
-
63
-task :spec_full do
64
-  Rake::Task[:spec_prep].invoke
65
-  Rake::Task[:spec].invoke
66
-  Rake::Task[:spec_clean].invoke
67
-end
68
-
69
-desc "Build puppet module package"
70
-task :build do
71
-  # This will be deprecated once puppet-module is a face.
72
-  begin
73
-    Gem::Specification.find_by_name('puppet-module')
74
-  rescue Gem::LoadError, NoMethodError
75
-    require 'puppet/face'
76
-    pmod = Puppet::Face['module', :current]
77
-    pmod.build('./')
78
-  end
79
-end
80
-
81
-desc "Clean a built module package"
82
-task :clean do
83
-  FileUtils.rm_rf("pkg/")
84
-end
85
-
86
-desc "Check puppet manifests with puppet-lint"
87
-task :lint do
88
-  # This requires pull request: https://github.com/rodjek/puppet-lint/pull/81
89
-  system("puppet-lint manifests")
90
-  system("puppet-lint tests")
91
-end
1
+require 'puppetlabs_spec_helper/rake_tasks'

+ 1
- 23
spec/spec_helper.rb View File

@@ -1,23 +1 @@
1
-require 'rubygems'
2
-require 'puppet'
3
-require 'rspec-puppet'
4
-
5
-def param_value(subject, type, title, param)
6
-  subject.resource(type, title).send(:parameters)[param.to_sym]
7
-end
8
-
9
-def verify_contents(subject, title, expected_lines)
10
-  content = subject.resource('file', title).send(:parameters)[:content]
11
-  (content.split("\n") & expected_lines).should == expected_lines
12
-end
13
-
14
-Puppet.parse_config
15
-puppet_module_path = Puppet[:modulepath]
16
-
17
-fixture_path = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures'))
18
-
19
-RSpec.configure do |c|
20
-  fixture_module_path = File.join(fixture_path, 'modules')
21
-  c.module_path = [fixture_module_path, puppet_module_path].join(":")
22
-  c.manifest_dir = File.join(fixture_path, 'manifests')
23
-end
1
+require 'puppetlabs_spec_helper/module_spec_helper'

Loading…
Cancel
Save