diff --git a/Gemfile b/Gemfile index 902091ae9..513b910ae 100644 --- a/Gemfile +++ b/Gemfile @@ -2,13 +2,12 @@ source 'https://rubygems.org' group :rake do gem 'puppet', '>=3.0.1' - gem 'rspec-puppet', '>=0.1.3' + gem 'rspec-puppet', '>=1.0.1' gem 'rake', '>=0.9.2.2' gem 'puppet-lint', '>=0.1.12' gem 'puppetlabs_spec_helper' gem 'puppet-blacksmith' gem 'librarian-puppet-maestrodev' gem 'rspec-system-puppet', :require => false - gem 'serverspec', '~> 0.11.0', :require => false gem 'rspec-system-serverspec', :require => false end diff --git a/spec/classes/config_spec.rb b/spec/classes/config_spec.rb index ed3e0e0e4..72fe533dc 100644 --- a/spec/classes/config_spec.rb +++ b/spec/classes/config_spec.rb @@ -23,25 +23,27 @@ { :osfamily => facts[:osfamily], :operatingsystem => facts[:operatingsystem], - :kernel => 'linux', } end - it { should include_class("nginx::params") } + it { should contain_class("nginx::params") } - it { should contain_file("/etc/nginx").with( + it { should contain_file("/etc/nginx").only_with( + :path => "/etc/nginx", :ensure => 'directory', :owner => 'root', :group => 'root', :mode => '0644' )} - it { should contain_file("/etc/nginx/conf.d").with( + it { should contain_file("/etc/nginx/conf.d").only_with( + :path => '/etc/nginx/conf.d', :ensure => 'directory', :owner => 'root', :group => 'root', :mode => '0644' )} - it { should contain_file("/etc/nginx/conf.mail.d").with( + it { should contain_file("/etc/nginx/conf.mail.d").only_with( + :path => '/etc/nginx/conf.mail.d', :ensure => 'directory', :owner => 'root', :group => 'root', @@ -104,7 +106,6 @@ { :osfamily => facts[:osfamily], :operatingsystem => facts[:operatingsystem], - :kernel => 'linux', } end it { should contain_file("/var/nginx/client_body_temp").with(:owner => 'www-data')} @@ -134,7 +135,6 @@ { :osfamily => facts[:osfamily], :operatingsystem => facts[:operatingsystem], - :kernel => 'linux', } end it { should contain_file("/var/nginx/client_body_temp").with(:owner => 'nginx')} @@ -150,7 +150,6 @@ { :osfamily => 'debian', :operatingsystem => 'debian', - :kernel => 'linux', } end @@ -196,7 +195,7 @@ :title => 'should not set proxy_cache_path', :attr => 'proxy_cache_path', :value => false, - :notmatch => ' proxy_cache_path /path/to/proxy.cache levels=1 keys_zone=d2:100m max_size=500m inactive=20m;', + :notmatch => / proxy_cache_path \/path\/to\/proxy\.cache levels=1 keys_zone=d2:100m max_size=500m inactive=20m;/, }, { :title => 'should contain ordered appended directives', @@ -215,8 +214,9 @@ it { should contain_file("/etc/nginx/nginx.conf").with_mode('0644') } it param[:title] do verify_contents(subject, "/etc/nginx/nginx.conf", Array(param[:match])) - lines = subject.resource('file', "/etc/nginx/nginx.conf").send(:parameters)[:content].split("\n") - (Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty + Array(param[:notmatch]).each do |item| + should contain_file("/etc/nginx/nginx.conf").without_content(item) + end end end end @@ -264,8 +264,9 @@ it { should contain_file("/etc/nginx/conf.d/proxy.conf").with_mode('0644') } it param[:title] do verify_contents(subject, "/etc/nginx/conf.d/proxy.conf", Array(param[:match])) - lines = subject.resource('file', "/etc/nginx/conf.d/proxy.conf").send(:parameters)[:content].split("\n") - (Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty + Array(param[:notmatch]).each do |item| + should contain_file("/etc/nginx/conf.d/proxy.conf").without_content(item) + end end end end diff --git a/spec/classes/nginx_spec.rb b/spec/classes/nginx_spec.rb index 3f6e7f7c0..edebfbcdc 100644 --- a/spec/classes/nginx_spec.rb +++ b/spec/classes/nginx_spec.rb @@ -9,61 +9,53 @@ } end - context "on a Debian OS" do - let :facts do - { - :kernel => 'linux', - :operatingsystem => 'Debian', - :osfamily => 'Debian', - :lsbdistcodename => 'precise', - :concat_basedir => '/var/lib/puppet/concat', - } - end - - it { should contain_nginx__package } - it { should contain_nginx__config } - it { should contain_nginx__service } - it { should include_class("nginx::params") } + shared_examples "a Linux OS" do + it { should compile.with_all_deps } + it { should contain_class('nginx') } + it { should contain_anchor('nginx::begin') } + it { should contain_nginx__package.that_requires('Anchor[nginx::begin]') } + it { should contain_nginx__config.that_requires('Class[nginx::package]') } + it { should contain_nginx__service.that_subscribes_to('Anchor[nginx::begin]') } + it { should contain_nginx__service.that_subscribes_to('Class[nginx::package]') } + it { should contain_nginx__service.that_subscribes_to('Class[nginx::config]') } + it { should contain_anchor('nginx::end').that_requires('Class[nginx::service]') } + it { should contain_class("nginx::params") } it { should contain_nginx__resource__upstream("upstream1") } it { should contain_nginx__resource__vhost("test2.local") } it { should contain_nginx__resource__location("test2.local") } end - context "on a RedHat OS" do - let :facts do - { - :kernel => 'linux', - :operatingsystem => 'RedHat', - :osfamily => 'RedHat', - :concat_basedir => '/var/lib/puppet/concat', - } + context "Debian OS" do + it_behaves_like "a Linux OS" do + let :facts do + { + :operatingsystem => 'Debian', + :osfamily => 'Debian', + :lsbdistcodename => 'precise', + } + end end - - it { should contain_nginx__package } - it { should contain_nginx__config } - it { should contain_nginx__service } - it { should include_class("nginx::params") } - it { should contain_nginx__resource__upstream("upstream1") } - it { should contain_nginx__resource__vhost("test2.local") } - it { should contain_nginx__resource__location("test2.local") } end - context "on a Suse OS" do - let :facts do - { - :kernel => 'linux', - :operatingsystem => 'SuSE', - :osfamily => 'Suse', - :concat_basedir => '/var/lib/puppet/concat', - } + context "RedHat OS" do + it_behaves_like "a Linux OS" do + let :facts do + { + :operatingsystem => 'RedHat', + :osfamily => 'RedHat', + } + end end + end - it { should contain_nginx__package } - it { should contain_nginx__config } - it { should contain_nginx__service } - it { should include_class("nginx::params") } - it { should contain_nginx__resource__upstream("upstream1") } - it { should contain_nginx__resource__vhost("test2.local") } - it { should contain_nginx__resource__location("test2.local") } + context "Suse OS" do + it_behaves_like "a Linux OS" do + let :facts do + { + :operatingsystem => 'SuSE', + :osfamily => 'Suse', + } + end + end end end diff --git a/spec/classes/package_spec.rb b/spec/classes/package_spec.rb index b8d2924a7..0ff2ec6ce 100644 --- a/spec/classes/package_spec.rb +++ b/spec/classes/package_spec.rb @@ -16,6 +16,8 @@ 'gpgkey' => 'http://nginx.org/keys/nginx_signing.key' )} it { should contain_file('/etc/yum.repos.d/nginx-release.repo') } + it { should contain_anchor('nginx::package::begin').that_comes_before('Class[nginx::package::redhat]') } + it { should contain_anchor('nginx::package::end').that_requires('Class[nginx::package::redhat]') } end context "manage_repo => false" do @@ -35,7 +37,7 @@ end describe 'installs the requested package version' do - let(:facts) {{ :kernel => 'linux', :operatingsystem => 'redhat', :osfamily => 'redhat' }} + let(:facts) {{ :operatingsystem => 'redhat', :osfamily => 'redhat' }} let(:params) {{ :package_ensure => '3.0.0' }} it 'installs 3.0.0 exactly' do @@ -58,6 +60,8 @@ 'key' => '7BD9BF62', 'key_source' => 'http://nginx.org/keys/nginx_signing.key' )} + it { should contain_anchor('nginx::package::begin').that_comes_before('Class[nginx::package::debian]') } + it { should contain_anchor('nginx::package::end').that_requires('Class[nginx::package::debian]') } end context "package_source => 'passenger'" do @@ -104,6 +108,8 @@ ].each do |package| it { should contain_package("#{package}") } end + it { should contain_anchor('nginx::package::begin').that_comes_before('Class[nginx::package::suse]') } + it { should contain_anchor('nginx::package::end').that_requires('Class[nginx::package::suse]') } end @@ -137,6 +143,8 @@ 'gpgkey' => 'http://nginx.org/keys/nginx_signing.key' )} it { should contain_file('/etc/yum.repos.d/nginx-release.repo') } + it { should contain_anchor('nginx::package::begin').that_comes_before('Class[nginx::package::redhat]') } + it { should contain_anchor('nginx::package::end').that_requires('Class[nginx::package::redhat]') } end context 'fedora' do diff --git a/spec/classes/params_spec.rb b/spec/classes/params_spec.rb index dd67d82b8..a813b3a10 100644 --- a/spec/classes/params_spec.rb +++ b/spec/classes/params_spec.rb @@ -5,16 +5,11 @@ let :facts do { :osfamily => 'debian', :operatingsystem => 'debian', - :kernel => 'Linux', } end it { should contain_nginx__params } + it { should have_class_count(1) } #only nginx::params itself + it { should have_resource_count(0) } #params class should never declare resources - # There are 4 resources in this class currently - # there should not be any more resources because it is a params class - # The resources are class[nginx::params], class[main], class[settings], stage[main] - it "Should not contain any resources" do - subject.resources.size.should == 4 - end end end diff --git a/spec/classes/service_spec.rb b/spec/classes/service_spec.rb index 06a40ed97..9e8e7ce1c 100644 --- a/spec/classes/service_spec.rb +++ b/spec/classes/service_spec.rb @@ -4,7 +4,6 @@ let :facts do { :osfamily => 'Debian', :operatingsystem => 'debian', - :kernel => 'Linux', } end let :pre_condition do diff --git a/spec/defines/resource_location_spec.rb b/spec/defines/resource_location_spec.rb index 22a89af47..1eb785b6e 100644 --- a/spec/defines/resource_location_spec.rb +++ b/spec/defines/resource_location_spec.rb @@ -8,8 +8,6 @@ { :osfamily => 'Debian', :operatingsystem => 'debian', - :kernel => 'Linux', - :concat_basedir => '/var/lib/puppet/concat', } end let :pre_condition do @@ -27,8 +25,8 @@ :vhost => 'vhost1', } end - it { should include_class("nginx::params") } - it { should include_class("nginx::config") } + it { should contain_class("nginx::params") } + it { should contain_class("nginx::config") } it { should contain_concat__fragment("vhost1-500-rspec-test").with_content(/location rspec-test/) } it { should_not contain_file('/etc/nginx/fastcgi_params') } it { should_not contain_concat__fragment("vhost1-800-rspec-test-ssl") } @@ -120,7 +118,9 @@ it param[:title] do lines = subject.resource('concat::fragment', "vhost1-500-#{params[:location]}").send(:parameters)[:content].split("\n") (lines & Array(param[:match])).should == Array(param[:match]) - (Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty + Array(param[:notmatch]).each do |item| + should contain_concat__fragment("vhost1-500-#{params[:location]}").without_content(item) + end end end end @@ -181,7 +181,9 @@ it param[:title] do lines = subject.resource('concat::fragment', "vhost1-500-#{params[:location]}").send(:parameters)[:content].split("\n") (lines & Array(param[:match])).should == Array(param[:match]) - (Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty + Array(param[:notmatch]).each do |item| + should contain_concat__fragment("vhost1-500-#{params[:location]}").without_content(item) + end end end end @@ -224,7 +226,9 @@ it param[:title] do lines = subject.resource('concat::fragment', "vhost1-500-#{params[:location]}").send(:parameters)[:content].split("\n") (lines & Array(param[:match])).should == Array(param[:match]) - (Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty + Array(param[:notmatch]).each do |item| + should contain_concat__fragment("vhost1-500-#{params[:location]}").without_content(item) + end end end end @@ -309,7 +313,9 @@ it param[:title] do lines = subject.resource('concat::fragment', "vhost1-500-#{params[:location]}").send(:parameters)[:content].split("\n") (lines & Array(param[:match])).should == Array(param[:match]) - (Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty + Array(param[:notmatch]).each do |item| + should contain_concat__fragment("vhost1-500-#{params[:location]}").without_content(/#{item}/) + end end end end @@ -394,7 +400,9 @@ it param[:title] do lines = subject.resource('concat::fragment', "vhost1-500-#{params[:location]}").send(:parameters)[:content].split("\n") (lines & Array(param[:match])).should == Array(param[:match]) - (Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty + Array(param[:notmatch]).each do |item| + should contain_concat__fragment("vhost1-500-#{params[:location]}").without_content(item) + end end end end @@ -427,7 +435,9 @@ it param[:title] do lines = subject.resource('concat::fragment', "vhost1-500-#{params[:location]}").send(:parameters)[:content].split("\n") (lines & Array(param[:match])).should == Array(param[:match]) - (Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty + Array(param[:notmatch]).each do |item| + should contain_concat__fragment("vhost1-500-#{params[:location]}").without_content(item) + end end end end diff --git a/spec/defines/resource_mailhost_spec.rb b/spec/defines/resource_mailhost_spec.rb index 9f71a6cd5..1401e157c 100644 --- a/spec/defines/resource_mailhost_spec.rb +++ b/spec/defines/resource_mailhost_spec.rb @@ -8,9 +8,7 @@ { :osfamily => 'debian', :operatingsystem => 'debian', - :kernel => 'Linux', :ipaddress6 => '::', - :concat_basedir => '/var/lib/puppet/concat', } end let :default_params do @@ -29,7 +27,7 @@ describe 'basic assumptions' do let :params do default_params end - it { should include_class("nginx::config") } + it { should contain_class("nginx::config") } it { should contain_concat("/etc/nginx/conf.mail.d/#{title}.conf").with({ 'owner' => 'root', 'group' => 'root', @@ -69,7 +67,7 @@ :title => 'should not enable IPv6', :attr => 'ipv6_enable', :value => false, - :notmatch => ' listen [::]:80 default ipv6only=on;', + :notmatch => / listen \[::\]:80 default ipv6only=on;/, }, { :title => 'should set the IPv6 listen IP', @@ -133,7 +131,9 @@ it param[:title] do lines = subject.resource('concat::fragment', "#{title}-header").send(:parameters)[:content].split("\n") (lines & Array(param[:match])).should == Array(param[:match]) - (Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty + Array(param[:notmatch]).each do |item| + should contain_concat__fragment("#{title}-header").without_content(item) + end end end end @@ -157,7 +157,7 @@ :title => 'should not enable SSL', :attr => 'starttls', :value => false, - :notmatch => ' ssl_session_timeout 5m;', + :notmatch => / ssl_session_timeout 5m;/, }, { :title => 'should set ssl_certificate', @@ -185,7 +185,9 @@ it param[:title] do lines = subject.resource('concat::fragment', "#{title}-header").send(:parameters)[:content].split("\n") (lines & Array(param[:match])).should == Array(param[:match]) - (Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty + Array(param[:notmatch]).each do |item| + should contain_concat__fragment("#{title}-header").without_content(item) + end end end end @@ -209,7 +211,7 @@ :title => 'should not enable IPv6', :attr => 'ipv6_enable', :value => false, - :notmatch => ' listen [::]:80 default ipv6only=on;', + :notmatch => / listen \[::\]:80 default ipv6only=on;/, }, { :title => 'should set the IPv6 listen IP', @@ -280,7 +282,9 @@ it param[:title] do lines = subject.resource('concat::fragment', "#{title}-ssl").send(:parameters)[:content].split("\n") (lines & Array(param[:match])).should == Array(param[:match]) - (Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty + Array(param[:notmatch]).each do |item| + should contain_concat__fragment("#{title}-ssl").without_content(item) + end end end end diff --git a/spec/defines/resource_upstream_spec.rb b/spec/defines/resource_upstream_spec.rb index 7e54fcc04..10bc54729 100644 --- a/spec/defines/resource_upstream_spec.rb +++ b/spec/defines/resource_upstream_spec.rb @@ -5,10 +5,6 @@ 'upstream-test' end - let :facts do { - :concat_basedir => '/var/lib/puppet/concat', - } end - let :default_params do { :members => ['test'], @@ -68,8 +64,9 @@ it { should contain_file("/etc/nginx/conf.d/#{title}-upstream.conf").with_mode('0644') } it param[:title] do verify_contents(subject, "/etc/nginx/conf.d/#{title}-upstream.conf", Array(param[:match])) - lines = subject.resource('file', "/etc/nginx/conf.d/#{title}-upstream.conf").send(:parameters)[:content].split("\n") - (Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty + Array(param[:notmatch]).each do |item| + should contain_file("/etc/nginx/conf.d/#{title}-upstream.conf").without_content(item) + end end end end diff --git a/spec/defines/resource_vhost_spec.rb b/spec/defines/resource_vhost_spec.rb index e65ae2f71..1932c5c33 100644 --- a/spec/defines/resource_vhost_spec.rb +++ b/spec/defines/resource_vhost_spec.rb @@ -14,9 +14,7 @@ { :osfamily => 'Debian', :operatingsystem => 'debian', - :kernel => 'Linux', :ipaddress6 => '::', - :concat_basedir => '/var/lib/puppet/concat', } end let :pre_condition do @@ -30,8 +28,8 @@ describe 'basic assumptions' do let :params do default_params end - it { should include_class("nginx::params") } - it { should include_class("nginx::config") } + it { should contain_class("nginx::params") } + it { should contain_class("nginx::config") } it { should contain_concat("/etc/nginx/sites-available/#{title}.conf").with({ 'owner' => 'root', 'group' => 'root', @@ -85,7 +83,7 @@ :title => 'should not enable IPv6', :attr => 'ipv6_enable', :value => false, - :notmatch => ' listen [::]:80 default ipv6only=on;', + :notmatch => / listen \[::\]:80 default ipv6only=on;/, }, { :title => 'should set the IPv6 listen IP', @@ -155,7 +153,7 @@ :title => 'should not set root', :attr => 'use_default_location', :value => true, - :notmatch => ' root /;', + :notmatch => / root \/;/, }, { :title => 'should set proxy_set_header', @@ -180,8 +178,8 @@ :attr => 'rewrite_to_https', :value => false, :notmatch => [ - ' if ($ssl_protocol = "") {', - ' return 301 https://$host$request_uri;', + /if \(\$ssl_protocol = ""\) \{/, + / return 301 https:\/\/\$host\$request_uri;/, ], }, { @@ -204,7 +202,9 @@ it param[:title] do lines = subject.resource('concat::fragment', "#{title}-header").send(:parameters)[:content].split("\n") (lines & Array(param[:match])).should == Array(param[:match]) - (Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty + Array(param[:notmatch]).each do |item| + should contain_concat__fragment("#{title}-header").without_content(item) + end end end end @@ -246,9 +246,9 @@ :attr => 'rewrite_www_to_non_www', :value => false, :notmatch => [ - ' listen *:80;', - ' server_name www.rspec.example.com;', - ' rewrite ^ http://rspec.example.com$uri permanent;', + / listen \*:80;/, + / server_name www\.rspec\.example\.com;/, + / rewrite \^ http:\/\/rspec\.example\.com\$uri permanent;/, ], }, ].each do |param| @@ -259,7 +259,9 @@ it param[:title] do lines = subject.resource('concat::fragment', "#{title}-footer").send(:parameters)[:content].split("\n") (lines & Array(param[:match])).should == Array(param[:match]) - (Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty + Array(param[:notmatch]).each do |item| + should contain_concat__fragment("#{title}-footer").without_content(item) + end end end end @@ -319,7 +321,7 @@ :title => 'should disable IPv6', :attr => 'ipv6_enable', :value => false, - :notmatch => ' listen [::]:80 default ipv6only=on;', + :notmatch => / listen \[::\]:80 default ipv6only=on;/, }, { :title => 'should set the IPv6 listen IP', @@ -409,7 +411,7 @@ :title => 'should not set root', :attr => 'use_default_location', :value => true, - :notmatch => ' root /;', + :notmatch => / root \/;/, }, ].each do |param| context "when #{param[:attr]} is #{param[:value]}" do @@ -423,7 +425,9 @@ it param[:title] do lines = subject.resource('concat::fragment', "#{title}-ssl-header").send(:parameters)[:content].split("\n") (lines & Array(param[:match])).should == Array(param[:match]) - (Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty + Array(param[:notmatch]).each do |item| + should contain_concat__fragment("#{title}-ssl-header").without_content(item) + end end end end @@ -465,9 +469,9 @@ :attr => 'rewrite_www_to_non_www', :value => false, :notmatch => [ - ' listen *:443 ssl;', - ' server_name www.rspec.example.com;', - ' rewrite ^ https://rspec.example.com$uri permanent;', + / listen \*:443 ssl;/, + / server_name www\.rspec\.example\.com;/, + / rewrite \^ https:\/\/rspec\.example\.com\$uri permanent;/, ], }, ].each do |param| @@ -483,7 +487,9 @@ it param[:title] do lines = subject.resource('concat::fragment', "#{title}-ssl-footer").send(:parameters)[:content].split("\n") (lines & Array(param[:match])).should == Array(param[:match]) - (Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty + Array(param[:notmatch]).each do |item| + should contain_concat__fragment("#{title}-ssl-footer").without_content(item) + end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2c6f56649..a987b6e6c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1 +1,8 @@ require 'puppetlabs_spec_helper/module_spec_helper' + +RSpec.configure do |c| + c.default_facts = { + :kernel => 'Linux', + :concat_basedir => '/var/lib/puppet/concat', + } +end diff --git a/spec/spec_helper_system.rb b/spec/spec_helper_system.rb index aceafba95..bfb7271d0 100644 --- a/spec/spec_helper_system.rb +++ b/spec/spec_helper_system.rb @@ -1,8 +1,6 @@ require 'rspec-system/spec_helper' require 'rspec-system-puppet/helpers' require 'rspec-system-serverspec/helpers' -include Serverspec::Helper::RSpecSystem -include Serverspec::Helper::DetectOS include RSpecSystemPuppet::Helpers RSpec.configure do |c|