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: Ice356e35a65204a62e47f49dd4f5816208a6dace
Signed-off-by: Gael Chamoulaud <gchamoul@redhat.com>
This commit is contained in:
Gael Chamoulaud 2015-03-31 12:13:33 +02:00
parent 62cdb1ae91
commit 3fa6399cad
11 changed files with 62 additions and 64 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'
gem 'mocha'
gem 'json'
end

View File

@ -15,7 +15,7 @@ describe 'openstacklib::policy' do
end
it 'configures the proper policy' do
should contain_openstacklib__policy__base('foo').with(
is_expected.to contain_openstacklib__policy__base('foo').with(
:file_path => '/etc/nova/policy.json',
:key => 'context_is_admin',
:value => 'foo:bar'

View File

@ -19,11 +19,11 @@ describe 'openstacklib::db::mysql::host_access' do
:privileges => 'ALL' }
end
it { should contain_mysql_user("#{params[:user]}@10.0.0.1").with(
it { is_expected.to contain_mysql_user("#{params[:user]}@10.0.0.1").with(
:password_hash => params[:password_hash]
)}
it { should contain_mysql_grant("#{params[:user]}@10.0.0.1/#{params[:database]}.*").with(
it { is_expected.to contain_mysql_grant("#{params[:user]}@10.0.0.1/#{params[:database]}.*").with(
:user => "#{params[:user]}@10.0.0.1",
:privileges => 'ALL',
:table => "#{params[:database]}.*"

View File

@ -19,11 +19,11 @@ describe 'openstacklib::db::mysql' do
required_params
end
it { should contain_mysql_database(title).with(
it { is_expected.to contain_mysql_database(title).with(
:charset => 'utf8',
:collate => 'utf8_unicode_ci'
)}
it { should contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
it { is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
:user => title,
:database => title,
:privileges => 'ALL'
@ -35,11 +35,11 @@ describe 'openstacklib::db::mysql' do
{ :dbname => 'foobar' }.merge(required_params)
end
it { should contain_mysql_database(params[:dbname]).with(
it { is_expected.to contain_mysql_database(params[:dbname]).with(
:charset => 'utf8',
:collate => 'utf8_unicode_ci'
)}
it { should contain_openstacklib__db__mysql__host_access("#{params[:dbname]}_127.0.0.1").with(
it { is_expected.to contain_openstacklib__db__mysql__host_access("#{params[:dbname]}_127.0.0.1").with(
:user => title,
:database => params[:dbname],
:privileges => 'ALL'
@ -51,11 +51,11 @@ describe 'openstacklib::db::mysql' do
{ :user => 'foobar' }.merge(required_params)
end
it { should contain_mysql_database(title).with(
it { is_expected.to contain_mysql_database(title).with(
:charset => 'utf8',
:collate => 'utf8_unicode_ci'
)}
it { should contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
it { is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
:user => params[:user],
:database => title,
:privileges => 'ALL'
@ -67,14 +67,14 @@ describe 'openstacklib::db::mysql' do
{ :charset => 'latin1' }.merge(required_params)
end
it { should contain_mysql_database(title).with_charset(params[:charset]) }
it { is_expected.to contain_mysql_database(title).with_charset(params[:charset]) }
end
context 'when omitting the required parameter password_hash' do
let :params do
required_params.delete(:password_hash)
end
it { expect { should raise_error(Puppet::Error) } }
it { expect { is_expected.to raise_error(Puppet::Error) } }
end
context 'when notifying other resources' do
@ -85,7 +85,7 @@ describe 'openstacklib::db::mysql' do
{ :notify => 'Exec[nova-db-sync]'}.merge(required_params)
end
it { should contain_exec('nova-db-sync').that_subscribes_to("Openstacklib::Db::Mysql[#{title}]") }
it { is_expected.to contain_exec('nova-db-sync').that_subscribes_to("Openstacklib::Db::Mysql[#{title}]") }
end
context 'when required for other openstack services' do
@ -99,7 +99,7 @@ describe 'openstacklib::db::mysql' do
{ :before => 'Service[keystone]'}.merge(required_params)
end
it { should contain_service('keystone').that_requires("Openstacklib::Db::Mysql[keystone]") }
it { is_expected.to contain_service('keystone').that_requires("Openstacklib::Db::Mysql[keystone]") }
end
context "overriding allowed_hosts parameter with array value" do
@ -107,12 +107,12 @@ describe 'openstacklib::db::mysql' do
{ :allowed_hosts => ['127.0.0.1','%'] }.merge(required_params)
end
it {should contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
it {is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
:user => title,
:password_hash => params[:password_hash],
:database => title
)}
it {should contain_openstacklib__db__mysql__host_access("#{title}_%").with(
it {is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_%").with(
:user => title,
:password_hash => params[:password_hash],
:database => title
@ -124,7 +124,7 @@ describe 'openstacklib::db::mysql' do
{ :allowed_hosts => '192.168.1.1' }.merge(required_params)
end
it {should contain_openstacklib__db__mysql__host_access("#{title}_192.168.1.1").with(
it {is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_192.168.1.1").with(
:user => title,
:password_hash => params[:password_hash],
:database => title
@ -136,7 +136,7 @@ describe 'openstacklib::db::mysql' do
{ :allowed_hosts => '127.0.0.1' }.merge(required_params)
end
it {should contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
it {is_expected.to contain_openstacklib__db__mysql__host_access("#{title}_127.0.0.1").with(
:user => title,
:password_hash => params[:password_hash],
:database => title

View File

@ -22,7 +22,7 @@ describe 'openstacklib::db::postgresql' do
required_params
end
it { should contain_postgresql__server__db(title).with(
it { is_expected.to contain_postgresql__server__db(title).with(
:user => title,
:password => password_hash
)}
@ -32,7 +32,7 @@ describe 'openstacklib::db::postgresql' do
let :params do
{ :encoding => 'latin1' }.merge(required_params)
end
it { should contain_postgresql__server__db(title).with_encoding(params[:encoding]) }
it { is_expected.to contain_postgresql__server__db(title).with_encoding(params[:encoding]) }
end
context 'when omitting the required parameter password_hash' do
@ -40,7 +40,7 @@ describe 'openstacklib::db::postgresql' do
required_params.delete(:password_hash)
end
it { expect { should raise_error(Puppet::Error) } }
it { expect { is_expected.to raise_error(Puppet::Error) } }
end
context 'when notifying other resources' do
@ -51,7 +51,7 @@ describe 'openstacklib::db::postgresql' do
{ :notify => 'Exec[nova-db-sync]'}.merge(required_params)
end
it {should contain_exec('nova-db-sync').that_subscribes_to("Openstacklib::Db::Postgresql[#{title}]") }
it {is_expected.to contain_exec('nova-db-sync').that_subscribes_to("Openstacklib::Db::Postgresql[#{title}]") }
end
context 'when required for other openstack services' do
@ -65,7 +65,7 @@ describe 'openstacklib::db::postgresql' do
{ :before => 'Service[keystone]'}.merge(required_params)
end
it { should contain_service('keystone').that_requires("Openstacklib::Db::Postgresql[keystone]") }
it { is_expected.to contain_service('keystone').that_requires("Openstacklib::Db::Postgresql[keystone]") }
end
end
@ -82,7 +82,7 @@ describe 'openstacklib::db::postgresql' do
required_params
end
it { should contain_postgresql__server__db(title).with(
it { is_expected.to contain_postgresql__server__db(title).with(
:user => title,
:password => password_hash
)}
@ -92,7 +92,7 @@ describe 'openstacklib::db::postgresql' do
let :params do
{ :encoding => 'latin1' }.merge(required_params)
end
it { should contain_postgresql__server__db(title).with_encoding(params[:encoding]) }
it { is_expected.to contain_postgresql__server__db(title).with_encoding(params[:encoding]) }
end
context 'when omitting the required parameter password_hash' do
@ -100,7 +100,7 @@ describe 'openstacklib::db::postgresql' do
required_params.delete(:password_hash)
end
it { expect { should raise_error(Puppet::Error) } }
it { expect { is_expected.to raise_error(Puppet::Error) } }
end
context 'when notifying other resources' do
@ -111,7 +111,7 @@ describe 'openstacklib::db::postgresql' do
{ :notify => 'Exec[nova-db-sync]'}.merge(required_params)
end
it {should contain_exec('nova-db-sync').that_subscribes_to("Openstacklib::Db::Postgresql[#{title}]") }
it {is_expected.to contain_exec('nova-db-sync').that_subscribes_to("Openstacklib::Db::Postgresql[#{title}]") }
end
context 'when required for other openstack services' do
@ -125,7 +125,7 @@ describe 'openstacklib::db::postgresql' do
{ :before => 'Service[keystone]'}.merge(required_params)
end
it { should contain_service('keystone').that_requires("Openstacklib::Db::Postgresql[keystone]") }
it { is_expected.to contain_service('keystone').that_requires("Openstacklib::Db::Postgresql[keystone]") }
end
end

View File

@ -28,18 +28,18 @@ describe 'openstacklib::messaging::rabbitmq' do
end
context 'with default parameters' do
it { should contain_rabbitmq_user('guest').with(
it { is_expected.to contain_rabbitmq_user('guest').with(
:admin => false,
:password => 'guest',
:provider => 'rabbitmqctl',
)}
it { should contain_rabbitmq_user_permissions('guest@/').with(
it { is_expected.to contain_rabbitmq_user_permissions('guest@/').with(
:configure_permission => '.*',
:write_permission => '.*',
:read_permission => '.*',
:provider => 'rabbitmqctl',
)}
it { should contain_rabbitmq_vhost('/').with(
it { is_expected.to contain_rabbitmq_vhost('/').with(
:provider => 'rabbitmqctl',
)}
end
@ -57,18 +57,18 @@ describe 'openstacklib::messaging::rabbitmq' do
)
end
it { should contain_rabbitmq_user('nova').with(
it { is_expected.to contain_rabbitmq_user('nova').with(
:admin => true,
:password => 'secrete',
:provider => 'rabbitmqctl',
)}
it { should contain_rabbitmq_user_permissions('nova@/nova').with(
it { is_expected.to contain_rabbitmq_user_permissions('nova@/nova').with(
:configure_permission => '.nova',
:write_permission => '.nova',
:read_permission => '.nova',
:provider => 'rabbitmqctl',
)}
it { should contain_rabbitmq_vhost('/nova').with(
it { is_expected.to contain_rabbitmq_vhost('/nova').with(
:provider => 'rabbitmqctl',
)}
end
@ -78,7 +78,7 @@ describe 'openstacklib::messaging::rabbitmq' do
params.merge!( :manage_vhost => false )
end
it { should_not contain_rabbitmq_vhost }
it { is_expected.not_to contain_rabbitmq_vhost }
end
end

View File

@ -13,7 +13,7 @@ describe 'openstacklib::policy::base' do
end
it 'configures (modifies) the proper policy' do
should contain_augeas('/etc/nova/policy.json-context_is_admin or owner-foo:bar').with(
is_expected.to contain_augeas('/etc/nova/policy.json-context_is_admin or owner-foo:bar').with(
'lens' => 'Json.lns',
'incl' => '/etc/nova/policy.json',
'changes' => 'set dict/entry[*][.="context_is_admin or owner"]/string "foo:bar"',
@ -22,7 +22,7 @@ describe 'openstacklib::policy::base' do
end
it 'configures (adds) the proper policy' do
should contain_augeas('/etc/nova/policy.json-context_is_admin or owner-foo:bar-add').with(
is_expected.to contain_augeas('/etc/nova/policy.json-context_is_admin or owner-foo:bar-add').with(
'lens' => 'Json.lns',
'incl' => '/etc/nova/policy.json',
'changes' => [

View File

@ -32,7 +32,7 @@ describe 'openstacklib::service_validation' do
required_params
end
it { should contain_exec("execute #{title} validation").with(
it { is_expected.to contain_exec("execute #{title} validation").with(
:path => '/usr/bin:/bin:/usr/sbin:/sbin',
:provider => 'shell',
:command => 'nova list',
@ -40,7 +40,7 @@ describe 'openstacklib::service_validation' do
:try_sleep => '2',
)}
it { should contain_anchor("create #{title} anchor").with(
it { is_expected.to contain_anchor("create #{title} anchor").with(
:require => "Exec[execute #{title} validation]",
)}
@ -50,7 +50,7 @@ describe 'openstacklib::service_validation' do
let :params do
required_params.delete(:command)
end
it { expect { should raise_error(Puppet::Error) } }
it { expect { is_expected.to raise_error(Puppet::Error) } }
end
end

View File

@ -42,20 +42,20 @@ describe 'openstacklib::wsgi::apache' do
end
shared_examples_for 'apache serving a service with mod_wsgi' do
it { should contain_service('httpd').with_name(platform_parameters[:httpd_service_name]) }
it { should contain_class('apache') }
it { should contain_class('apache::mod::wsgi') }
it { is_expected.to contain_service('httpd').with_name(platform_parameters[:httpd_service_name]) }
it { is_expected.to contain_class('apache') }
it { is_expected.to contain_class('apache::mod::wsgi') }
describe 'with default parameters' do
it { should contain_file('/var/www/cgi-bin/keystone').with(
it { is_expected.to contain_file('/var/www/cgi-bin/keystone').with(
'ensure' => 'directory',
'owner' => 'keystone',
'group' => 'keystone',
'require' => 'Package[httpd]'
)}
it { should contain_file('keystone_wsgi').with(
it { is_expected.to contain_file('keystone_wsgi').with(
'ensure' => 'file',
'path' => '/var/www/cgi-bin/keystone/main',
'source' => '/usr/share/keystone/keystone.wsgi',
@ -64,7 +64,7 @@ describe 'openstacklib::wsgi::apache' do
'mode' => '0644',
)}
it { should contain_apache__vhost('keystone_wsgi').with(
it { is_expected.to contain_apache__vhost('keystone_wsgi').with(
'servername' => 'some.host.tld',
'ip' => nil,
'port' => '5000',
@ -77,7 +77,7 @@ describe 'openstacklib::wsgi::apache' do
'wsgi_script_aliases' => { '/' => "/var/www/cgi-bin/keystone/main" },
'require' => 'File[keystone_wsgi]'
)}
it { should contain_file("#{platform_parameters[:httpd_ports_file]}") }
it { is_expected.to contain_file("#{platform_parameters[:httpd_ports_file]}") }
end
end

View File

@ -3,27 +3,27 @@ require 'spec_helper'
describe 'os_database_connection' do
it 'refuses String' do
should run.with_params('foo').\
is_expected.to run.with_params('foo').\
and_raise_error(Puppet::ParseError, /Requires an hash/)
end
it 'refuses Array' do
should run.with_params(['foo']).\
is_expected.to run.with_params(['foo']).\
and_raise_error(Puppet::ParseError, /Requires an hash/)
end
it 'refuses without at least one argument' do
should run.with_params().\
is_expected.to run.with_params().\
and_raise_error(Puppet::ParseError, /Wrong number of arguments/)
end
it 'refuses too many arguments' do
should run.with_params('foo', 'bar').\
is_expected.to run.with_params('foo', 'bar').\
and_raise_error(Puppet::ParseError, /Wrong number of arguments/)
end
it 'fails if port is provided with missing host' do
should run.with_params({
is_expected.to run.with_params({
'dialect' => 'sqlite',
'database' => '/var/lib/keystone/keystone.db',
'port' => '3306',
@ -34,7 +34,7 @@ describe 'os_database_connection' do
context 'creates the correct connection URI' do
it 'with all parameters' do
should run.with_params({
is_expected.to run.with_params({
'dialect' => 'mysql',
'host' => '127.0.0.1',
'port' => '3306',
@ -46,7 +46,7 @@ describe 'os_database_connection' do
end
it 'without port' do
should run.with_params({
is_expected.to run.with_params({
'dialect' => 'mysql',
'host' => '127.0.0.1',
'database' => 'test',
@ -57,7 +57,7 @@ describe 'os_database_connection' do
end
it 'without host and port' do
should run.with_params({
is_expected.to run.with_params({
'dialect' => 'sqlite',
'database' => '/var/lib/keystone/keystone.db',
'charset' => 'utf-8'
@ -65,7 +65,7 @@ describe 'os_database_connection' do
end
it 'without username and password' do
should run.with_params({
is_expected.to run.with_params({
'dialect' => 'mysql',
'host' => '127.0.0.1',
'port' => '3306',
@ -75,7 +75,7 @@ describe 'os_database_connection' do
end
it 'with username set to undef' do
should run.with_params({
is_expected.to run.with_params({
'dialect' => 'mysql',
'host' => '127.0.0.1',
'port' => '3306',
@ -86,7 +86,7 @@ describe 'os_database_connection' do
end
it 'with username set to an empty string' do
should run.with_params({
is_expected.to run.with_params({
'dialect' => 'mysql',
'host' => '127.0.0.1',
'port' => '3306',
@ -97,7 +97,7 @@ describe 'os_database_connection' do
end
it 'without password' do
should run.with_params({
is_expected.to run.with_params({
'dialect' => 'mysql',
'host' => '127.0.0.1',
'port' => '3306',
@ -108,7 +108,7 @@ describe 'os_database_connection' do
end
it 'with password set to undef' do
should run.with_params({
is_expected.to run.with_params({
'dialect' => 'mysql',
'host' => '127.0.0.1',
'port' => '3306',
@ -120,7 +120,7 @@ describe 'os_database_connection' do
end
it 'with password set to an empty string' do
should run.with_params({
is_expected.to run.with_params({
'dialect' => 'mysql',
'host' => '127.0.0.1',
'port' => '3306',

View File

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