Class: SpecMigration
- Inherits:
-
Object
- Object
- SpecMigration
- Defined in:
- lib/r2m/spec_migration.rb
Overview
rubocop:todo Style/Documentation
Instance Method Summary collapse
-
#initialize(basedir) ⇒ SpecMigration
constructor
A new instance of SpecMigration.
-
#migrate(spec_file) ⇒ Object
rubocop:todo Metrics/AbcSize.
- #move_and_rename_spec_to_test(spec_file) ⇒ Object
- #split_path(file) ⇒ Object
Constructor Details
#initialize(basedir) ⇒ SpecMigration
Returns a new instance of SpecMigration.
6 7 8 |
# File 'lib/r2m/spec_migration.rb', line 6 def initialize(basedir) @basedir = Pathname(basedir) end |
Instance Method Details
#migrate(spec_file) ⇒ Object
rubocop:todo Metrics/AbcSize
10 11 12 |
# File 'lib/r2m/spec_migration.rb', line 10 def migrate(spec_file) # rubocop:todo Metrics/AbcSize move_and_rename_spec_to_test(spec_file) end |
#move_and_rename_spec_to_test(spec_file) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/r2m/spec_migration.rb', line 22 def move_and_rename_spec_to_test(spec_file) relative_path, spec_basename = split_path(spec_file) test_root = @basedir / 'test' test_dirname = test_root + relative_path FileUtils.mkdir_p test_dirname test_basename = spec_basename.sub(/_spec(?=\.rb)/, '_test') test_file = test_dirname + test_basename FileUtils.cp spec_file, test_file unless test_file.exist? test_file end |
#split_path(file) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/r2m/spec_migration.rb', line 14 def split_path(file) spec_root = @basedir / 'spec' dirname, basename = Pathname(file).split relative_path = dirname.relative_path_from(spec_root) [relative_path, basename] end |