Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various improvements to the spec_helper #505

Merged
merged 6 commits into from
Oct 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config_defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Gemfile:
- gem: puppetlabs_spec_helper
version: '>= 2.11.0'
- gem: rspec-puppet-facts
version: '>= 1.8.0'
- gem: rspec-puppet-utils
- gem: puppet-lint-leading_zero-check
- gem: puppet-lint-trailing_comma-check
Expand Down
4 changes: 0 additions & 4 deletions moduleroot/spec/classes/coverage_spec.rb.erb

This file was deleted.

1 change: 0 additions & 1 deletion moduleroot/spec/default_facts.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# Hint if using with rspec-puppet-facts ("on_supported_os.each"):
# if a same named fact exists in facterdb it will be overridden.
---
concat_basedir: "/tmp"
ipaddress: "172.16.254.254"
is_pe: false
macaddress: "AA:AA:AA:AA:AA:AA"
29 changes: 16 additions & 13 deletions moduleroot/spec/spec_helper.rb.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
require 'puppetlabs_spec_helper/module_spec_helper'
require 'rspec-puppet-facts'
include RspecPuppetFacts

# This file is managed via modulesync
# https://github.com/voxpupuli/modulesync
# https://github.com/voxpupuli/modulesync_config
<%- if @configs['mock_with'] -%>
RSpec.configure do |c|
c.mock_with <%= @configs['mock_with'] %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this block is now duplicate. We probably can remove the other one. This need to be tested within one module

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just verified this on puppet-mongodb (in my local branch) that the later one is indeed redundant and it must be done here at the top.

end

<%- end -%>
require 'puppetlabs_spec_helper/module_spec_helper'
require 'rspec-puppet-facts'
include RspecPuppetFacts

<% if @configs['augeasproviders'] -%>
# Setup augeasproviders
Expand Down Expand Up @@ -37,22 +42,20 @@ if Dir.exist?(File.expand_path('../../lib', __FILE__))
end

RSpec.configure do |c|
default_facts = {
puppetversion: Puppet.version,
facterversion: Facter.version
}
default_facts = {}
default_facts.merge!(YAML.load(File.read(File.expand_path('../default_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_facts.yml', __FILE__))
default_facts.merge!(YAML.load(File.read(File.expand_path('../default_module_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_module_facts.yml', __FILE__))
c.default_facts = default_facts
<%- if @configs['mock_with'] -%>
c.mock_with <%= @configs['mock_with'] %>
<%- end -%>
<%- if @configs['hiera_config'] -%>
c.hiera_config = <%= @configs['hiera_config'] %>
<%- end -%>
end

# Coverage generation
c.after(:suite) do
RSpec::Puppet::Coverage.report!
end
end
<%- [@configs['spec_overrides']].flatten.compact.each do |line| -%>

<%= line %>
<%- end -%>
# vim: syntax=ruby