From 245eeba2609e4021375208178bd8f26c3ee03a08 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 26 Jun 2011 16:13:33 -0400 Subject: [PATCH] refactor something that was really starting to bug me --- lib/guard/jasmine-headless-webkit.rb | 47 +++++++++++++++------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/lib/guard/jasmine-headless-webkit.rb b/lib/guard/jasmine-headless-webkit.rb index 8ef3d49..154cb3f 100644 --- a/lib/guard/jasmine-headless-webkit.rb +++ b/lib/guard/jasmine-headless-webkit.rb @@ -22,33 +22,27 @@ module Guard end def run_all - UI.info "Guard::JasmineHeadlessWebkit running all specs..." - JasmineHeadlessWebkitRunner.run if run_all_things_before - @ran_before = false - rescue ::CoffeeScript::CompilationError - rescue StandardError => e - puts e.message - puts e.backtrace.join("\n") - puts + run_something_and_rescue do + UI.info "Guard::JasmineHeadlessWebkit running all specs..." + JasmineHeadlessWebkitRunner.run if run_all_things_before + @ran_before = false + end end def run_on_change(paths) - paths = filter_paths(paths) - @ran_before = false - if run_all_things_before - @ran_before = true - if !paths.empty? - UI.info "Guard::JasmineHeadlessWebkit running the following: #{paths.join(' ')}" - JasmineHeadlessWebkitRunner.run(paths) - else - run_all + run_something_and_rescue do + paths = filter_paths(paths) + @ran_before = false + if run_all_things_before + @ran_before = true + if !paths.empty? + UI.info "Guard::JasmineHeadlessWebkit running the following: #{paths.join(' ')}" + JasmineHeadlessWebkitRunner.run(paths) + else + run_all + end end end - rescue ::CoffeeScript::CompilationError - rescue StandardError => e - puts e.message - puts e.backtrace.join("\n") - puts end private @@ -91,6 +85,15 @@ module Guard system command $?.exitstatus == 0 end + + def run_something_and_rescue + yield + rescue ::CoffeeScript::CompilationError + rescue StandardError => e + puts e.message + puts e.backtrace.join("\n") + puts + end end class Dsl