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.
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/autowatchr.rb', line 83 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.
81 82 83 |
# File 'lib/autowatchr.rb', line 81 def config @config end |
Instance Method Details
#classname_to_path(s) ⇒ Object
134 135 136 |
# File 'lib/autowatchr.rb', line 134 def classname_to_path(s) File.join(@config.test_dir, underscore(s)+".rb") end |
#run_lib_file(file) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/autowatchr.rb', line 95 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
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/autowatchr.rb', line 103 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 |