spec: updates for rspec-puppet 2.x and rspec 3.x

This patch aim to update our specs test in order to work with the rspec-puppet
release 2.0.0, in the mean time, we update rspec syntax order to be prepared
for rspec 3.x move.

In details:
* Upgrade and pin rspec-puppet from 1.0.1 to 2.0.0
* Convert 'should' keyword to 'is_expected.to' (prepare rspec 3.x)
* Fix spec tests for rspec-puppet 2.0.0
* Clean Gemfile (remove over-specificication of runtime deps of
  puppetlabs_spec_helper)

Change-Id: I405830cd95c9f0635418b91ff081c43d77234e39
Signed-off-by: Gael Chamoulaud <gchamoul@redhat.com>
This commit is contained in:
Gael Chamoulaud 2015-04-14 11:38:34 +02:00
parent f6bece8c53
commit cb436e722e
6 changed files with 53 additions and 55 deletions

View File

@ -2,6 +2,7 @@ source 'https://rubygems.org'
group :development, :test do
gem 'puppetlabs_spec_helper', :require => false
gem 'rspec-puppet', '~> 2.0.0', :require => false
gem 'puppet-lint', '~> 1.1.0'
gem 'metadata-json-lint'
@ -16,9 +17,6 @@ group :development, :test do
gem 'puppet-lint-variable_contains_upcase'
gem 'puppet-lint-numericvariable'
gem 'rspec-puppet', '~> 1.0.1'
gem 'rake', '10.1.1'
gem 'rspec', '< 2.99'
gem 'json'
gem 'webmock'
end

View File

