Class: CommitLive::Test

Inherits:
Object
  • Object
show all
Defined in:
lib/commit-live/tests/runner.rb

Constant Summary collapse

REPO_BELONGS_TO_US =
[
  'commit-live-students'
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTest

Returns a new instance of Test.



14
15
16
17
# File 'lib/commit-live/tests/runner.rb', line 14

def initialize()
  check_lesson_dir
  die if !strategy
end

Instance Attribute Details

#gitObject (readonly)

Returns the value of attribute git.



8
9
10
# File 'lib/commit-live/tests/runner.rb', line 8

def git
  @git
end

Instance Method Details

#check_lesson_dirObject



27
28
29
30
31
32
33
34
35
# File 'lib/commit-live/tests/runner.rb', line 27

def check_lesson_dir
  @git = set_git
  netrc = CommitLive::NetrcInteractor.new()
  netrc.read(machine: 'ga-extra')
  username = netrc.
  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

#put_error_msgObject



42
43
44
45
46
# File 'lib/commit-live/tests/runner.rb', line 42

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



37
38
39
40
# File 'lib/commit-live/tests/runner.rb', line 37

def repo_name(remote: remote_name)
  url = git.remote(remote).url
  url.match(/^.+[\w-]+\/(.*?)(?:\.git)?$/)[1]
end

#runObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/commit-live/tests/runner.rb', line 48

def run
  strategy.check_dependencies
  strategy.configure
  results = strategy.run
  puts 'Updating lesson status...'
  lessonName = repo_name(remote: 'origin')
  if results
    # test case passed
    CommitLive::Status.new().update('test_case_pass', lessonName)
  else
    # test case failed
    CommitLive::Status.new().update('test_case_fail', lessonName)
  end
end

#set_gitObject



19
20
21
22
23
24
25
# File 'lib/commit-live/tests/runner.rb', line 19

def set_git
  begin
    Git.open(FileUtils.pwd)
  rescue => e
    put_error_msg
  end
end

#strategyObject



63
64
65
# File 'lib/commit-live/tests/runner.rb', line 63

def strategy
  @strategy ||= strategies.map{ |s| s.new() }.detect(&:detect)
end