Class: Dispatch

Inherits:
Object
  • Object
show all
Defined in:
lib/test_officer/dispatch.rb

Constant Summary collapse

SPEC_FILE =
/\_{1}s{1}p{1}e{1}c{1}.+/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, path) ⇒ Dispatch

Returns a new instance of Dispatch.



7
8
9
10
# File 'lib/test_officer/dispatch.rb', line 7

def initialize(file, path)
  @file = file.to_s
  @path = path.to_s
end

Instance Attribute Details

#listObject

Returns the value of attribute list.



5
6
7
# File 'lib/test_officer/dispatch.rb', line 5

def list
  @list
end

Instance Method Details

#alternative_file(file) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/test_officer/dispatch.rb', line 30

def alternative_file file
  file = file.split("/").last.split(".")[0]
  file = "#{file}_spec.rb"
  found = false
  @list.each{|f| found = f if f.include? file}
  found
end

#run_testObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/test_officer/dispatch.rb', line 12

def run_test
  begin
    found = false
    @list = Dir.glob("**/*").each{|f| found = true if f.to_s == @file and @file =~ SPEC_FILE}
    if found
      run @file, "running #{@file}"
    else
      if found = alternative_file(@file)
        run found, "alternative find, running"
      else
        run 'spec', 'could not find file, running full suite ... '
      end
    end
  rescue => e
    run 'spec', "could not find file due to errors, running full suite ... ERROR: #{e}"
  end
end