@ -25,20 +25,20 @@ describe 'horizon' do
context 'with default parameters' do
it {
should contain_package('python-lesscpy').with_ensure('present')
should contain_package('horizon').with(
is_expected.to contain_package('python-lesscpy').with_ensure('present')
is_expected.to contain_package('horizon').with(
:ensure => 'present',
:tag => 'openstack'
)
}
it { should contain_exec('refresh_horizon_django_cache').with({
it { is_expected.to contain_exec('refresh_horizon_django_cache').with({
:command => '/usr/share/openstack-dashboard/manage.py compress',
:refreshonly => true,
})}
it { should contain_concat(platforms_params[:config_file]).that_notifies('Exec[refresh_horizon_django_cache]') }
it { is_expected.to contain_concat(platforms_params[:config_file]).that_notifies('Exec[refresh_horizon_django_cache]') }
it 'configures apache' do
should contain_class('horizon::wsgi::apache').with({
is_expected.to contain_class('horizon::wsgi::apache').with({
:servername => 'some.host.tld',
:listen_ssl => false,
:servername => 'some.host.tld',
@ -47,7 +47,7 @@ describe 'horizon' do
end
it 'generates local_settings.py' do
verify_concat_fragment_contents(subject, 'local_settings.py', [
verify_concat_fragment_contents(catalogue, 'local_settings.py', [
'DEBUG = False',
"ALLOWED_HOSTS = ['*', ]",
"SECRET_KEY = 'elj1IWiLoWHgcyYxFVLj7cM5rGOOxWl0'",
@ -71,13 +71,13 @@ describe 'horizon' do
])
# From internals of verify_contents, get the contents to check for absence of a line
content = subject.resource('concat::fragment', 'local_settings.py').send(:parameters)[:content]
content = catalogue.resource('concat::fragment', 'local_settings.py').send(:parameters)[:content]
# With default options, should _not_ have a line to configure SESSION_ENGINE
content.should_not match(/^SESSION_ENGINE/)
expect(content).not_to match(/^SESSION_ENGINE/)
end
it { should_not contain_file(params[:file_upload_temp_dir]) }
it { is_expected.not_to contain_file(params[:file_upload_temp_dir]) }
end
context 'with overridden parameters' do
@ -102,7 +102,7 @@ describe 'horizon' do
end
it 'generates local_settings.py' do
verify_concat_fragment_contents(subject, 'local_settings.py', [
verify_concat_fragment_contents(catalogue, 'local_settings.py', [
'DEBUG = True',
"ALLOWED_HOSTS = ['*', ]",
'CSRF_COOKIE_SECURE = True',
@ -129,9 +129,9 @@ describe 'horizon' do
])
end
it { should_not contain_file(platforms_params[:config_file]).that_notifies('Exec[refresh_horizon_django_cache]') }
it { is_expected.not_to contain_file(platforms_params[:config_file]).that_notifies('Exec[refresh_horizon_django_cache]') }
it { should contain_file(params[:file_upload_temp_dir]) }
it { is_expected.to contain_file(params[:file_upload_temp_dir]) }
end
context 'with overridden parameters and cache_server_ip array' do
@ -142,12 +142,12 @@ describe 'horizon' do
end
it 'generates local_settings.py' do
verify_concat_fragment_contents(subject, 'local_settings.py', [
verify_concat_fragment_contents(catalogue, 'local_settings.py', [
" 'LOCATION': [ '10.0.0.1:11211','10.0.0.2:11211', ],",
])
end
it { should contain_exec('refresh_horizon_django_cache') }
it { is_expected.to contain_exec('refresh_horizon_django_cache') }
end
context 'with vhost_extra_params' do
@ -158,7 +158,7 @@ describe 'horizon' do
end
it 'configures apache' do
should contain_class('horizon::wsgi::apache').with({
is_expected.to contain_class('horizon::wsgi::apache').with({
:extra_params => { 'add_listen' => false },
})
end
@ -177,7 +177,7 @@ describe 'horizon' do
end
it 'configures apache' do
should contain_class('horizon::wsgi::apache').with({
is_expected.to contain_class('horizon::wsgi::apache').with({
:bind_address => nil,
:listen_ssl => true,
:horizon_cert => '/etc/pki/tls/certs/httpd.crt',
@ -193,7 +193,7 @@ describe 'horizon' do
end
it 'does not configure apache' do
should_not contain_class('horizon::wsgi::apache')
is_expected.not_to contain_class('horizon::wsgi::apache')
end
end
@ -208,7 +208,7 @@ describe 'horizon' do
end
it 'AVAILABLE_REGIONS is configured' do
verify_concat_fragment_contents(subject, 'local_settings.py', [
verify_concat_fragment_contents(catalogue, 'local_settings.py', [
"AVAILABLE_REGIONS = [",
" ('http://region-1.example.com:5000/v2.0', 'Region-1'),",
" ('http://region-2.example.com:5000/v2.0', 'Region-2'),",
@ -230,7 +230,7 @@ describe 'horizon' do
end
it 'POLICY_FILES_PATH and POLICY_FILES are configured' do
verify_concat_fragment_contents(subject, 'local_settings.py', [
verify_concat_fragment_contents(catalogue, 'local_settings.py', [
"POLICY_FILES_PATH = '/opt/openstack-dashboard'",
"POLICY_FILES = {",
" 'compute': 'nova_policy.json',",
@ -251,7 +251,7 @@ describe 'horizon' do
end
it 'uses the custom local_settings.py template' do
verify_concat_fragment_contents(subject, 'local_settings.py', [
verify_concat_fragment_contents(catalogue, 'local_settings.py', [
'# Custom local_settings.py',
'DEBUG = True',
"HORIZON_CONFIG = {",
@ -280,7 +280,7 @@ describe 'horizon' do
})
end
it { should_not contain_file(params[:file_upload_temp_dir]) }
it { is_expected.not_to contain_file(params[:file_upload_temp_dir]) }
end
end

View File

@ -29,13 +29,13 @@ describe 'horizon::wsgi::apache' do
context 'with default parameters' do
it 'configures apache' do
should contain_class('horizon::params')
should contain_class('apache')
should contain_class('apache::mod::wsgi')
should contain_service('httpd').with_name(platforms_params[:http_service])
should contain_file(platforms_params[:httpd_config_file])
should contain_package('horizon').with_ensure('present')
should contain_apache__vhost('horizon_vhost').with(
is_expected.to contain_class('horizon::params')
is_expected.to contain_class('apache')
is_expected.to contain_class('apache::mod::wsgi')
is_expected.to contain_service('httpd').with_name(platforms_params[:http_service])
is_expected.to contain_file(platforms_params[:httpd_config_file])
is_expected.to contain_package('horizon').with_ensure('present')
is_expected.to contain_apache__vhost('horizon_vhost').with(
'servername' => 'some.host.tld',
'access_log_file' => 'horizon_access.log',
'error_log_file' => 'horizon_error.log',
@ -62,13 +62,13 @@ describe 'horizon::wsgi::apache' do
end
it 'configures apache' do
should contain_class('horizon::params')
should contain_class('apache')
should contain_class('apache::mod::wsgi')
should contain_service('httpd').with_name(platforms_params[:http_service])
should contain_file(platforms_params[:httpd_config_file])
should contain_package('horizon').with_ensure('present')
should contain_apache__vhost('horizon_vhost').with(
is_expected.to contain_class('horizon::params')
is_expected.to contain_class('apache')
is_expected.to contain_class('apache::mod::wsgi')
is_expected.to contain_service('httpd').with_name(platforms_params[:http_service])
is_expected.to contain_file(platforms_params[:httpd_config_file])
is_expected.to contain_package('horizon').with_ensure('present')
is_expected.to contain_apache__vhost('horizon_vhost').with(
'servername' => 'some.host.tld',
'access_log_file' => 'horizon_access.log',
'error_log_file' => 'horizon_error.log',
@ -100,9 +100,9 @@ describe 'horizon::wsgi::apache' do
context 'with required parameters' do
it 'configures apache for SSL' do
should contain_class('apache::mod::ssl')
is_expected.to contain_class('apache::mod::ssl')
end
it { should contain_apache__vhost('horizon_ssl_vhost').with(
it { is_expected.to contain_apache__vhost('horizon_ssl_vhost').with(
'servername' => 'some.host.tld',
'access_log_file' => 'horizon_ssl_access.log',
'error_log_file' => 'horizon_ssl_error.log',
@ -121,7 +121,7 @@ describe 'horizon::wsgi::apache' do
'wsgi_script_aliases' => { platforms_params[:root_url] => '/usr/share/openstack-dashboard/openstack_dashboard/wsgi/django.wsgi' }
)}
it { should contain_apache__vhost('horizon_vhost').with(
it { is_expected.to contain_apache__vhost('horizon_vhost').with(
'servername' => 'some.host.tld',
'access_log_file' => 'horizon_access.log',
'error_log_file' => 'horizon_error.log',
@ -167,7 +167,7 @@ describe 'horizon::wsgi::apache' do
end
it 'configures apache' do
should contain_apache__vhost('horizon_vhost').with(
is_expected.to contain_apache__vhost('horizon_vhost').with(
'add_listen' => false,
'docroot' => '/tmp'
)
@ -201,7 +201,7 @@ describe 'horizon::wsgi::apache' do
it_behaves_like 'apache for horizon'
it {
should contain_class('apache::mod::wsgi').with(:wsgi_socket_prefix => '/var/run/wsgi')
is_expected.to contain_class('apache::mod::wsgi').with(:wsgi_socket_prefix => '/var/run/wsgi')
}
end

View File

@ -1,5 +1,5 @@
shared_examples_for "a Puppet::Error" do |description|
it "with message matching #{description.inspect}" do
expect { subject }.to raise_error(Puppet::Error, description)
expect { is_expected.to have_class_count(1) }.to raise_error(Puppet::Error, description)
end
end

View File

@ -8,5 +8,5 @@ end
def verify_concat_fragment_contents(subject, title, expected_lines)
content = subject.resource('concat::fragment', title).send(:parameters)[:content]
(content.split("\n") & expected_lines).should == expected_lines
expect(content.split("\n") & expected_lines).to eq(expected_lines)
end

View File

@ -5,51 +5,51 @@ describe "the os_any2array function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
Puppet::Parser::Functions.function("os_any2array").should == "function_os_any2array"
expect(Puppet::Parser::Functions.function("os_any2array")).to eq("function_os_any2array")
end
it "should return an empty array if there is less than 1 argument" do
result = scope.function_os_any2array([])
result.should(eq([]))
expect(result).to(eq([]))
end
it "should convert boolean true to [ true ] " do
result = scope.function_os_any2array([true])
result.should(eq([true]))
expect(result).to(eq([true]))
end
it "should convert one object to [object]" do
result = scope.function_os_any2array(['one'])
result.should(eq(['one']))
expect(result).to(eq(['one']))
end
it "should convert multiple objects to [objects]" do
result = scope.function_os_any2array(['one', 'two'])
result.should(eq(['one', 'two']))
expect(result).to(eq(['one', 'two']))
end
it "should return empty array it was called with" do
result = scope.function_os_any2array([[]])
result.should(eq([]))
expect(result).to(eq([]))
end
it "should return one-member array it was called with" do
result = scope.function_os_any2array([['string']])
result.should(eq(['string']))
expect(result).to(eq(['string']))
end
it "should return multi-member array it was called with" do
result = scope.function_os_any2array([['one', 'two']])
result.should(eq(['one', 'two']))
expect(result).to(eq(['one', 'two']))
end
it "should return members of a hash it was called with" do
result = scope.function_os_any2array([{ 'key' => 'value' }])
result.should(eq(['key', 'value']))
expect(result).to(eq(['key', 'value']))
end
it "should return an empty array if it was called with an empty hash" do
result = scope.function_os_any2array([{ }])
result.should(eq([]))
expect(result).to(eq([]))
end
end