Class: CommitLive::Test
- Inherits:
-
Object
- Object
- CommitLive::Test
- Defined in:
- lib/commit-live/tests/runner.rb
Constant Summary collapse
- HOME_DIR =
File.("~")
- REPO_BELONGS_TO_US =
[ 'commit-live-students' ]
Instance Attribute Summary collapse
-
#git ⇒ Object
readonly
Returns the value of attribute git.
-
#lesson ⇒ Object
readonly
Returns the value of attribute lesson.
-
#rootDir ⇒ Object
readonly
Returns the value of attribute rootDir.
-
#sentry ⇒ Object
readonly
Returns the value of attribute sentry.
-
#track_slug ⇒ Object
readonly
Returns the value of attribute track_slug.
Instance Method Summary collapse
- #check_lesson_dir ⇒ Object
- #clear_changes_in_tests ⇒ Object
- #dir_path ⇒ Object
-
#initialize(trackSlug) ⇒ Test
constructor
A new instance of Test.
- #is_practice ⇒ Object
- #is_project ⇒ Object
- #is_project_assignment ⇒ Object
- #lesson_name ⇒ Object
- #put_error_msg ⇒ Object
- #repo_name(remote: remote_name) ⇒ Object
- #run(updateStatus = true) ⇒ Object
- #set_git ⇒ Object
- #strategy ⇒ Object
- #test_case_dir_path ⇒ Object
- #test_slug ⇒ Object
- #title_slug ⇒ Object
Constructor Details
#initialize(trackSlug) ⇒ Test
Returns a new instance of Test.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/commit-live/tests/runner.rb', line 20 def initialize(trackSlug) @track_slug = trackSlug check_lesson_dir check_if_practice_lesson check_if_user_in_right_folder die if !strategy @sentry = CommitLive::Sentry.new() if File.exists?("#{HOME_DIR}/.ga-config") @rootDir = YAML.load(File.read("#{HOME_DIR}/.ga-config"))[:workspace] end end |
Instance Attribute Details
#git ⇒ Object (readonly)
Returns the value of attribute git.
13 14 15 |
# File 'lib/commit-live/tests/runner.rb', line 13 def git @git end |
#lesson ⇒ Object (readonly)
Returns the value of attribute lesson.
13 14 15 |
# File 'lib/commit-live/tests/runner.rb', line 13 def lesson @lesson end |
#rootDir ⇒ Object (readonly)
Returns the value of attribute rootDir.
13 14 15 |
# File 'lib/commit-live/tests/runner.rb', line 13 def rootDir @rootDir end |
#sentry ⇒ Object (readonly)
Returns the value of attribute sentry.
13 14 15 |
# File 'lib/commit-live/tests/runner.rb', line 13 def sentry @sentry end |
#track_slug ⇒ Object (readonly)
Returns the value of attribute track_slug.
13 14 15 |
# File 'lib/commit-live/tests/runner.rb', line 13 def track_slug @track_slug end |
Instance Method Details
#check_lesson_dir ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/commit-live/tests/runner.rb', line 40 def check_lesson_dir @git = set_git netrc = CommitLive::NetrcInteractor.new() netrc.read(machine: 'ga-extra') username = netrc.login if git.remote.url.match(/#{username}/i).nil? && git.remote.url.match(/#{REPO_BELONGS_TO_US.join('|').gsub('-','\-')}/i).nil? put_error_msg end end |
#clear_changes_in_tests ⇒ Object
95 96 97 |
# File 'lib/commit-live/tests/runner.rb', line 95 def clear_changes_in_tests system("git checkout HEAD -- #{test_case_dir_path}") end |
#dir_path ⇒ Object
99 100 101 102 103 |
# File 'lib/commit-live/tests/runner.rb', line 99 def dir_path filePath = "#{title_slug}/" filePath += "#{test_slug}/" if is_project_assignment return filePath end |
#is_practice ⇒ Object
130 131 132 133 |
# File 'lib/commit-live/tests/runner.rb', line 130 def is_practice lessonType = lesson.getValue('type') !lessonType.nil? && lessonType == "PRACTICE" end |
#is_project ⇒ Object
125 126 127 128 |
# File 'lib/commit-live/tests/runner.rb', line 125 def is_project isProject = lesson.getValue('isProject') !isProject.nil? && isProject == 1 end |
#is_project_assignment ⇒ Object
120 121 122 123 |
# File 'lib/commit-live/tests/runner.rb', line 120 def is_project_assignment isProjectAssignment = lesson.getValue('isProjectAssignment') !isProjectAssignment.nil? && isProjectAssignment == 1 end |
#lesson_name ⇒ Object
55 56 57 |
# File 'lib/commit-live/tests/runner.rb', line 55 def lesson_name repo_name(remote: 'origin') end |
#put_error_msg ⇒ Object
59 60 61 62 63 |
# File 'lib/commit-live/tests/runner.rb', line 59 def put_error_msg puts "It doesn't look like you're in a lesson directory." puts 'Please cd into an appropriate directory and try again.' exit 1 end |
#repo_name(remote: remote_name) ⇒ Object
50 51 52 53 |
# File 'lib/commit-live/tests/runner.rb', line 50 def repo_name(remote: remote_name) url = git.remote(remote).url url.match(/^.+[\w-]+\/(.*?)(?:\.git)?$/)[1] end |
#run(updateStatus = true) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/commit-live/tests/runner.rb', line 65 def run(updateStatus = true) clear_changes_in_tests puts 'Testing lesson...' strategy.check_dependencies strategy.configure results = strategy.run(test_case_dir_path) if strategy.results strategy.print_results end file_path = "#{rootDir}/#{dir_path}/build.py" if updateStatus && strategy.results if results # test case passed puts 'Great! You have passed all the test cases.' puts 'Use `clive submit` to push your changes.' CommitLive::Status.new().update('testCasesPassed', track_slug, true, strategy.results, file_path) else # test case failed puts 'Oops! You still have to pass all the test cases.' CommitLive::Status.new().update('testCasesFailed', track_slug, true, strategy.results, file_path) end end strategy.cleanup return results end |
#set_git ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/commit-live/tests/runner.rb', line 32 def set_git begin Git.open(FileUtils.pwd) rescue => e put_error_msg end end |
#strategy ⇒ Object
91 92 93 |
# File 'lib/commit-live/tests/runner.rb', line 91 def strategy @strategy ||= strategies.map{ |s| s.new() }.detect(&:detect) end |
#test_case_dir_path ⇒ Object
105 106 107 108 109 110 |
# File 'lib/commit-live/tests/runner.rb', line 105 def test_case_dir_path filePath = "" filePath += "#{test_slug}/" if is_project_assignment filePath += "tests/" return filePath end |
#test_slug ⇒ Object
112 113 114 |
# File 'lib/commit-live/tests/runner.rb', line 112 def test_slug lesson.getValue('testCase') end |
#title_slug ⇒ Object
116 117 118 |
# File 'lib/commit-live/tests/runner.rb', line 116 def title_slug lesson.getValue('titleSlug') end |