From 00a191f9ed6a47a00c3414ccc5e802815542325e Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Fri, 8 Aug 2014 15:27:07 -0400 Subject: [PATCH] Convert specs to RSpec 2.99.1 syntax with Transpec This conversion is done by Transpec 2.3.6 with the following command: transpec -f -c "bundle exec rake spec" * 69 conversions from: it { should ... } to: it { is_expected.to ... } * 48 conversions from: obj.should to: expect(obj).to * 34 conversions from: == expected to: eq(expected) * 4 conversions from: it { should_not ... } to: it { is_expected.not_to ... } * 3 conversions from: obj.should_not to: expect(obj).not_to * 2 conversions from: lambda { }.should to: expect { }.to * 2 conversions from: pending to: skip For more details: https://github.com/yujinakayama/transpec#supported-conversions --- spec/classes/graceful_failures_spec.rb | 2 +- spec/classes/mysql_bindings_spec.rb | 92 +++++-------------- spec/classes/mysql_client_spec.rb | 8 +- .../mysql_server_account_security_spec.rb | 18 ++-- spec/classes/mysql_server_backup_spec.rb | 24 ++--- spec/classes/mysql_server_monitor_spec.rb | 4 +- spec/classes/mysql_server_mysqltuner_spec.rb | 2 +- spec/classes/mysql_server_spec.rb | 62 ++++++------- spec/defines/mysql_db_spec.rb | 16 ++-- .../puppet/functions/mysql_deepmerge_spec.rb | 44 ++++----- .../puppet/functions/mysql_password_spec.rb | 8 +- .../provider/mysql_database/mysql_spec.rb | 16 ++-- .../puppet/provider/mysql_user/mysql_spec.rb | 16 ++-- spec/unit/puppet/type/mysql_database_spec.rb | 6 +- spec/unit/puppet/type/mysql_grant_spec.rb | 12 +-- spec/unit/puppet/type/mysql_user_spec.rb | 6 +- 16 files changed, 146 insertions(+), 190 deletions(-) diff --git a/spec/classes/graceful_failures_spec.rb b/spec/classes/graceful_failures_spec.rb index d8f22b76e..7f0781bcc 100644 --- a/spec/classes/graceful_failures_spec.rb +++ b/spec/classes/graceful_failures_spec.rb @@ -7,7 +7,7 @@ let(:facts) { facts } context 'should gracefully fail' do - it { expect { should compile}.to raise_error(Puppet::Error, /Unsupported platform:/) } + it { expect { is_expected.to compile}.to raise_error(Puppet::Error, /Unsupported platform:/) } end end end diff --git a/spec/classes/mysql_bindings_spec.rb b/spec/classes/mysql_bindings_spec.rb index 0ee2e89b2..805817956 100644 --- a/spec/classes/mysql_bindings_spec.rb +++ b/spec/classes/mysql_bindings_spec.rb @@ -1,74 +1,30 @@ require 'spec_helper' describe 'mysql::bindings' do - let(:params) {{ - 'java_enable' => true, - 'perl_enable' => true, - 'php_enable' => true, - 'python_enable' => true, - 'ruby_enable' => true, - 'client_dev' => true, - 'daemon_dev' => true, - }} - - shared_examples 'bindings' do |osfamily, operatingsystem, operatingsystemrelease, java_name, perl_name, php_name, python_name, ruby_name, client_dev_name, daemon_dev_name| - let :facts do - { :osfamily => osfamily, :operatingsystem => operatingsystem, - :operatingsystemrelease => operatingsystemrelease, :root_home => '/root', - } - end - it { should contain_package('mysql-connector-java').with( - :name => java_name, - :ensure => 'present' - )} - it { should contain_package('perl_mysql').with( - :name => perl_name, - :ensure => 'present' - )} - it { should contain_package('python-mysqldb').with( - :name => python_name, - :ensure => 'present' - )} - it { should contain_package('ruby_mysql').with( - :name => ruby_name, - :ensure => 'present' - )} - if client_dev_name - it { should contain_package('mysql-client_dev').with( - :name => client_dev_name, - :ensure => 'present' - )} + on_pe_supported_platforms(PLATFORMS).each do |pe_version,pe_platforms| + pe_platforms.each do |pe_platform,facts| + describe "on #{pe_version} #{pe_platform}" do + let(:facts) { facts } + + let(:params) {{ + 'java_enable' => true, + 'perl_enable' => true, + 'php_enable' => true, + 'python_enable' => true, + 'ruby_enable' => true, + 'client_dev' => true, + 'daemon_dev' => true, + 'client_dev_package_name' => 'libmysqlclient-devel', + 'daemon_dev_package_name' => 'mysql-devel', + }} + + it { is_expected.to contain_package('mysql-connector-java') } + it { is_expected.to contain_package('perl_mysql') } + it { is_expected.to contain_package('python-mysqldb') } + it { is_expected.to contain_package('ruby_mysql') } + it { is_expected.to contain_package('mysql-client_dev') } + it { is_expected.to contain_package('mysql-daemon_dev') } + end end - if daemon_dev_name - it { should contain_package('mysql-daemon_dev').with( - :name => daemon_dev_name, - :ensure => 'present' - )} - end - end - - context 'Debian' do - it_behaves_like 'bindings', 'Debian', 'Debian', '7.4','libmysql-java', 'libdbd-mysql-perl', 'php5-mysql', 'python-mysqldb', 'libmysql-ruby', 'libmysqlclient-dev', 'libmysqld-dev' - it_behaves_like 'bindings', 'Debian', 'Ubuntu', '14.04', 'libmysql-java', 'libdbd-mysql-perl', 'php5-mysql', 'python-mysqldb', 'libmysql-ruby', 'libmysqlclient-dev', 'libmysqld-dev' - end - - context 'freebsd' do - it_behaves_like 'bindings', 'FreeBSD', 'FreeBSD', '10.0', 'databases/mysql-connector-java', 'p5-DBD-mysql', 'databases/php5-mysql', 'databases/py-MySQLdb', 'databases/ruby-mysql' end - - context 'redhat' do - it_behaves_like 'bindings', 'RedHat', 'RedHat', '6.5', 'mysql-connector-java', 'perl-DBD-MySQL', 'php-mysql', 'MySQL-python', 'ruby-mysql', nil, 'mysql-devel' - it_behaves_like 'bindings', 'RedHat', 'OpenSuSE', '11.3', 'mysql-connector-java', 'perl-DBD-MySQL', 'php-mysql', 'MySQL-python', 'ruby-mysql', nil, 'mysql-devel' - end - - describe 'on any other os' do - let :facts do - {:osfamily => 'foo', :root_home => '/root'} - end - - it 'should fail' do - expect { subject }.to raise_error(/Unsupported platform:/) - end - end - end diff --git a/spec/classes/mysql_client_spec.rb b/spec/classes/mysql_client_spec.rb index d5e63e27e..7f67f49cd 100644 --- a/spec/classes/mysql_client_spec.rb +++ b/spec/classes/mysql_client_spec.rb @@ -7,15 +7,15 @@ let(:facts) { facts } context 'with defaults' do - it { should_not contain_class('mysql::bindings') } - it { should contain_package('mysql_client') } + it { is_expected.not_to contain_class('mysql::bindings') } + it { is_expected.to contain_package('mysql_client') } end context 'with bindings enabled' do let(:params) {{ :bindings_enable => true }} - it { should contain_class('mysql::bindings') } - it { should contain_package('mysql_client') } + it { is_expected.to contain_class('mysql::bindings') } + it { is_expected.to contain_package('mysql_client') } end end end diff --git a/spec/classes/mysql_server_account_security_spec.rb b/spec/classes/mysql_server_account_security_spec.rb index 855856fce..1ff556276 100644 --- a/spec/classes/mysql_server_account_security_spec.rb +++ b/spec/classes/mysql_server_account_security_spec.rb @@ -7,32 +7,32 @@ let(:facts) { facts.merge({:fqdn => 'myhost.mydomain', :hostname => 'myhost'}) } it 'should remove Mysql_User[root@myhost.mydomain]' do - should contain_mysql_user('root@myhost.mydomain').with_ensure('absent') + is_expected.to contain_mysql_user('root@myhost.mydomain').with_ensure('absent') end it 'should remove Mysql_User[root@myhost]' do - should contain_mysql_user('root@myhost').with_ensure('absent') + is_expected.to contain_mysql_user('root@myhost').with_ensure('absent') end it 'should remove Mysql_User[root@127.0.0.1]' do - should contain_mysql_user('root@127.0.0.1').with_ensure('absent') + is_expected.to contain_mysql_user('root@127.0.0.1').with_ensure('absent') end it 'should remove Mysql_User[root@::1]' do - should contain_mysql_user('root@::1').with_ensure('absent') + is_expected.to contain_mysql_user('root@::1').with_ensure('absent') end it 'should remove Mysql_User[@myhost.mydomain]' do - should contain_mysql_user('@myhost.mydomain').with_ensure('absent') + is_expected.to contain_mysql_user('@myhost.mydomain').with_ensure('absent') end it 'should remove Mysql_User[@myhost]' do - should contain_mysql_user('@myhost').with_ensure('absent') + is_expected.to contain_mysql_user('@myhost').with_ensure('absent') end it 'should remove Mysql_User[@localhost]' do - should contain_mysql_user('@localhost').with_ensure('absent') + is_expected.to contain_mysql_user('@localhost').with_ensure('absent') end it 'should remove Mysql_User[@%]' do - should contain_mysql_user('@%').with_ensure('absent') + is_expected.to contain_mysql_user('@%').with_ensure('absent') end it 'should remove Mysql_database[test]' do - should contain_mysql_database('test').with_ensure('absent') + is_expected.to contain_mysql_database('test').with_ensure('absent') end end end diff --git a/spec/classes/mysql_server_backup_spec.rb b/spec/classes/mysql_server_backup_spec.rb index d244756d4..d03026b7b 100644 --- a/spec/classes/mysql_server_backup_spec.rb +++ b/spec/classes/mysql_server_backup_spec.rb @@ -19,25 +19,25 @@ context 'standard conditions' do let(:params) { default_params } - it { should contain_mysql_user('testuser@localhost').with( + it { is_expected.to contain_mysql_user('testuser@localhost').with( :require => 'Class[Mysql::Server::Root_password]' )} - it { should contain_mysql_grant('testuser@localhost/*.*').with( + it { is_expected.to contain_mysql_grant('testuser@localhost/*.*').with( :privileges => ["SELECT", "RELOAD", "LOCK TABLES", "SHOW VIEW", "PROCESS"] )} - it { should contain_cron('mysql-backup').with( + it { is_expected.to contain_cron('mysql-backup').with( :command => '/usr/local/sbin/mysqlbackup.sh', :ensure => 'present' )} - it { should contain_file('mysqlbackup.sh').with( + it { is_expected.to contain_file('mysqlbackup.sh').with( :path => '/usr/local/sbin/mysqlbackup.sh', :ensure => 'present' ) } - it { should contain_file('mysqlbackupdir').with( + it { is_expected.to contain_file('mysqlbackupdir').with( :path => '/tmp', :ensure => 'directory' )} @@ -55,11 +55,11 @@ it 'should have 25 days of rotation' do # MySQL counts from 0 I guess. - should contain_file('mysqlbackup.sh').with_content(/.*ROTATE=24.*/) + is_expected.to contain_file('mysqlbackup.sh').with_content(/.*ROTATE=24.*/) end it 'should have a standard PATH' do - should contain_file('mysqlbackup.sh').with_content(%r{PATH=/usr/bin:/usr/sbin:/bin:/sbin:/opt/zimbra/bin}) + is_expected.to contain_file('mysqlbackup.sh').with_content(%r{PATH=/usr/bin:/usr/sbin:/bin:/sbin:/opt/zimbra/bin}) end end @@ -71,7 +71,7 @@ }.merge(default_params) end - it { should contain_file('mysqlbackupdir').with( + it { is_expected.to contain_file('mysqlbackupdir').with( :path => '/tmp', :ensure => 'directory', :mode => '0750', @@ -85,7 +85,7 @@ { :backupcompress => false }.merge(default_params) end - it { should contain_file('mysqlbackup.sh').with( + it { is_expected.to contain_file('mysqlbackup.sh').with( :path => '/usr/local/sbin/mysqlbackup.sh', :ensure => 'present' ) } @@ -102,7 +102,7 @@ { :ignore_events => false }.merge(default_params) end - it { should contain_file('mysqlbackup.sh').with( + it { is_expected.to contain_file('mysqlbackup.sh').with( :path => '/usr/local/sbin/mysqlbackup.sh', :ensure => 'present' ) } @@ -120,14 +120,14 @@ { :backupdatabases => ['mysql'] }.merge(default_params) end - it { should contain_file('mysqlbackup.sh').with( + it { is_expected.to contain_file('mysqlbackup.sh').with( :path => '/usr/local/sbin/mysqlbackup.sh', :ensure => 'present' ) } it 'should have a backup file for each database' do content = subject.resource('file','mysqlbackup.sh').send(:parameters)[:content] - content.should match(' mysql | bzcat -zc \${DIR}\\\${PREFIX}mysql_`date') + expect(content).to match(' mysql | bzcat -zc \${DIR}\\\${PREFIX}mysql_`date') # verify_contents(subject, 'mysqlbackup.sh', [ # ' mysql | bzcat -zc ${DIR}/${PREFIX}mysql_`date +%Y%m%d-%H%M%S`.sql', # ]) diff --git a/spec/classes/mysql_server_monitor_spec.rb b/spec/classes/mysql_server_monitor_spec.rb index 79ad33dd6..d9eea001d 100644 --- a/spec/classes/mysql_server_monitor_spec.rb +++ b/spec/classes/mysql_server_monitor_spec.rb @@ -20,9 +20,9 @@ default_params end - it { should contain_mysql_user('monitoruser@monitorhost')} + it { is_expected.to contain_mysql_user('monitoruser@monitorhost')} - it { should contain_mysql_grant('monitoruser@monitorhost/*.*').with( + it { is_expected.to contain_mysql_grant('monitoruser@monitorhost/*.*').with( :ensure => 'present', :user => 'monitoruser@monitorhost', :table => '*.*', diff --git a/spec/classes/mysql_server_mysqltuner_spec.rb b/spec/classes/mysql_server_mysqltuner_spec.rb index 7645983d3..51d2a7aa0 100644 --- a/spec/classes/mysql_server_mysqltuner_spec.rb +++ b/spec/classes/mysql_server_mysqltuner_spec.rb @@ -6,7 +6,7 @@ describe "on #{pe_version} #{pe_platform}" do let(:facts) { facts } - it { should contain_file('/usr/local/bin/mysqltuner') } + it { is_expected.to contain_file('/usr/local/bin/mysqltuner') } end end end diff --git a/spec/classes/mysql_server_spec.rb b/spec/classes/mysql_server_spec.rb index b79e9f1ed..a9faafefa 100644 --- a/spec/classes/mysql_server_spec.rb +++ b/spec/classes/mysql_server_spec.rb @@ -7,18 +7,18 @@ let(:facts) { facts } context 'with defaults' do - it { should contain_class('mysql::server::install') } - it { should contain_class('mysql::server::config') } - it { should contain_class('mysql::server::service') } - it { should contain_class('mysql::server::root_password') } - it { should contain_class('mysql::server::providers') } + it { is_expected.to contain_class('mysql::server::install') } + it { is_expected.to contain_class('mysql::server::config') } + it { is_expected.to contain_class('mysql::server::service') } + it { is_expected.to contain_class('mysql::server::root_password') } + it { is_expected.to contain_class('mysql::server::providers') } end # make sure that overriding the mysqld settings keeps the defaults for everything else context 'with overrides' do let(:params) {{ :override_options => { 'mysqld' => { 'socket' => '/var/lib/mysql/mysql.sock' } } }} it do - should contain_file('mysql-config-file').with({ + is_expected.to contain_file('mysql-config-file').with({ :mode => '0644', }).with_content(/basedir/) end @@ -27,7 +27,7 @@ describe 'with multiple instance of an option' do let(:params) {{ :override_options => { 'mysqld' => { 'replicate-do-db' => ['base1', 'base2', 'base3'], } }}} it do - should contain_file('mysql-config-file').with_content( + is_expected.to contain_file('mysql-config-file').with_content( /^replicate-do-db = base1$/ ).with_content( /^replicate-do-db = base2$/ @@ -42,7 +42,7 @@ { :override_options => { 'mysqld' => { 'ssl' => true } }} } it do - should contain_file('mysql-config-file').with_content(/^\s*ssl\s*(?:$|= true)/m) + is_expected.to contain_file('mysql-config-file').with_content(/^\s*ssl\s*(?:$|= true)/m) end end @@ -51,13 +51,13 @@ { :override_options => { 'mysqld' => { 'ssl' => false } }} } it do - should contain_file('mysql-config-file').with_content(/^\s*ssl = false/m) + is_expected.to contain_file('mysql-config-file').with_content(/^\s*ssl = false/m) end end context 'with remove_default_accounts set' do let (:params) {{ :remove_default_accounts => true }} - it { should contain_class('mysql::server::account_security') } + it { is_expected.to contain_class('mysql::server::account_security') } end describe 'possibility of disabling ssl completely' do @@ -65,14 +65,14 @@ { :override_options => { 'mysqld' => { 'ssl' => true, 'ssl-disable' => true } }} } it do - should contain_file('mysql-config-file').without_content(/^\s*ssl\s*(?:$|= true)/m) + is_expected.to contain_file('mysql-config-file').without_content(/^\s*ssl\s*(?:$|= true)/m) end end context 'mysql::server::install' do let(:params) {{ :package_ensure => 'present', :name => 'mysql-server' }} it do - should contain_package('mysql-server').with({ + is_expected.to contain_package('mysql-server').with({ :ensure => :present, :name => 'mysql-server', }) @@ -83,7 +83,7 @@ context 'mysql::server::install on RHEL 7' do let(:params) {{ :package_ensure => 'present', :name => 'mariadb-server' }} it do - should contain_package('mysql-server').with({ + is_expected.to contain_package('mysql-server').with({ :ensure => :present, :name => 'mariadb-server', }) @@ -95,54 +95,54 @@ context 'with includedir' do let(:params) {{ :includedir => '/etc/my.cnf.d' }} it do - should contain_file('/etc/my.cnf.d').with({ + is_expected.to contain_file('/etc/my.cnf.d').with({ :ensure => :directory, :mode => '0755', }) end it do - should contain_file('mysql-config-file').with({ + is_expected.to contain_file('mysql-config-file').with({ :mode => '0644', }) end it do - should contain_file('mysql-config-file').with_content(/!includedir/) + is_expected.to contain_file('mysql-config-file').with_content(/!includedir/) end end context 'without includedir' do let(:params) {{ :includedir => '' }} it do - should_not contain_file('mysql-config-file').with({ + is_expected.not_to contain_file('mysql-config-file').with({ :ensure => :directory, :mode => '0755', }) end it do - should contain_file('mysql-config-file').with({ + is_expected.to contain_file('mysql-config-file').with({ :mode => '0644', }) end it do - should contain_file('mysql-config-file').without_content(/!includedir/) + is_expected.to contain_file('mysql-config-file').without_content(/!includedir/) end end end context 'mysql::server::service' do context 'with defaults' do - it { should contain_service('mysqld') } + it { is_expected.to contain_service('mysqld') } end context 'service_enabled set to false' do let(:params) {{ :service_enabled => false }} it do - should contain_service('mysqld').with({ + is_expected.to contain_service('mysqld').with({ :ensure => :stopped }) end @@ -151,13 +151,13 @@ context 'mysql::server::root_password' do describe 'when defaults' do - it { should_not contain_mysql_user('root@localhost') } - it { should_not contain_file('/root/.my.cnf') } + it { is_expected.not_to contain_mysql_user('root@localhost') } + it { is_expected.not_to contain_file('/root/.my.cnf') } end describe 'when set' do let(:params) {{:root_password => 'SET' }} - it { should contain_mysql_user('root@localhost') } - it { should contain_file('/root/.my.cnf') } + it { is_expected.to contain_mysql_user('root@localhost') } + it { is_expected.to contain_file('/root/.my.cnf') } end end @@ -174,14 +174,14 @@ }, 'foo2@localhost' => {} }}} - it { should contain_mysql_user('foo@localhost').with( + it { is_expected.to contain_mysql_user('foo@localhost').with( :max_connections_per_hour => '1', :max_queries_per_hour => '2', :max_updates_per_hour => '3', :max_user_connections => '4', :password_hash => '*F3A2A51A9B0F2BE2468926B4132313728C250DBF' )} - it { should contain_mysql_user('foo2@localhost').with( + it { is_expected.to contain_mysql_user('foo2@localhost').with( :max_connections_per_hour => nil, :max_queries_per_hour => nil, :max_updates_per_hour => nil, @@ -204,13 +204,13 @@ 'privileges' => ["SELECT"], }, }}} - it { should contain_mysql_grant('foo@localhost/somedb.*').with( + it { is_expected.to contain_mysql_grant('foo@localhost/somedb.*').with( :user => 'foo@localhost', :table => 'somedb.*', :privileges => ["SELECT", "UPDATE"], :options => ["GRANT"] )} - it { should contain_mysql_grant('foo2@localhost/*.*').with( + it { is_expected.to contain_mysql_grant('foo2@localhost/*.*').with( :user => 'foo2@localhost', :table => '*.*', :privileges => ["SELECT"], @@ -226,11 +226,11 @@ }, 'somedb2' => {} }}} - it { should contain_mysql_database('somedb').with( + it { is_expected.to contain_mysql_database('somedb').with( :charset => 'latin1', :collate => 'latin1' )} - it { should contain_mysql_database('somedb2')} + it { is_expected.to contain_mysql_database('somedb2')} end end end diff --git a/spec/defines/mysql_db_spec.rb b/spec/defines/mysql_db_spec.rb index 01ec80733..15f433bb5 100644 --- a/spec/defines/mysql_db_spec.rb +++ b/spec/defines/mysql_db_spec.rb @@ -17,33 +17,33 @@ end it 'should not notify the import sql exec if no sql script was provided' do - should contain_mysql_database('test_db').without_notify + is_expected.to contain_mysql_database('test_db').without_notify end it 'should subscribe to database if sql script is given' do params.merge!({'sql' => 'test_sql'}) - should contain_exec('test_db-import').with_subscribe('Mysql_database[test_db]') + is_expected.to contain_exec('test_db-import').with_subscribe('Mysql_database[test_db]') end it 'should only import sql script on creation if not enforcing' do params.merge!({'sql' => 'test_sql', 'enforce_sql' => false}) - should contain_exec('test_db-import').with_refreshonly(true) + is_expected.to contain_exec('test_db-import').with_refreshonly(true) end it 'should import sql script on creation if enforcing' do params.merge!({'sql' => 'test_sql', 'enforce_sql' => true}) - should contain_exec('test_db-import').with_refreshonly(false) + is_expected.to contain_exec('test_db-import').with_refreshonly(false) end it 'should not create database and database user' do params.merge!({'ensure' => 'absent', 'host' => 'localhost'}) - should contain_mysql_database('test_db').with_ensure('absent') - should contain_mysql_user('testuser@localhost').with_ensure('absent') + is_expected.to contain_mysql_database('test_db').with_ensure('absent') + is_expected.to contain_mysql_user('testuser@localhost').with_ensure('absent') end it 'should create with an appropriate collate and charset' do params.merge!({'charset' => 'utf8', 'collate' => 'utf8_danish_ci'}) - should contain_mysql_database('test_db').with({ + is_expected.to contain_mysql_database('test_db').with({ 'charset' => 'utf8', 'collate' => 'utf8_danish_ci', }) @@ -51,6 +51,6 @@ it 'should use dbname parameter as database name instead of name' do params.merge!({'dbname' => 'real_db'}) - should contain_mysql_database('real_db') + is_expected.to contain_mysql_database('real_db') end end diff --git a/spec/unit/puppet/functions/mysql_deepmerge_spec.rb b/spec/unit/puppet/functions/mysql_deepmerge_spec.rb index fa9c72b78..18cb26bfa 100644 --- a/spec/unit/puppet/functions/mysql_deepmerge_spec.rb +++ b/spec/unit/puppet/functions/mysql_deepmerge_spec.rb @@ -7,7 +7,7 @@ describe 'when calling mysql_deepmerge from puppet' do it "should not compile when no arguments are passed" do - pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ + skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ Puppet[:code] = '$x = mysql_deepmerge()' expect { scope.compiler.compile @@ -15,7 +15,7 @@ end it "should not compile when 1 argument is passed" do - pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ + skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ Puppet[:code] = "$my_hash={'one' => 1}\n$x = mysql_deepmerge($my_hash)" expect { scope.compiler.compile @@ -35,57 +35,57 @@ it 'should be able to mysql_deepmerge two hashes' do new_hash = scope.function_mysql_deepmerge([{'one' => '1', 'two' => '1'}, {'two' => '2', 'three' => '2'}]) - new_hash['one'].should == '1' - new_hash['two'].should == '2' - new_hash['three'].should == '2' + expect(new_hash['one']).to eq('1') + expect(new_hash['two']).to eq('2') + expect(new_hash['three']).to eq('2') end it 'should mysql_deepmerge multiple hashes' do hash = scope.function_mysql_deepmerge([{'one' => 1}, {'one' => '2'}, {'one' => '3'}]) - hash['one'].should == '3' + expect(hash['one']).to eq('3') end it 'should accept empty hashes' do - scope.function_mysql_deepmerge([{},{},{}]).should == {} + expect(scope.function_mysql_deepmerge([{},{},{}])).to eq({}) end it 'should mysql_deepmerge subhashes' do hash = scope.function_mysql_deepmerge([{'one' => 1}, {'two' => 2, 'three' => { 'four' => 4 } }]) - hash['one'].should == 1 - hash['two'].should == 2 - hash['three'].should == { 'four' => 4 } + expect(hash['one']).to eq(1) + expect(hash['two']).to eq(2) + expect(hash['three']).to eq({ 'four' => 4 }) end it 'should append to subhashes' do hash = scope.function_mysql_deepmerge([{'one' => { 'two' => 2 } }, { 'one' => { 'three' => 3 } }]) - hash['one'].should == { 'two' => 2, 'three' => 3 } + expect(hash['one']).to eq({ 'two' => 2, 'three' => 3 }) end it 'should append to subhashes 2' do hash = scope.function_mysql_deepmerge([{'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } }, {'two' => 'dos', 'three' => { 'five' => 5 } }]) - hash['one'].should == 1 - hash['two'].should == 'dos' - hash['three'].should == { 'four' => 4, 'five' => 5 } + expect(hash['one']).to eq(1) + expect(hash['two']).to eq('dos') + expect(hash['three']).to eq({ 'four' => 4, 'five' => 5 }) end it 'should append to subhashes 3' do hash = scope.function_mysql_deepmerge([{ 'key1' => { 'a' => 1, 'b' => 2 }, 'key2' => { 'c' => 3 } }, { 'key1' => { 'b' => 99 } }]) - hash['key1'].should == { 'a' => 1, 'b' => 99 } - hash['key2'].should == { 'c' => 3 } + expect(hash['key1']).to eq({ 'a' => 1, 'b' => 99 }) + expect(hash['key2']).to eq({ 'c' => 3 }) end it 'should equate keys mod dash and underscore' do hash = scope.function_mysql_deepmerge([{ 'a-b-c' => 1 } , { 'a_b_c' => 10 }]) - hash['a_b_c'].should == 10 - hash.should_not have_key('a-b-c') + expect(hash['a_b_c']).to eq(10) + expect(hash).not_to have_key('a-b-c') end it 'should keep style of the last when keys are euqal mod dash and underscore' do hash = scope.function_mysql_deepmerge([{ 'a-b-c' => 1, 'b_c_d' => { 'c-d-e' => 2, 'e-f-g' => 3 }} , { 'a_b_c' => 10, 'b-c-d' => { 'c_d_e' => 12 } }]) - hash['a_b_c'].should == 10 - hash.should_not have_key('a-b-c') - hash['b-c-d'].should == { 'e-f-g' => 3, 'c_d_e' => 12 } - hash.should_not have_key('b_c_d') + expect(hash['a_b_c']).to eq(10) + expect(hash).not_to have_key('a-b-c') + expect(hash['b-c-d']).to eq({ 'e-f-g' => 3, 'c_d_e' => 12 }) + expect(hash).not_to have_key('b_c_d') end end end diff --git a/spec/unit/puppet/functions/mysql_password_spec.rb b/spec/unit/puppet/functions/mysql_password_spec.rb index 073691004..77726d13f 100644 --- a/spec/unit/puppet/functions/mysql_password_spec.rb +++ b/spec/unit/puppet/functions/mysql_password_spec.rb @@ -8,20 +8,20 @@ let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it 'should exist' do - Puppet::Parser::Functions.function('mysql_password').should == 'function_mysql_password' + expect(Puppet::Parser::Functions.function('mysql_password')).to eq('function_mysql_password') end it 'should raise a ParseError if there is less than 1 arguments' do - lambda { scope.function_mysql_password([]) }.should( raise_error(Puppet::ParseError)) + expect { scope.function_mysql_password([]) }.to( raise_error(Puppet::ParseError)) end it 'should raise a ParseError if there is more than 1 arguments' do - lambda { scope.function_mysql_password(%w(foo bar)) }.should( raise_error(Puppet::ParseError)) + expect { scope.function_mysql_password(%w(foo bar)) }.to( raise_error(Puppet::ParseError)) end it 'should convert password into a hash' do result = scope.function_mysql_password(%w(password)) - result.should(eq('*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19')) + expect(result).to(eq('*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19')) end end diff --git a/spec/unit/puppet/provider/mysql_database/mysql_spec.rb b/spec/unit/puppet/provider/mysql_database/mysql_spec.rb index 4bc24b46c..d97f2535f 100644 --- a/spec/unit/puppet/provider/mysql_database/mysql_spec.rb +++ b/spec/unit/puppet/provider/mysql_database/mysql_spec.rb @@ -43,7 +43,7 @@ provider.class.stubs(:mysql).with([defaults_file, '-NBe', "show variables like '%_database'", db.chomp]).returns("character_set_database latin1\ncollation_database latin1_swedish_ci\nskip_show_database OFF") end databases = provider.class.instances.collect {|x| x.name } - parsed_databases.should match_array(databases) + expect(parsed_databases).to match_array(databases) end end @@ -58,7 +58,7 @@ it 'makes a database' do provider.expects(:mysql).with([defaults_file, '-NBe', "create database if not exists `#{resource[:name]}` character set #{resource[:charset]} collate #{resource[:collate]}"]) provider.expects(:exists?).returns(true) - provider.create.should be_truthy + expect(provider.create).to be_truthy end end @@ -66,30 +66,30 @@ it 'removes a database if present' do provider.expects(:mysql).with([defaults_file, '-NBe', "drop database if exists `#{resource[:name]}`"]) provider.expects(:exists?).returns(false) - provider.destroy.should be_truthy + expect(provider.destroy).to be_truthy end end describe 'exists?' do it 'checks if database exists' do - instance.exists?.should be_truthy + expect(instance.exists?).to be_truthy end end describe 'self.defaults_file' do it 'sets --defaults-extra-file' do File.stubs(:file?).with('/root/.my.cnf').returns(true) - provider.defaults_file.should eq '--defaults-extra-file=/root/.my.cnf' + expect(provider.defaults_file).to eq '--defaults-extra-file=/root/.my.cnf' end it 'fails if file missing' do File.stubs(:file?).with('/root/.my.cnf').returns(false) - provider.defaults_file.should be_nil + expect(provider.defaults_file).to be_nil end end describe 'charset' do it 'returns a charset' do - instance.charset.should == 'latin1' + expect(instance.charset).to eq('latin1') end end @@ -103,7 +103,7 @@ describe 'collate' do it 'returns a collate' do - instance.collate.should == 'latin1_swedish_ci' + expect(instance.collate).to eq('latin1_swedish_ci') end end diff --git a/spec/unit/puppet/provider/mysql_user/mysql_spec.rb b/spec/unit/puppet/provider/mysql_user/mysql_spec.rb index 50f0c3bd2..dacbae4b0 100644 --- a/spec/unit/puppet/provider/mysql_user/mysql_spec.rb +++ b/spec/unit/puppet/provider/mysql_user/mysql_spec.rb @@ -50,7 +50,7 @@ end usernames = provider.class.instances.collect {|x| x.name } - parsed_users.should match_array(usernames) + expect(parsed_users).to match_array(usernames) end end @@ -65,7 +65,7 @@ it 'makes a user' do provider.expects(:mysql).with([defaults_file, '-e', "GRANT USAGE ON *.* TO 'joe'@'localhost' IDENTIFIED BY PASSWORD '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4' WITH MAX_USER_CONNECTIONS 10 MAX_CONNECTIONS_PER_HOUR 10 MAX_QUERIES_PER_HOUR 10 MAX_UPDATES_PER_HOUR 10"]) provider.expects(:exists?).returns(true) - provider.create.should be_truthy + expect(provider.create).to be_truthy end end @@ -73,30 +73,30 @@ it 'removes a user if present' do provider.expects(:mysql).with([defaults_file, '-e', "DROP USER 'joe'@'localhost'"]) provider.expects(:exists?).returns(false) - provider.destroy.should be_truthy + expect(provider.destroy).to be_truthy end end describe 'exists?' do it 'checks if user exists' do - instance.exists?.should be_truthy + expect(instance.exists?).to be_truthy end end describe 'self.defaults_file' do it 'sets --defaults-extra-file' do File.stubs(:file?).with('/root/.my.cnf').returns(true) - provider.defaults_file.should eq '--defaults-extra-file=/root/.my.cnf' + expect(provider.defaults_file).to eq '--defaults-extra-file=/root/.my.cnf' end it 'fails if file missing' do File.expects(:file?).with('/root/.my.cnf').returns(false) - provider.defaults_file.should be_nil + expect(provider.defaults_file).to be_nil end end describe 'password_hash' do it 'returns a hash' do - instance.password_hash.should == '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4' + expect(instance.password_hash).to eq('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4') end end @@ -114,7 +114,7 @@ describe property do it "returns #{property}" do - instance.send("#{property}".to_sym).should == '10' + expect(instance.send("#{property}".to_sym)).to eq('10') end end diff --git a/spec/unit/puppet/type/mysql_database_spec.rb b/spec/unit/puppet/type/mysql_database_spec.rb index e2ebd90d4..7897d8109 100644 --- a/spec/unit/puppet/type/mysql_database_spec.rb +++ b/spec/unit/puppet/type/mysql_database_spec.rb @@ -7,17 +7,17 @@ end it 'should accept a database name' do - @user[:name].should == 'test' + expect(@user[:name]).to eq('test') end it 'should accept a charset' do @user[:charset] = 'latin1' - @user[:charset].should == 'latin1' + expect(@user[:charset]).to eq('latin1') end it 'should accept a collate' do @user[:collate] = 'latin1_swedish_ci' - @user[:collate].should == 'latin1_swedish_ci' + expect(@user[:collate]).to eq('latin1_swedish_ci') end it 'should require a name' do diff --git a/spec/unit/puppet/type/mysql_grant_spec.rb b/spec/unit/puppet/type/mysql_grant_spec.rb index 4171ab28e..73e0e954a 100644 --- a/spec/unit/puppet/type/mysql_grant_spec.rb +++ b/spec/unit/puppet/type/mysql_grant_spec.rb @@ -7,32 +7,32 @@ end it 'should accept a grant name' do - @user[:name].should == 'foo@localhost/*.*' + expect(@user[:name]).to eq('foo@localhost/*.*') end it 'should accept ALL privileges' do @user[:privileges] = 'ALL' - @user[:privileges].should == ['ALL'] + expect(@user[:privileges]).to eq(['ALL']) end it 'should accept PROXY privilege' do @user[:privileges] = 'PROXY' - @user[:privileges].should == ['PROXY'] + expect(@user[:privileges]).to eq(['PROXY']) end it 'should accept a table' do @user[:table] = '*.*' - @user[:table].should == '*.*' + expect(@user[:table]).to eq('*.*') end it 'should accept @ for table' do @user[:table] = '@' - @user[:table].should == '@' + expect(@user[:table]).to eq('@') end it 'should accept a user' do @user[:user] = 'foo@localhost' - @user[:user].should == 'foo@localhost' + expect(@user[:user]).to eq('foo@localhost') end it 'should require a name' do diff --git a/spec/unit/puppet/type/mysql_user_spec.rb b/spec/unit/puppet/type/mysql_user_spec.rb index 7ffc801b6..f66741c99 100644 --- a/spec/unit/puppet/type/mysql_user_spec.rb +++ b/spec/unit/puppet/type/mysql_user_spec.rb @@ -20,12 +20,12 @@ end it 'should accept a user name' do - @user[:name].should == 'foo@localhost' + expect(@user[:name]).to eq('foo@localhost') end it 'should accept a password' do @user[:password_hash] = 'foo' - @user[:password_hash].should == 'foo' + expect(@user[:password_hash]).to eq('foo') end end @@ -35,7 +35,7 @@ end it 'should lowercase the user name' do - @user[:name].should == 'foo@localhost' + expect(@user[:name]).to eq('foo@localhost') end end