Skip to content

Commit

Permalink
Use rspec shared examples to reduce duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
ekohl authored and domcleal committed Jan 16, 2017
1 parent a787cf4 commit 005ffdf
Show file tree
Hide file tree
Showing 22 changed files with 31 additions and 137 deletions.
2 changes: 2 additions & 0 deletions .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ spec/spec_helper.rb:
def static_fixture_path
File.join(File.dirname(__FILE__), 'static_fixtures')
end
Dir["./spec/support/**/*.rb"].sort.each { |f| require f }
8 changes: 1 addition & 7 deletions spec/classes/plugin/abrt_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
require 'spec_helper'

describe 'foreman::plugin::abrt' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman' }

it { should contain_foreman__plugin('abrt') }
include_examples 'basic foreman plugin tests', 'abrt'
end
8 changes: 1 addition & 7 deletions spec/classes/plugin/ansible_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
require 'spec_helper'

describe 'foreman::plugin::ansible' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman' }

it { should contain_foreman__plugin('ansible') }
include_examples 'basic foreman plugin tests', 'ansible'
it { should contain_foreman__plugin('tasks') }
end
8 changes: 1 addition & 7 deletions spec/classes/plugin/azure_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
require 'spec_helper'

describe 'foreman::plugin::azure' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman' }

it { should contain_foreman__plugin('azure') }
include_examples 'basic foreman plugin tests', 'azure'
end
8 changes: 1 addition & 7 deletions spec/classes/plugin/bootdisk_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
require 'spec_helper'

describe 'foreman::plugin::bootdisk' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman' }

it { should contain_foreman__plugin('bootdisk') }
include_examples 'basic foreman plugin tests', 'bootdisk'
end
8 changes: 1 addition & 7 deletions spec/classes/plugin/chef_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
require 'spec_helper'

describe 'foreman::plugin::chef' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman' }

it { should contain_foreman__plugin('chef') }
include_examples 'basic foreman plugin tests', 'chef'
it { should contain_foreman__plugin('tasks') }
end
8 changes: 1 addition & 7 deletions spec/classes/plugin/cockpit_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
require 'spec_helper'

describe 'foreman::plugin::cockpit' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman' }

it { should contain_foreman__plugin('cockpit') }
include_examples 'basic foreman plugin tests', 'cockpit'
end
8 changes: 1 addition & 7 deletions spec/classes/plugin/default_hostgroup_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
require 'spec_helper'

describe 'foreman::plugin::default_hostgroup' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman' }

it { should contain_foreman__plugin('default_hostgroup') }
include_examples 'basic foreman plugin tests', 'default_hostgroup'
end
8 changes: 1 addition & 7 deletions spec/classes/plugin/dhcp_browser_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
require 'spec_helper'

describe 'foreman::plugin::dhcp_browser' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman' }

it { should contain_foreman__plugin('dhcp_browser') }
include_examples 'basic foreman plugin tests', 'dhcp_browser'
end
8 changes: 1 addition & 7 deletions spec/classes/plugin/digitalocean_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
require 'spec_helper'

describe 'foreman::plugin::digitalocean' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman' }

it { should contain_foreman__plugin('digitalocean') }
include_examples 'basic foreman plugin tests', 'digitalocean'
end
8 changes: 1 addition & 7 deletions spec/classes/plugin/docker_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
require 'spec_helper'

describe 'foreman::plugin::docker' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman' }

it { should contain_foreman__plugin('docker') }
include_examples 'basic foreman plugin tests', 'docker'
end
8 changes: 1 addition & 7 deletions spec/classes/plugin/expire_hosts_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
require 'spec_helper'

describe 'foreman::plugin::expire_hosts' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman' }

it { should contain_foreman__plugin('expire_hosts') }
include_examples 'basic foreman plugin tests', 'expire_hosts'
end
8 changes: 1 addition & 7 deletions spec/classes/plugin/hooks_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
require 'spec_helper'

describe 'foreman::plugin::hooks' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman' }

it { should contain_foreman__plugin('hooks') }
include_examples 'basic foreman plugin tests', 'hooks'
end
8 changes: 1 addition & 7 deletions spec/classes/plugin/host_extra_validator_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
require 'spec_helper'

describe 'foreman::plugin::host_extra_validator' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman' }

it { should contain_foreman__plugin('host_extra_validator') }
include_examples 'basic foreman plugin tests', 'host_extra_validator'
end
10 changes: 1 addition & 9 deletions spec/classes/plugin/memcache_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
require 'spec_helper'

describe 'foreman::plugin::memcache' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman' }

it 'should call the plugin' do
should contain_foreman__plugin('memcache')
end
include_examples 'basic foreman plugin tests', 'memcache'
end
8 changes: 1 addition & 7 deletions spec/classes/plugin/monitoring_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
require 'spec_helper'

describe 'foreman::plugin::monitoring' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman' }

it { should contain_foreman__plugin('monitoring') }
include_examples 'basic foreman plugin tests', 'monitoring'
end
8 changes: 1 addition & 7 deletions spec/classes/plugin/omaha_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
require 'spec_helper'

describe 'foreman::plugin::omaha' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman' }

it { should contain_foreman__plugin('omaha') }
include_examples 'basic foreman plugin tests', 'omaha'
end
8 changes: 1 addition & 7 deletions spec/classes/plugin/salt_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
require 'spec_helper'

describe 'foreman::plugin::salt' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman' }

it { should contain_foreman__plugin('salt') }
include_examples 'basic foreman plugin tests', 'salt'
it { should contain_foreman__plugin('tasks') }
end
8 changes: 1 addition & 7 deletions spec/classes/plugin/setup_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
require 'spec_helper'

describe 'foreman::plugin::setup' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman' }

it { should contain_foreman__plugin('setup') }
include_examples 'basic foreman plugin tests', 'setup'
end
10 changes: 1 addition & 9 deletions spec/classes/plugin/templates_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
require 'spec_helper'

describe 'foreman::plugin::templates' do
let(:facts) do
on_supported_os['redhat-7-x86_64']
end

let(:pre_condition) { 'include foreman' }

it 'should call the plugin' do
should contain_foreman__plugin('templates')
end
include_examples 'basic foreman plugin tests', 'templates'
end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,5 @@ def verify_concat_fragment_exact_contents(subject, title, expected_lines)
def static_fixture_path
File.join(File.dirname(__FILE__), 'static_fixtures')
end

Dir["./spec/support/**/*.rb"].sort.each { |f| require f }
8 changes: 8 additions & 0 deletions spec/support/plugin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DEFAULT_OS_FACTS = on_supported_os['redhat-7-x86_64']

shared_examples 'basic foreman plugin tests' do |name|
let(:facts) { DEFAULT_OS_FACTS }
let(:pre_condition) { 'include foreman' }
it { should compile.with_all_deps }
it { should contain_foreman__plugin(name) }
end

0 comments on commit 005ffdf

Please sign in to comment.