module RSpec::Rails module Migration include RSpec::Rails::App::Dirs def create_migration number, name, &block file = migration_file_name(number, name) unless File.exist?(file) FileUtils.mkdir_p File.dirname(file) File.open(file, 'w') do |f| f.puts file_content(name) yield f if block_given? end end end def remove_migration name migrations = Dir.glob("#{migration_dir}/[0-9]*_*.rb") migration_file = if !migrations.empty? migrations.grep(/\d+_#{name}\.rb$/).first else false end FileUtils.rm_f(migration_file) if migration_file end def remove_migrations *names names.each do |name| remove_migration name end end def migration_file_name number, name File.join(migration_dir, "#{number}_#{name}.rb") end end end