Class: Bolt::Runners::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/bolt/runners/base.rb

Direct Known Subclasses

Cucumber, RSpec, TestUnit

Constant Summary collapse

MAPPINGS =

mappings define which folders hold the files that the listener should listen to

/(\.\/app\/|\.\/lib\/)/
CLASS_MAP =

class map specifies the folders holding classes that can be reloaded

/(app\/controllers|app\/models|lib\/)/

Instance Method Summary collapse

Instance Method Details

#clear_class(klass) ⇒ Object

clear the class of methods before reload



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/bolt/runners/base.rb', line 76

def clear_class(klass)
  begin
    klass.instance_methods.each do |m| 
      next if m.to_s == '__id__'
      next if m.to_s == '__send__'
      begin
        klass.send(:remove_method, m)
      rescue
      end
    end
  rescue NameError
  end
end

#file_verified?(filename) ⇒ Boolean

check whether file exists

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
# File 'lib/bolt/runners/base.rb', line 51

def file_verified?(filename)
  if !File.exists?(filename)
    notifier.test_file_missing(filename)
    puts "=> ERROR: could not find test file: #{filename}"
    return false
  end
  return true
end

#handle(filename) ⇒ Object

handle an updated file



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bolt/runners/base.rb', line 23

def handle(filename)
  
  reload filename
  
  puts "=> #{self.class} running test for #{filename}" if Bolt.verbose?
  test_files = translate(filename)
  
  return if test_files == []
  
  puts "==== #{self.class} running: #{ test_files.join(', ')}  ===="
          
  run(test_files)
  
  puts "==== #{self.class} completed run ===="
  
end

#initializedObject

do not allow this class to be instantiated

Raises:

  • (NotImplementedError)


17
18
19
# File 'lib/bolt/runners/base.rb', line 17

def initialized
  raise NotImplementedError
end

#load_file(filename) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/bolt/runners/base.rb', line 90

def load_file(filename)
  # load file again to rebuild the class we just ripped apart
  if filename.match(self.class::CLASS_MAP)
    begin
      require File.join(Dir.pwd, filename)
    rescue LoadError
      notifier.error("Error in #{filename}", $!)
      return false
    rescue ArgumentError
      notifier.error("Error in #{filename}", $!)
      return false
    end
  end
end

#reload(filename) ⇒ Object

force reload of a file/class



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/bolt/runners/base.rb', line 106

def reload(filename)
  
  # remove the file from list of loaded files
  $".delete(filename)
  $".delete(File.join(Dir.pwd, filename))
  
  # remove methods from class (if present)
  if filename.match(self.class::CLASS_MAP)
    class_filename = filename.sub(self.class::CLASS_MAP, '')
    
    # get the class
    klass = resolve_class(class_filename)

    # remove all methods - don't worry, the reload will bring them back refreshed
    clear_class(klass) if klass

  end

  load_file(filename)
  
end

#resolve_class(filename) ⇒ Object

resolve the class based on filename



66
67
68
69
70
71
72
73
# File 'lib/bolt/runners/base.rb', line 66

def resolve_class(filename)
  klassname = resolve_classname(filename)
  begin
    return eval(klassname)
  rescue NameError
    return false
  end
end

#resolve_classname(filename) ⇒ Object

get the classname based on file



61
62
63
# File 'lib/bolt/runners/base.rb', line 61

def resolve_classname(filename)
  filename.sub('.rb', '').gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
end

#run(test_filename) ⇒ Object

run the specified test



46
47
48
# File 'lib/bolt/runners/base.rb', line 46

def run(test_filename)

end

#translate(filename) ⇒ Object

translate the filename into a test



41
42
43
# File 'lib/bolt/runners/base.rb', line 41

def translate(filename)
  
end