Class: CommitLive::Test
- Inherits:
-
Object
- Object
- CommitLive::Test
- Defined in:
- lib/commit-live/tests/runner.rb
Constant Summary collapse
- REPO_BELONGS_TO_US =
[ 'commit-live-students' ]
Instance Attribute Summary collapse
-
#git ⇒ Object
readonly
Returns the value of attribute git.
-
#sentry ⇒ Object
readonly
Returns the value of attribute sentry.
Instance Method Summary collapse
- #check_lesson_dir ⇒ Object
- #clear_changes_in_tests ⇒ Object
-
#initialize ⇒ Test
constructor
A new instance of Test.
- #lesson_name ⇒ Object
- #put_error_msg ⇒ Object
- #repo_name(remote: remote_name) ⇒ Object
- #run(updateStatus = true) ⇒ Object
- #set_git ⇒ Object
- #strategy ⇒ Object
Constructor Details
#initialize ⇒ Test
Returns a new instance of Test.
18 19 20 21 22 23 |
# File 'lib/commit-live/tests/runner.rb', line 18 def initialize() check_lesson_dir check_if_practice_lesson die if !strategy @sentry = CommitLive::Sentry.new() end |
Instance Attribute Details
#git ⇒ Object (readonly)
Returns the value of attribute git.
12 13 14 |
# File 'lib/commit-live/tests/runner.rb', line 12 def git @git end |
#sentry ⇒ Object (readonly)
Returns the value of attribute sentry.
12 13 14 |
# File 'lib/commit-live/tests/runner.rb', line 12 def sentry @sentry end |
Instance Method Details
#check_lesson_dir ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/commit-live/tests/runner.rb', line 33 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
87 88 89 |
# File 'lib/commit-live/tests/runner.rb', line 87 def clear_changes_in_tests system("git checkout HEAD -- tests/") end |
#lesson_name ⇒ Object
48 49 50 |
# File 'lib/commit-live/tests/runner.rb', line 48 def lesson_name repo_name(remote: 'origin') end |
#put_error_msg ⇒ Object
52 53 54 55 56 |
# File 'lib/commit-live/tests/runner.rb', line 52 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
43 44 45 46 |
# File 'lib/commit-live/tests/runner.rb', line 43 def repo_name(remote: remote_name) url = git.remote(remote).url url.match(/^.+[\w-]+\/(.*?)(?:\.git)?$/)[1] end |
#run(updateStatus = true) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/commit-live/tests/runner.rb', line 58 def run(updateStatus = true) clear_changes_in_tests puts 'Testing lesson...' strategy.check_dependencies strategy.configure results = strategy.run if updateStatus 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('test_case_pass', lesson_name) else # test case failed puts 'Oops! You still have to pass all the test cases.' CommitLive::Status.new().update('test_case_fail', lesson_name) end end if strategy.results dump_results end strategy.cleanup return results end |
#set_git ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/commit-live/tests/runner.rb', line 25 def set_git begin Git.open(FileUtils.pwd) rescue => e put_error_msg end end |
#strategy ⇒ Object
83 84 85 |
# File 'lib/commit-live/tests/runner.rb', line 83 def strategy @strategy ||= strategies.map{ |s| s.new() }.detect(&:detect) end |