Class: Autowatchr
- Inherits:
-
Object
- Object
- Autowatchr
- Defined in:
- lib/autowatchr.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #classname_to_path(s) ⇒ Object
-
#initialize(script, options = {}) {|@config| ... } ⇒ Autowatchr
constructor
A new instance of Autowatchr.
- #run_lib_file(file) ⇒ Object
- #run_test_file(files) ⇒ Object
Constructor Details
#initialize(script, options = {}) {|@config| ... } ⇒ Autowatchr
Returns a new instance of Autowatchr.
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/autowatchr.rb', line 98 def initialize(script, = {}) @config = Config.new() yield @config if block_given? @script = script @test_files = [] @failed_tests = {} discover_files run_all_tests start_watching_files end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
96 97 98 |
# File 'lib/autowatchr.rb', line 96 def config @config end |
Instance Method Details
#classname_to_path(s) ⇒ Object
149 150 151 |
# File 'lib/autowatchr.rb', line 149 def classname_to_path(s) File.join(@config.test_dir, underscore(s)+".rb") end |
#run_lib_file(file) ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/autowatchr.rb', line 110 def run_lib_file(file) md = file.match(%r{^#{@config.lib_dir}#{File::SEPARATOR}?(.+)$}) parts = md[1].split(File::SEPARATOR) parts[-1] = "test_#{parts[-1]}" file = "#{@config.test_dir}/" + File.join(parts) run_test_file(file) end |
#run_test_file(files) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/autowatchr.rb', line 118 def run_test_file(files) files = [files] unless files.is_a?(Array) passing = [] commands = [] files.each do |file| tests = @failed_tests[file] if tests && !tests.empty? predicate = %!#{file} -n "/^(#{tests.join("|")})$/"! commands << @config.eval_command(predicate) else passing << file end end if !passing.empty? predicate = if passing.length > 1 "-e \"%w[#{passing.join(" ")}].each do |f| require f end\"" else passing[0] end commands.unshift(@config.eval_command(predicate)) end cmd = commands.join("; ") puts cmd results = execute_cmd(cmd) handle_results(results, files) end |