spec/spec_helper.rb in ridgepole-0.7.3.beta vs spec/spec_helper.rb in ridgepole-0.7.3.beta2

- old
+ new

@@ -1,6 +1,6 @@ -$: << File.expand_path('..', __FILE__) +$LOAD_PATH << File.expand_path(__dir__) require 'spec_const' require 'spec_condition' require 'cli_helper' require 'hide_pending_formatter' @@ -33,12 +33,14 @@ Ridgepole::Logger.instance.level = ::Logger::ERROR end end config.before(:each) do |example| - if conds = example.metadata[:condition] - skip unless Array(conds).any? {|c| condition(*c) } + conds = example.metadata[:condition] + + if conds + skip unless Array(conds).any? { |c| condition(*c) } end case example.metadata[:file_path] when /mysql57/ skip unless condition(:mysql57) @@ -60,22 +62,20 @@ restore_database_mysql end end def system_raise_on_fail(*args) - unless system(*args) - raise "Failed to run: #{args}" - end + raise "Failed to run: #{args}" unless system(*args) end def restore_database_mysql - sql_file = File.expand_path('../mysql/ridgepole_test_database.sql', __FILE__) + sql_file = File.expand_path('mysql/ridgepole_test_database.sql', __dir__) system_raise_on_fail("#{MYSQL_CLI} < #{sql_file}") end def restore_database_postgresql - sql_file = File.expand_path('../postgresql/ridgepole_test_database.sql', __FILE__) + sql_file = File.expand_path('postgresql/ridgepole_test_database.sql', __dir__) system("#{PG_CREATEDB} ridgepole_test 2>/dev/null") system_raise_on_fail("#{PG_PSQL} ridgepole_test --set ON_ERROR_STOP=off -q -f #{sql_file} 2>/dev/null") end def restore_tables @@ -85,27 +85,27 @@ restore_tables_mysql end end def restore_tables_mysql - sql_file = File.expand_path('../mysql/ridgepole_test_tables.sql', __FILE__) + sql_file = File.expand_path('mysql/ridgepole_test_tables.sql', __dir__) system_raise_on_fail("#{MYSQL_CLI} < #{sql_file}") end def restore_tables_postgresql - sql_file = File.expand_path('../postgresql/ridgepole_test_tables.sql', __FILE__) + sql_file = File.expand_path('postgresql/ridgepole_test_tables.sql', __dir__) system_raise_on_fail("#{PG_PSQL} ridgepole_test -q -f #{sql_file} 2>/dev/null") end def restore_tables_mysql_unknown_column_type - sql_file = File.expand_path('../mysql/ridgepole_test_tables_unknown_column_type.sql', __FILE__) + sql_file = File.expand_path('mysql/ridgepole_test_tables_unknown_column_type.sql', __dir__) system_raise_on_fail("#{MYSQL_CLI} < #{sql_file}") end def client(options = {}, config = {}) config = conn_spec(config) - default_options = {debug: condition(:debug)} + default_options = { debug: condition(:debug) } default_options[:dump_without_table_options] = true options = default_options.merge(options) Ridgepole::Client.new(config, options) @@ -117,20 +117,20 @@ adapter: 'postgresql', database: TEST_SCHEMA, host: TEST_PG_HOST, port: TEST_PG_PORT, username: TEST_PG_USER, - password: TEST_PG_PASS, + password: TEST_PG_PASS }.merge(config) else { adapter: 'mysql2', database: TEST_SCHEMA, host: TEST_MYSQL_HOST, port: TEST_MYSQL_PORT, username: TEST_MYSQL_USER, - password: TEST_MYSQL_PASS, + password: TEST_MYSQL_PASS }.merge(config) end end def show_create_table(table_name) @@ -149,21 +149,19 @@ def show_create_table_postgresql(table_name) `#{PG_DUMP} --schema-only #{TEST_SCHEMA} --table=#{table_name} | awk '/^CREATE TABLE/,/);/{print} /^CREATE INDEX/{print}'`.strip end def tempfile(basename, content = '') - begin - path = `mktemp /tmp/#{basename}.XXXXXX` - open(path, 'wb') {|f| f << content } - FileUtils.chmod(0777, path) - yield(path) - ensure - FileUtils.rm_f(path) if path - end + path = `mktemp /tmp/#{basename}.XXXXXX` + File.open(path, 'wb') { |f| f << content } + FileUtils.chmod(0o777, path) + yield(path) + ensure + FileUtils.rm_f(path) if path end def run_ridgepole(*args) - Dir.chdir(File.expand_path('../..', __FILE__)) do + Dir.chdir(File.expand_path('..', __dir__)) do cmd = [:bundle, :exec, './bin/ridgepole'] + args Open3.capture2e(cmd.join(' ')) end end end