spec/support/macros/path_helpers.rb in daigaku-0.0.2 vs spec/support/macros/path_helpers.rb in daigaku-0.1.0

- old
+ new

@@ -3,12 +3,12 @@ CONFIGURATION_FILE = 'daigaku.settings' COURSES = 'courses' SOLUTIONS = 'solutions' TEMP_PATH = File.expand_path("../../../../tmp/", __FILE__) COURSE_DIR_NAMES = ['Course_A', 'Course_B'] - CHAPTER_DIR_NAMES = ['Chapter-1', 'Chapter-2'] - UNIT_DIR_NAMES = ['unit-1', 'unit-2'] + CHAPTER_DIR_NAMES = ['1_Chapter-A', '2_Chapter-B'] + UNIT_DIR_NAMES = ['1_unit-a', '2_unit-b'] TASK_NAME = 'task.md' REFERENCE_SOLUTION_NAME = 'solution.rb' TEST_NAME = 'solution_spec.rb' STORAGE_FILE = 'daigaku.db.yml' @@ -43,11 +43,11 @@ def test_name TEST_NAME end def courses_basepath - File.join(test_basepath, COURSES) + File.join(test_basepath, LOCAL_DIR, COURSES) end def solutions_basepath File.join(test_basepath, SOLUTIONS) end @@ -84,14 +84,20 @@ dirs.flatten end def all_solution_file_paths all_unit_dirs.map do |unit_dir| - underscored_unit_dir = File.basename(unit_dir).gsub(/(\_+|\-+|\.+)/, '_') - file_name = underscored_unit_dir + Daigaku::Generator::SOLUTION_SUFFIX + underscored_unit_dir = File.basename(unit_dir).gsub(/[\_\-\.]+/, '_') + file_name = underscored_unit_dir + Daigaku::Solution::FILE_SUFFIX + unit_path = File.join(solutions_basepath, unit_dir.split('/')[-3..-1]) + parts = File.join(File.dirname(unit_path), file_name).split('/') - File.join(File.dirname(unit_path), file_name) + course_parts = parts[-3..-1].map do |part| + part.gsub(/^[\d]+\_/, '').gsub(/[\_\-]+/, '_').downcase + end + + [*parts[0...-3], *course_parts].join('/') end end def all_test_file_paths all_unit_dirs.map do |unit_dir|