diff --git a/lib/guard/interactor.rb b/lib/guard/interactor.rb index 8a518e751..d725e24d9 100644 --- a/lib/guard/interactor.rb +++ b/lib/guard/interactor.rb @@ -76,6 +76,30 @@ def enabled=(status) @enabled = status end + + # Converts and validates a plain text scope + # to a valid plugin or group scope. + # + # @param [Array] entries the text scope + # @return [Hash, Array] the plugin or group scope, the unknown entries + # + def convert_scope(entries) + scopes = { :plugins => [], :groups => [] } + unknown = [] + + entries.each do |entry| + if plugin = ::Guard.guards(entry) + scopes[:plugins] << plugin + elsif group = ::Guard.groups(entry) + scopes[:groups] << group + else + unknown << entry + end + end + + [scopes, unknown] + end + end # Initialize the interactor. This configures @@ -89,15 +113,47 @@ def initialize Pry.config.should_load_local_rc = false Pry.config.history.file = File.expand_path(self.class.options[:history_file] || HISTORY_FILE) - add_hooks + _add_hooks + + _replace_reset_command + _create_run_all_command + _create_command_aliases + _create_guard_commands + _create_group_commands + + _configure_prompt + end + + # Start the line reader in its own thread and + # stop Guard on Ctrl-D. + # + def start + return if ENV['GUARD_ENV'] == 'test' + + _store_terminal_settings if _stty_exists? + + if !@thread || !@thread.alive? + ::Guard::UI.debug 'Start interactor' + + @thread = Thread.new do + Pry.start + ::Guard.stop + end + end + end - replace_reset_command - create_run_all_command - create_command_aliases - create_guard_commands - create_group_commands + # Kill interactor thread if not current + # + def stop + return if !@thread || ENV['GUARD_ENV'] == 'test' + + unless Thread.current == @thread + ::Guard::UI.reset_line + ::Guard::UI.debug 'Stop interactor' + @thread.kill + end - configure_prompt + _restore_terminal_settings if _stty_exists? end # Add Pry hooks: @@ -106,7 +162,7 @@ def initialize # * Load project's `.guardrc` within each new Pry session. # * Restore prompt after each evaluation. # - def add_hooks + def _add_hooks Pry.config.hooks.add_hook :when_started, :load_guard_rc do (self.class.options[:guard_rc] || GUARD_RC).tap do |p| load p if File.exist?(File.expand_path(p)) @@ -118,7 +174,7 @@ def add_hooks load project_guard_rc if File.exist?(project_guard_rc) end - if stty_exists? + if _stty_exists? Pry.config.hooks.add_hook :after_eval, :restore_visibility do system('stty echo 2>/dev/null') end @@ -127,8 +183,8 @@ def add_hooks # Replaces reset defined inside of Pry with a reset that # instead restarts guard. - - def replace_reset_command + # + def _replace_reset_command Pry.commands.command "reset", "Reset the Guard to a clean state." do output.puts "Guard reset." exec "guard" @@ -139,7 +195,7 @@ def replace_reset_command # when the command is empty (just pressing enter on the # beginning of a line). # - def create_run_all_command + def _create_run_all_command Pry.commands.block_command /^$/, 'Hit enter to run all' do Pry.run_command 'all' end @@ -149,7 +205,7 @@ def create_run_all_command # `help`, `reload`, `change`, `scope`, `notification`, `pause`, `exit` and `quit`, # which will be the first letter of the command. # - def create_command_aliases + def _create_command_aliases SHORTCUTS.each do |command, shortcut| Pry.commands.alias_command shortcut, command.to_s end @@ -160,7 +216,7 @@ def create_command_aliases # when guard-rspec is available, then a command # `rspec` is created that runs `all rspec`. # - def create_guard_commands + def _create_guard_commands ::Guard.guards.each do |guard_plugin| Pry.commands.create_command guard_plugin.name, "Run all #{ guard_plugin.title }" do group 'Guard' @@ -177,7 +233,7 @@ def process # when you have a group `frontend`, then a command # `frontend` is created that runs `all frontend`. # - def create_group_commands + def _create_group_commands ::Guard.groups.each do |group| next if group.name == :default @@ -194,7 +250,7 @@ def process # Configure the pry prompt to see `guard` instead of # `pry`. # - def configure_prompt + def _configure_prompt Pry.config.prompt = [ proc do |target_self, nest_level, pry| history = pry.input_array.size @@ -229,81 +285,27 @@ def configure_prompt ] end - # Start the line reader in its own thread and - # stop Guard on Ctrl-D. - # - def start - return if ENV['GUARD_ENV'] == 'test' - - store_terminal_settings if stty_exists? - - if !@thread || !@thread.alive? - ::Guard::UI.debug 'Start interactor' - - @thread = Thread.new do - Pry.start - ::Guard.stop - end - end - end - - # Kill interactor thread if not current - # - def stop - return if !@thread || ENV['GUARD_ENV'] == 'test' - - unless Thread.current == @thread - ::Guard::UI.reset_line - ::Guard::UI.debug 'Stop interactor' - @thread.kill - end - - restore_terminal_settings if stty_exists? - end - # Detects whether or not the stty command exists # on the user machine. # # @return [Boolean] the status of stty # - def stty_exists? + def _stty_exists? @stty_exists ||= system('hash', 'stty') end # Stores the terminal settings so we can resore them # when stopping. # - def store_terminal_settings + def _store_terminal_settings @stty_save = `stty -g 2>#{ DEV_NULL }`.chomp end # Restore terminal settings # - def restore_terminal_settings + def _restore_terminal_settings system("stty #{ @stty_save } 2>#{ DEV_NULL }") if @stty_save end - # Converts and validates a plain text scope - # to a valid plugin or group scope. - # - # @param [Array] entries the text scope - # @return [Hash, Array] the plugin or group scope, the unknown entries - # - def self.convert_scope(entries) - scopes = { :plugins => [], :groups => [] } - unknown = [] - - entries.each do |entry| - if plugin = ::Guard.guards(entry) - scopes[:plugins] << plugin - elsif group = ::Guard.groups(entry) - scopes[:groups] << group - else - unknown << entry - end - end - - [scopes, unknown] - end end end diff --git a/lib/guard/notifier.rb b/lib/guard/notifier.rb index 3667f2a84..3651f5c04 100644 --- a/lib/guard/notifier.rb +++ b/lib/guard/notifier.rb @@ -98,14 +98,14 @@ def clear_notifications # library. # def turn_on - auto_detect_notification if notifications.empty? && (!::Guard.options || ::Guard.options[:notify]) + _auto_detect_notification if notifications.empty? && (!::Guard.options || ::Guard.options[:notify]) if notifications.empty? ENV['GUARD_NOTIFY'] = 'false' else notifications.each do |notification| - ::Guard::UI.info "Guard uses #{ get_notifier_module(notification[:name]).to_s.split('::').last } to send notifications." - notifier = get_notifier_module(notification[:name]) + notifier = _get_notifier_module(notification[:name]) + ::Guard::UI.info "Guard uses #{ notifier.to_s.split('::').last } to send notifications." notifier.turn_on(notification[:options]) if notifier.respond_to?(:turn_on) end @@ -117,7 +117,7 @@ def turn_on # def turn_off notifications.each do |notification| - notifier = get_notifier_module(notification[:name]) + notifier = _get_notifier_module(notification[:name]) notifier.turn_off(notification[:options]) if notifier.respond_to?(:turn_off) end @@ -150,10 +150,10 @@ def enabled? # @param [Hash] options the notifier options # @return [Boolean] if the notification could be added # - def add_notification(name, options = { }, silent = false) + def add_notification(name, options = {}, silent = false) return turn_off if name == :off - notifier = get_notifier_module(name) + notifier = _get_notifier_module(name) if notifier && notifier.available?(silent, options) self.notifications = notifications << { :name => name, :options => options } @@ -169,15 +169,15 @@ def add_notification(name, options = { }, silent = false) # @option options [Symbol, String] image the image symbol or path to an image # @option options [String] title the notification title # - def notify(message, options = { }) + def notify(message, options = {}) if enabled? - type = notification_type(options[:image] || :success) - image = image_path(options.delete(:image) || :success) + type = _notification_type(options[:image] || :success) + image = _image_path(options.delete(:image) || :success) title = options.delete(:title) || 'Guard' notifications.each do |notification| begin - get_notifier_module(notification[:name]).notify(type, title, message, image, options.merge(notification[:options])) + _get_notifier_module(notification[:name]).notify(type, title, message, image, options.merge(notification[:options])) rescue Exception => e ::Guard::UI.error "Error sending notification with #{ notification[:name] }: #{ e.message }" end @@ -192,7 +192,7 @@ def notify(message, options = { }) # @param [Symbol] name the notifier name # @return [Module] the notifier module # - def get_notifier_module(name) + def _get_notifier_module(name) notifier = NOTIFIERS.flatten(1).detect { |n| n.first == name } notifier ? notifier.last : notifier end @@ -201,12 +201,12 @@ def get_notifier_module(name) # the list of supported notification gems and picks the first that # is available in each notification group. # - def auto_detect_notification + def _auto_detect_notification available = nil self.notifications = [] NOTIFIERS.each do |group| - added = group.map { |n| n.first }.find { |notifier| add_notification(notifier, { }, true) } + added = group.map { |n| n.first }.find { |notifier| add_notification(notifier, {}, true) } available = available || added end @@ -225,14 +225,14 @@ def auto_detect_notification # @param [Symbol, String] image the image symbol or path to an image # @return [String] the image path # - def image_path(image) + def _image_path(image) case image when :failed - images_path.join('failed.png').to_s + _images_path.join('failed.png').to_s when :pending - images_path.join('pending.png').to_s + _images_path.join('pending.png').to_s when :success - images_path.join('success.png').to_s + _images_path.join('success.png').to_s else image end @@ -242,8 +242,8 @@ def image_path(image) # # @return [Pathname] the path to the images directory # - def images_path - @images_path ||= Pathname.new(File.dirname(__FILE__)).join('../../images') + def _images_path + @_images_path ||= Pathname.new(File.dirname(__FILE__)).join('../../images') end # Get the notification type depending on the @@ -252,7 +252,7 @@ def images_path # @param [Symbol, String] image the image symbol or path to an image # @return [String] the notification type # - def notification_type(image) + def _notification_type(image) case image when :failed 'failed' diff --git a/lib/guard/notifiers/emacs.rb b/lib/guard/notifiers/emacs.rb index 0dfe86152..791a3d340 100644 --- a/lib/guard/notifiers/emacs.rb +++ b/lib/guard/notifiers/emacs.rb @@ -49,7 +49,7 @@ def available?(silent = false, options = {}) # @option options [String] client the client to use for notification (default is 'emacsclient') # @option options [String, Integer] priority specify an int or named key (default is 0) # - def notify(type, title, message, image, options = { }) + def notify(type, title, message, image, options = {}) options = DEFAULTS.merge options color = emacs_color type, options fontcolor = emacs_color :fontcolor, options diff --git a/lib/guard/notifiers/file_notifier.rb b/lib/guard/notifiers/file_notifier.rb index ac6de7f11..7a53fb41c 100644 --- a/lib/guard/notifiers/file_notifier.rb +++ b/lib/guard/notifiers/file_notifier.rb @@ -35,7 +35,7 @@ def available?(silent = false, options = {}) # @option options [String] format printf style format for file contents # @option options [String] path the path of where to write the file # - def notify(type, title, message, image, options = { }) + def notify(type, title, message, image, options = {}) if options[:path] format = options.fetch(:format, DEFAULTS[:format]) diff --git a/lib/guard/notifiers/gntp.rb b/lib/guard/notifiers/gntp.rb index c93858718..9aeb27e4d 100644 --- a/lib/guard/notifiers/gntp.rb +++ b/lib/guard/notifiers/gntp.rb @@ -84,7 +84,7 @@ def available?(silent = false, options = {}) # @option options [Integer] port the port to send a remote notification # @option options [Boolean] sticky make the notification sticky # - def notify(type, title, message, image, options = { }) + def notify(type, title, message, image, options = {}) require 'ruby_gntp' options = DEFAULTS.merge(options) diff --git a/lib/guard/notifiers/growl.rb b/lib/guard/notifiers/growl.rb index bd3de91f8..bb007541e 100644 --- a/lib/guard/notifiers/growl.rb +++ b/lib/guard/notifiers/growl.rb @@ -85,7 +85,7 @@ def available?(silent = false, options = {}) # @option options [String] host the hostname or IP address to which to send a remote notification # @option options [String] password the password used for remote notifications # - def notify(type, title, message, image, options = { }) + def notify(type, title, message, image, options = {}) require 'growl' ::Growl.notify(message, DEFAULTS.merge(options).merge({ diff --git a/lib/guard/notifiers/growl_notify.rb b/lib/guard/notifiers/growl_notify.rb index 3c5679601..bb618059a 100644 --- a/lib/guard/notifiers/growl_notify.rb +++ b/lib/guard/notifiers/growl_notify.rb @@ -75,7 +75,7 @@ def available?(silent = false, options = {}) # @option options [Boolean] sticky if the message should stick to the screen # @option options [Integer] priority the importance of message from -2 (very low) to 2 (emergency) # - def notify(type, title, message, image, options = { }) + def notify(type, title, message, image, options = {}) require 'growl_notify' ::GrowlNotify.send_notification(DEFAULTS.merge(options).merge({ diff --git a/lib/guard/notifiers/libnotify.rb b/lib/guard/notifiers/libnotify.rb index 8eaa200b9..77be66003 100644 --- a/lib/guard/notifiers/libnotify.rb +++ b/lib/guard/notifiers/libnotify.rb @@ -63,7 +63,7 @@ def available?(silent = false, options = {}) # @option options [Boolean] append append onto existing notification # @option options [Number, Boolean] timeout the number of seconds to display (1.5 (s), 1000 (ms), false) # - def notify(type, title, message, image, options = { }) + def notify(type, title, message, image, options = {}) require 'libnotify' options = DEFAULTS.merge(options).merge({ diff --git a/lib/guard/notifiers/notifysend.rb b/lib/guard/notifiers/notifysend.rb index 9f15707b5..ac62289f5 100644 --- a/lib/guard/notifiers/notifysend.rb +++ b/lib/guard/notifiers/notifysend.rb @@ -47,7 +47,7 @@ def available?(silent = false, options = {}) # @option options [String] c the notification category # @option options [Number] t the number of milliseconds to display (1000, 3000) # - def notify(type, title, message, image, options = { }) + def notify(type, title, message, image, options = {}) command = "notify-send '#{title}' '#{message}'" options = DEFAULTS.merge(options).merge({ :i => image diff --git a/lib/guard/notifiers/rb_notifu.rb b/lib/guard/notifiers/rb_notifu.rb index 273c45396..44f9712c0 100644 --- a/lib/guard/notifiers/rb_notifu.rb +++ b/lib/guard/notifiers/rb_notifu.rb @@ -69,7 +69,7 @@ def available?(silent = false, options = {}) # @option options [Boolean] noquiet show the tooltip even if the user is in the quiet period that follows his very first login (Windows 7 and up) # @option options [Boolean] xp use IUserNotification interface event when IUserNotification2 is available # - def notify(type, title, message, image, options = { }) + def notify(type, title, message, image, options = {}) require 'rb-notifu' ::Notifu.show(DEFAULTS.merge(options).merge({ diff --git a/lib/guard/notifiers/terminal_notifier.rb b/lib/guard/notifiers/terminal_notifier.rb index 4d971a27b..b58bf76f0 100644 --- a/lib/guard/notifiers/terminal_notifier.rb +++ b/lib/guard/notifiers/terminal_notifier.rb @@ -55,7 +55,7 @@ def available?(silent = false, options = {}) # @option options [String] activate an app bundle # @option options [String] open some url or file # - def notify(type, title, message, image, options = { }) + def notify(type, title, message, image, options = {}) require 'terminal-notifier-guard' options[:title] = title || [options[:app_name] || 'Guard', type.downcase.capitalize].join(' ') options.merge!(:type => type.to_sym, :message => message) diff --git a/lib/guard/notifiers/terminal_title.rb b/lib/guard/notifiers/terminal_title.rb index e01bbeefe..89535dcea 100644 --- a/lib/guard/notifiers/terminal_title.rb +++ b/lib/guard/notifiers/terminal_title.rb @@ -22,7 +22,7 @@ def available?(silent = false, options = {}) # @param [String] image the path to the notification image # @param [Hash] options additional notification library options # - def notify(type, title, message, image, options = { }) + def notify(type, title, message, image, options = {}) first_line = message.sub(/^\n/, '').sub(/\n.*/m, '') puts("\e]2;[#{ title }] #{ first_line }\a") end diff --git a/lib/guard/notifiers/tmux.rb b/lib/guard/notifiers/tmux.rb index 7cb5ef5c7..a3130aa9e 100644 --- a/lib/guard/notifiers/tmux.rb +++ b/lib/guard/notifiers/tmux.rb @@ -61,7 +61,7 @@ def available?(silent = false, options = {}) # @option options [String] color_location the location where to draw the color notification # @option options [Boolean] display_message whether to display a message or not # - def notify(type, title, message, image, options = { }) + def notify(type, title, message, image, options = {}) color = tmux_color(type, options) color_location = options[:color_location] || DEFAULTS[:color_location] @@ -88,7 +88,7 @@ def notify(type, title, message, image, options = { }) # @option options [String] default_message_color a notification foreground color to use when no color per type is defined. # @option options [String] line_separator a string to use instead of a line-break. # - def display_message(type, title, message, options = { }) + def display_message(type, title, message, options = {}) message_format = options["#{ type }_message_format".to_sym] || options[:default_message_format] || DEFAULTS[:default_message_format] message_color = options["#{ type }_message_color".to_sym] || options[:default_message_color] || DEFAULTS[:default_message_color] display_time = options[:timeout] || DEFAULTS[:timeout] @@ -110,7 +110,7 @@ def display_message(type, title, message, options = { }) # @param [String] type the notification type # @return [String] the name of the emacs color # - def tmux_color(type, options = { }) + def tmux_color(type, options = {}) case type when 'success' options[:success] || DEFAULTS[:success] @@ -126,7 +126,7 @@ def tmux_color(type, options = { }) # Notification starting, save the current Tmux settings # and quiet the Tmux output. # - def turn_on(options = { }) + def turn_on(options = {}) unless @options_stored reset_options_store @@ -145,7 +145,7 @@ def turn_on(options = { }) # if available (existing options are restored, new options # are unset) and unquiet the Tmux output. # - def turn_off(options = { }) + def turn_off(options = {}) if @options_stored @options_store.each do |key, value| if value diff --git a/lib/guard/plugin/hooker.rb b/lib/guard/plugin/hooker.rb index 0d69fce42..f690333fd 100644 --- a/lib/guard/plugin/hooker.rb +++ b/lib/guard/plugin/hooker.rb @@ -75,7 +75,7 @@ def reset_callbacks! # hook :foo # end # - # Here, when {Guard::Plugin#run_all} is called, {#hook} will notify callbacks + # Here, when {Guard::Plugin::Base#run_all} is called, {#hook} will notify callbacks # registered for the "run_all_foo" event. # # When event is a String, {#hook} will directly turn the String @@ -87,7 +87,7 @@ def reset_callbacks! # hook "foo_bar" # end # - # When {Guard::Plugin#run_all} is called, {#hook} will notify callbacks + # When {Guard::Plugin::Base#run_all} is called, {#hook} will notify callbacks # registered for the "foo_bar" event. # # @param [Symbol, String] event the name of the Guard event diff --git a/lib/guard/plugin_util.rb b/lib/guard/plugin_util.rb index 55a265caa..56cca6a41 100644 --- a/lib/guard/plugin_util.rb +++ b/lib/guard/plugin_util.rb @@ -99,17 +99,17 @@ def plugin_class(options = {}) begin require "guard/#{ name.downcase }" if try_require - @plugin_class ||= ::Guard.const_get(plugin_constant) + @plugin_class ||= ::Guard.const_get(_plugin_constant) rescue TypeError if try_require - ::Guard::UI.error "Could not find class Guard::#{ constant_name }" + ::Guard::UI.error "Could not find class Guard::#{ _constant_name }" else try_require = true retry end rescue LoadError => loadError unless options[:fail_gracefully] - ::Guard::UI.error "Could not load 'guard/#{ name.downcase }' or find class Guard::#{ constant_name }" + ::Guard::UI.error "Could not load 'guard/#{ name.downcase }' or find class Guard::#{ _constant_name }" ::Guard::UI.error loadError.to_s end end @@ -137,21 +137,21 @@ def add_to_guardfile # Returns the constant for the current plugin. # # @example Returns the constant for a plugin - # > Guard::PluginUtil.new('rspec').plugin_constant + # > Guard::PluginUtil.new('rspec').send(:_plugin_constant) # => Guard::RSpec # - def plugin_constant - @plugin_constant ||= ::Guard.constants.find { |c| c.to_s.downcase == constant_name.downcase } + def _plugin_constant + @_plugin_constant ||= ::Guard.constants.find { |c| c.to_s.downcase == _constant_name.downcase } end # Guesses the most probable name for the current plugin based on its name. # # @example Returns the most probable name for a plugin - # > Guard::PluginUtil.new('rspec').plugin_constant + # > Guard::PluginUtil.new('rspec').send(:_constant_name) # => "Rspec" # - def constant_name - @constant_name ||= name.gsub(/\/(.?)/) { "::#{ $1.upcase }" }.gsub(/(?:^|[_-])(.)/) { $1.upcase } + def _constant_name + @_constant_name ||= name.gsub(/\/(.?)/) { "::#{ $1.upcase }" }.gsub(/(?:^|[_-])(.)/) { $1.upcase } end end diff --git a/lib/guard/runner.rb b/lib/guard/runner.rb index 94e2a455f..b71b25338 100644 --- a/lib/guard/runner.rb +++ b/lib/guard/runner.rb @@ -19,7 +19,7 @@ class Runner # def run(task, scopes = {}) Lumberjack.unit_of_work do - scoped_guards(scopes) do |guard| + _scoped_guards(scopes) do |guard| run_supervised_task(guard, task) if guard.respond_to?(task) end end @@ -38,16 +38,16 @@ def run(task, scopes = {}) # def run_on_changes(modified, added, removed) ::Guard::UI.clearable - scoped_guards do |guard| + _scoped_guards do |guard| modified_paths = ::Guard::Watcher.match_files(guard, modified) added_paths = ::Guard::Watcher.match_files(guard, added) removed_paths = ::Guard::Watcher.match_files(guard, removed) - ::Guard::UI.clear if clearable?(guard, modified_paths, added_paths, removed_paths) + ::Guard::UI.clear if _clearable?(guard, modified_paths, added_paths, removed_paths) - run_first_task_found(guard, MODIFICATION_TASKS, modified_paths) unless modified_paths.empty? - run_first_task_found(guard, ADDITION_TASKS, added_paths) unless added_paths.empty? - run_first_task_found(guard, REMOVAL_TASKS, removed_paths) unless removed_paths.empty? + _run_first_task_found(guard, MODIFICATION_TASKS, modified_paths) unless modified_paths.empty? + _run_first_task_found(guard, ADDITION_TASKS, added_paths) unless added_paths.empty? + _run_first_task_found(guard, REMOVAL_TASKS, removed_paths) unless removed_paths.empty? end end @@ -86,7 +86,7 @@ def run_supervised_task(guard, task, *args) # @note If a Guard group is being run and it has the `:halt_on_fail` # option set, this method returns :no_catch as it will be caught at the # group level. - # @see .scoped_guards + # @see ._scoped_guards # # @param [Guard::Plugin] guard the Guard plugin to execute # @return [Symbol] the symbol to catch @@ -95,7 +95,7 @@ def self.stopping_symbol_for(guard) guard.group.options[:halt_on_fail] ? :no_catch : :task_has_failed end - private + private # Tries to run the first implemented task by a given guard # from a collection of tasks. @@ -104,7 +104,7 @@ def self.stopping_symbol_for(guard) # @param [Array] tasks the tasks to run the first among # @param [Object] task_param the param to pass to each task # - def run_first_task_found(guard, tasks, task_param) + def _run_first_task_found(guard, tasks, task_param) tasks.each do |task| if guard.respond_to?(task) run_supervised_task(guard, task, task_param) @@ -127,13 +127,13 @@ def run_first_task_found(guard, tasks, task_param) # @param [Hash] scopes hash with plugins or a groups scope # @yield the task to run # - def scoped_guards(scopes = {}) - if guards = current_plugins_scope(scopes) + def _scoped_guards(scopes = {}) + if guards = _current_plugins_scope(scopes) guards.each do |guard| yield(guard) end else - current_groups_scope(scopes).each do |group| + _current_groups_scope(scopes).each do |group| current_plugin = nil block_return = catch :task_has_failed do Array(::Guard.guards(:group => group.name)).each do |guard| @@ -157,7 +157,7 @@ def scoped_guards(scopes = {}) # @param [Array] added_paths the added paths. # @param [Array] removed_paths the removed paths. # - def clearable?(guard, modified_paths, added_paths, removed_paths) + def _clearable?(guard, modified_paths, added_paths, removed_paths) (MODIFICATION_TASKS.any? { |task| guard.respond_to?(task) } && !modified_paths.empty?) || (ADDITION_TASKS.any? { |task| guard.respond_to?(task) } && !added_paths.empty?) || (REMOVAL_TASKS.any? { |task| guard.respond_to?(task) } && !removed_paths.empty?) @@ -170,7 +170,7 @@ def clearable?(guard, modified_paths, added_paths, removed_paths) # @param [Hash] scopes hash with a local plugins or a groups scope # @return [Array] the plugins to scope to # - def current_plugins_scope(scopes) + def _current_plugins_scope(scopes) if scopes[:plugins] && !scopes[:plugins].empty? scopes[:plugins] @@ -189,7 +189,7 @@ def current_plugins_scope(scopes) # @param [Hash] scopes hash with a local plugins or a groups scope # @return [Array] the groups to scope to # - def current_groups_scope(scopes) + def _current_groups_scope(scopes) if scopes[:groups] && !scopes[:groups].empty? scopes[:groups] diff --git a/lib/guard/setuper.rb b/lib/guard/setuper.rb index 6a22efe66..1870bbd1f 100644 --- a/lib/guard/setuper.rb +++ b/lib/guard/setuper.rb @@ -30,24 +30,41 @@ def setup(options = {}) Dir.chdir(@watchdir) ::Guard::UI.clear(:force => true) - setup_debug if options[:debug] + _setup_debug if options[:debug] + _setup_listener + _setup_signal_traps - setup_listener - setup_signal_traps reset_groups reset_guards - setup_scopes evaluate_guardfile + _setup_scopes + ::Guard::Deprecator.deprecated_options_warning(options) ::Guard::Deprecator.deprecated_plugin_methods_warning - setup_notifier - setup_interactor + _setup_notifier + _setup_interactor self end + # Initializes the groups array with the default group(s). + # + # @see #_default_groups + # + def reset_groups + @groups = _default_groups + end + + # Initializes the guards array to an empty array. + # + # @see Guard.guards + # + def reset_guards + @guards = [] + end + # Evaluates the Guardfile content. It displays an error message if no # Guard plugins are instantiated after the Guardfile evaluation. # @@ -58,25 +75,27 @@ def evaluate_guardfile ::Guard::UI.error 'No guards found in Guardfile, please add at least one.' if guards.empty? end + private + # Sets up various debug behaviors: # # * Abort threads on exception; # * Set the logging level to `:debug`; # * Modify the system and ` methods to log themselves before being executed # - # @see #debug_command_execution + # @see #_debug_command_execution # - def setup_debug + def _setup_debug Thread.abort_on_exception = true ::Guard::UI.options[:level] = :debug - debug_command_execution + _debug_command_execution end # Initializes the listener and registers a callback for changes. # - def setup_listener + def _setup_listener listener_callback = lambda do |modified, added, removed| - ::Guard::Dsl.reevaluate_guardfile if ::Guard::Watcher.match_guardfile?(modified) + evaluator.reevaluate_guardfile if ::Guard::Watcher.match_guardfile?(modified) ::Guard.within_preserved_state do runner.run_on_changes(modified, added, removed) @@ -98,7 +117,7 @@ def setup_listener # - `USR2` which resumes listening to changes. # - 'INT' which is delegated to Pry if active, otherwise stops Guard. # - def setup_signal_traps + def _setup_signal_traps unless defined?(JRUBY_VERSION) if Signal.list.keys.include?('USR1') Signal.trap('USR1') { ::Guard.pause unless listener.paused? } @@ -125,15 +144,16 @@ def setup_signal_traps # specific plugin). # # @see CLI#start + # @see DSL#scope # - def setup_scopes + def _setup_scopes scope[:groups] = options[:group].map { |g| ::Guard.groups(g) } if options[:group] scope[:plugins] = options[:plugin].map { |p| ::Guard.guards(p) } if options[:plugin] end # Enables or disables the notifier based on user's configurations. # - def setup_notifier + def _setup_notifier if options[:notify] && ENV['GUARD_NOTIFY'] != 'false' ::Guard::Notifier.turn_on else @@ -143,30 +163,12 @@ def setup_notifier # Initializes the interactor unless the user has specified not to. # - def setup_interactor + def _setup_interactor unless options[:no_interactions] || !::Guard::Interactor.enabled @interactor = ::Guard::Interactor.new end end - # Initializes the groups array with the default group(s). - # - # @see #default_groups - # - def reset_groups - @groups = default_groups - end - - # Initializes the guards array to an empty array. - # - # @see Guard.guards - # - def reset_guards - @guards = [] - end - - private - # Returns an array of the default group(s) when Guard starts or when # `Guard.reset` is called. # @@ -174,14 +176,14 @@ def reset_guards # # @return [Array] the default groups # - def default_groups + def _default_groups [Group.new(:default)] end # Adds a command logger in debug mode. This wraps common command # execution functions and logs the executed command before execution. # - def debug_command_execution + def _debug_command_execution Kernel.send(:alias_method, :original_system, :system) Kernel.send(:define_method, :system) do |command, *args| ::Guard::UI.debug "Command execution: #{ command } #{ args.join(' ') }" diff --git a/lib/guard/ui.rb b/lib/guard/ui.rb index 929c71757..e3f48af2a 100644 --- a/lib/guard/ui.rb +++ b/lib/guard/ui.rb @@ -49,7 +49,7 @@ def options=(options) # @option options [Boolean] reset whether to clean the output before # @option options [String] plugin manually define the calling plugin # - def info(message, options = { }) + def info(message, options = {}) filter(options[:plugin]) do |plugin| reset_line if options[:reset] self.logger.info(message, plugin) @@ -62,7 +62,7 @@ def info(message, options = { }) # @option options [Boolean] reset whether to clean the output before # @option options [String] plugin manually define the calling plugin # - def warning(message, options = { }) + def warning(message, options = {}) filter(options[:plugin]) do |plugin| reset_line if options[:reset] self.logger.warn(color(message, :yellow), plugin) @@ -75,7 +75,7 @@ def warning(message, options = { }) # @option options [Boolean] reset whether to clean the output before # @option options [String] plugin manually define the calling plugin # - def error(message, options = { }) + def error(message, options = {}) filter(options[:plugin]) do |plugin| reset_line if options[:reset] self.logger.error(color(message, :red), plugin) diff --git a/spec/guard/notifier_spec.rb b/spec/guard/notifier_spec.rb index f05bc32aa..f5a20feef 100644 --- a/spec/guard/notifier_spec.rb +++ b/spec/guard/notifier_spec.rb @@ -5,7 +5,7 @@ describe '.turn_on' do context 'with configured notifications' do before do - Guard::Notifier.notifications = [{ :name => :gntp, :options => { } }] + Guard::Notifier.notifications = [{ :name => :gntp, :options => {} }] end it 'shows the used notifications' do @@ -31,43 +31,43 @@ context 'when notifications are globally enabled' do before do - ::Guard.options = { } + ::Guard.options = {} ::Guard.options.should_receive(:[]).with(:notify).and_return true end it 'tries to add each available notification silently' do - Guard::Notifier.should_receive(:add_notification).with(:gntp, { }, true).and_return false - Guard::Notifier.should_receive(:add_notification).with(:growl, { }, true).and_return false - Guard::Notifier.should_receive(:add_notification).with(:growl_notify, { }, true).and_return false - Guard::Notifier.should_receive(:add_notification).with(:terminal_notifier, { }, true).and_return false - Guard::Notifier.should_receive(:add_notification).with(:libnotify, { }, true).and_return false - Guard::Notifier.should_receive(:add_notification).with(:notifysend, { }, true).and_return false - Guard::Notifier.should_receive(:add_notification).with(:notifu, { }, true).and_return false - Guard::Notifier.should_receive(:add_notification).with(:emacs, { }, true).and_return false - Guard::Notifier.should_receive(:add_notification).with(:terminal_title, { }, true).and_return false - Guard::Notifier.should_receive(:add_notification).with(:tmux, { }, true).and_return false - Guard::Notifier.should_receive(:add_notification).with(:file, { }, true).and_return false + Guard::Notifier.should_receive(:add_notification).with(:gntp, {}, true).and_return false + Guard::Notifier.should_receive(:add_notification).with(:growl, {}, true).and_return false + Guard::Notifier.should_receive(:add_notification).with(:growl_notify, {}, true).and_return false + Guard::Notifier.should_receive(:add_notification).with(:terminal_notifier, {}, true).and_return false + Guard::Notifier.should_receive(:add_notification).with(:libnotify, {}, true).and_return false + Guard::Notifier.should_receive(:add_notification).with(:notifysend, {}, true).and_return false + Guard::Notifier.should_receive(:add_notification).with(:notifu, {}, true).and_return false + Guard::Notifier.should_receive(:add_notification).with(:emacs, {}, true).and_return false + Guard::Notifier.should_receive(:add_notification).with(:terminal_title, {}, true).and_return false + Guard::Notifier.should_receive(:add_notification).with(:tmux, {}, true).and_return false + Guard::Notifier.should_receive(:add_notification).with(:file, {}, true).and_return false Guard::Notifier.turn_on end it 'adds only the first notification per group' do - Guard::Notifier.should_receive(:add_notification).with(:gntp, { }, true).and_return false - Guard::Notifier.should_receive(:add_notification).with(:growl, { }, true).and_return false - Guard::Notifier.should_receive(:add_notification).with(:growl_notify, { }, true).and_return true - Guard::Notifier.should_not_receive(:add_notification).with(:terminal_notifier, { }, true) - Guard::Notifier.should_not_receive(:add_notification).with(:libnotify, { }, true) - Guard::Notifier.should_not_receive(:add_notification).with(:notifysend, { }, true) - Guard::Notifier.should_not_receive(:add_notification).with(:notifu, { }, true) - Guard::Notifier.should_receive(:add_notification).with(:emacs, { }, true) - Guard::Notifier.should_receive(:add_notification).with(:terminal_title, { }, true) - Guard::Notifier.should_receive(:add_notification).with(:tmux, { }, true) - Guard::Notifier.should_receive(:add_notification).with(:file, { }, true) + Guard::Notifier.should_receive(:add_notification).with(:gntp, {}, true).and_return false + Guard::Notifier.should_receive(:add_notification).with(:growl, {}, true).and_return false + Guard::Notifier.should_receive(:add_notification).with(:growl_notify, {}, true).and_return true + Guard::Notifier.should_not_receive(:add_notification).with(:terminal_notifier, {}, true) + Guard::Notifier.should_not_receive(:add_notification).with(:libnotify, {}, true) + Guard::Notifier.should_not_receive(:add_notification).with(:notifysend, {}, true) + Guard::Notifier.should_not_receive(:add_notification).with(:notifu, {}, true) + Guard::Notifier.should_receive(:add_notification).with(:emacs, {}, true) + Guard::Notifier.should_receive(:add_notification).with(:terminal_title, {}, true) + Guard::Notifier.should_receive(:add_notification).with(:tmux, {}, true) + Guard::Notifier.should_receive(:add_notification).with(:file, {}, true) Guard::Notifier.turn_on end it 'does enable the notifications when a library is available' do Guard::Notifier.should_receive(:add_notification) do - Guard::Notifier.notifications = [{ :name => :gntp, :options => { } }] + Guard::Notifier.notifications = [{ :name => :gntp, :options => {} }] true end.any_number_of_times Guard::Notifier.turn_on @@ -77,7 +77,7 @@ it 'does turn on the notification module for libraries that are available' do ::Guard::Notifier::GNTP.should_receive(:turn_on) Guard::Notifier.should_receive(:add_notification) do - Guard::Notifier.notifications = [{ :name => :gntp, :options => { } }] + Guard::Notifier.notifications = [{ :name => :gntp, :options => {} }] true end.any_number_of_times Guard::Notifier.turn_on @@ -92,7 +92,7 @@ context 'when notifications are globally disabled' do before do - ::Guard.options = { } + ::Guard.options = {} ::Guard.options.should_receive(:[]).with(:notify).and_return false end @@ -115,7 +115,7 @@ context 'when turned on with available notifications' do before do - Guard::Notifier.notifications = [{ :name => :gntp, :options => { } }] + Guard::Notifier.notifications = [{ :name => :gntp, :options => {} }] end it 'turns off each notification' do @@ -198,37 +198,37 @@ describe '.notify' do context 'when notifications are enabled' do before do - Guard::Notifier.notifications = [{ :name => :gntp, :options => { } }] + Guard::Notifier.notifications = [{ :name => :gntp, :options => {} }] Guard::Notifier.stub(:enabled?).and_return true end it 'uses the :success image when no image is defined' do - Guard::Notifier::GNTP.should_receive(:notify).with('success', 'Hi', 'Hi to everyone', /success.png/, { }) + Guard::Notifier::GNTP.should_receive(:notify).with('success', 'Hi', 'Hi to everyone', /success.png/, {}) ::Guard::Notifier.notify('Hi to everyone', :title => 'Hi') end it 'uses "Guard" as title when no title is defined' do - Guard::Notifier::GNTP.should_receive(:notify).with('success', 'Guard', 'Hi to everyone', /success.png/, { }) + Guard::Notifier::GNTP.should_receive(:notify).with('success', 'Guard', 'Hi to everyone', /success.png/, {}) ::Guard::Notifier.notify('Hi to everyone') end it 'sets the "failed" type for a :failed image' do - Guard::Notifier::GNTP.should_receive(:notify).with('failed', 'Guard', 'Hi to everyone', /failed.png/, { }) + Guard::Notifier::GNTP.should_receive(:notify).with('failed', 'Guard', 'Hi to everyone', /failed.png/, {}) ::Guard::Notifier.notify('Hi to everyone', :image => :failed) end it 'sets the "pending" type for a :pending image' do - Guard::Notifier::GNTP.should_receive(:notify).with('pending', 'Guard', 'Hi to everyone', /pending.png/, { }) + Guard::Notifier::GNTP.should_receive(:notify).with('pending', 'Guard', 'Hi to everyone', /pending.png/, {}) ::Guard::Notifier.notify('Hi to everyone', :image => :pending) end it 'sets the "success" type for a :success image' do - Guard::Notifier::GNTP.should_receive(:notify).with('success', 'Guard', 'Hi to everyone', /success.png/, { }) + Guard::Notifier::GNTP.should_receive(:notify).with('success', 'Guard', 'Hi to everyone', /success.png/, {}) ::Guard::Notifier.notify('Hi to everyone', :image => :success) end it 'sets the "notify" type for a custom image' do - Guard::Notifier::GNTP.should_receive(:notify).with('notify', 'Guard', 'Hi to everyone', '/path/to/image.png', { }) + Guard::Notifier::GNTP.should_receive(:notify).with('notify', 'Guard', 'Hi to everyone', '/path/to/image.png', {}) ::Guard::Notifier.notify('Hi to everyone', :image => '/path/to/image.png') end @@ -238,7 +238,7 @@ end it 'sends the notification to multiple notifier' do - Guard::Notifier.notifications = [{ :name => :gntp, :options => { } }, { :name => :growl, :options => { } }] + Guard::Notifier.notifications = [{ :name => :gntp, :options => {} }, { :name => :growl, :options => {} }] Guard::Notifier::GNTP.should_receive(:notify) Guard::Notifier::Growl.should_receive(:notify) ::Guard::Notifier.notify('Hi to everyone') @@ -247,7 +247,7 @@ context 'when notifications are disabled' do before do - Guard::Notifier.notifications = [{ :name => :gntp, :options => { } }, { :name => :growl, :options => { } }] + Guard::Notifier.notifications = [{ :name => :gntp, :options => {} }, { :name => :growl, :options => {} }] Guard::Notifier.stub(:enabled?).and_return false end diff --git a/spec/guard/notifiers/emacs_spec.rb b/spec/guard/notifiers/emacs_spec.rb index 2a37a24c4..75db5e338 100644 --- a/spec/guard/notifiers/emacs_spec.rb +++ b/spec/guard/notifiers/emacs_spec.rb @@ -10,7 +10,7 @@ command.should include(%{(set-face-attribute 'mode-line nil :background "ForestGreen" :foreground "White")}) end - subject.notify('success', 'any title', 'any message', 'any image', { }) + subject.notify('success', 'any title', 'any message', 'any image', {}) end end diff --git a/spec/guard/notifiers/file_notifier_spec.rb b/spec/guard/notifiers/file_notifier_spec.rb index da3cee58d..f706ef7a5 100644 --- a/spec/guard/notifiers/file_notifier_spec.rb +++ b/spec/guard/notifiers/file_notifier_spec.rb @@ -31,7 +31,7 @@ subject.should_not_receive(:write) ::Guard::UI.should_receive(:error).with ":file notifier requires a :path option" - subject.notify('success', 'any title', 'any message', 'any image', { }) + subject.notify('success', 'any title', 'any message', 'any image', {}) end end diff --git a/spec/guard/notifiers/gntp_spec.rb b/spec/guard/notifiers/gntp_spec.rb index 07a0b58b0..2da159edc 100644 --- a/spec/guard/notifiers/gntp_spec.rb +++ b/spec/guard/notifiers/gntp_spec.rb @@ -54,12 +54,12 @@ def self.notify(options) end it 'requires the library again' do subject.should_receive(:require).with('ruby_gntp').and_return true - subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { }) + subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', {}) end it 'opens GNTP as Guard application' do ::GNTP.should_receive(:new).with('Guard', '127.0.0.1', '', 23053) - subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { }) + subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', {}) end context 'when not registered' do @@ -67,7 +67,7 @@ def self.notify(options) end it 'registers the Guard notification types' do gntp.should_receive(:register) - subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { }) + subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', {}) end end @@ -76,7 +76,7 @@ def self.notify(options) end it 'registers the Guard notification types' do gntp.should_not_receive(:register) - subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { }) + subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', {}) end end @@ -89,7 +89,7 @@ def self.notify(options) end :text => 'Welcome to Guard', :icon => '/tmp/welcome.png' }) - subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { }) + subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', {}) end end diff --git a/spec/guard/notifiers/growl_notify_spec.rb b/spec/guard/notifiers/growl_notify_spec.rb index 6c1a46eff..ace5ba5af 100644 --- a/spec/guard/notifiers/growl_notify_spec.rb +++ b/spec/guard/notifiers/growl_notify_spec.rb @@ -73,7 +73,7 @@ def self.send_notification(options) end describe '.nofify' do it 'requires the library again' do subject.should_receive(:require).with('growl_notify').and_return true - subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { }) + subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', {}) end context 'without additional options' do @@ -87,7 +87,7 @@ def self.send_notification(options) end :description => 'Welcome to Guard', :icon => '/tmp/welcome.png' }) - subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { }) + subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', {}) end end diff --git a/spec/guard/notifiers/growl_spec.rb b/spec/guard/notifiers/growl_spec.rb index 3cacdf839..ae10f4e0f 100644 --- a/spec/guard/notifiers/growl_spec.rb +++ b/spec/guard/notifiers/growl_spec.rb @@ -63,7 +63,7 @@ def self.installed?; end describe '.nofify' do it 'requires the library again' do subject.should_receive(:require).with('growl').and_return true - subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { }) + subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', {}) end context 'without additional options' do @@ -75,7 +75,7 @@ def self.installed?; end :title => 'Welcome', :image => '/tmp/welcome.png' }) - subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { }) + subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', {}) end end diff --git a/spec/guard/notifiers/libnotify_spec.rb b/spec/guard/notifiers/libnotify_spec.rb index 6264682f4..6fa3c86b0 100644 --- a/spec/guard/notifiers/libnotify_spec.rb +++ b/spec/guard/notifiers/libnotify_spec.rb @@ -48,7 +48,7 @@ def self.show(options) end describe '.notify' do it 'requires the library again' do subject.should_receive(:require).with('libnotify').and_return true - subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { }) + subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', {}) end context 'without additional options' do @@ -62,7 +62,7 @@ def self.show(options) end :body => 'Welcome to Guard', :icon_path => '/tmp/welcome.png' }) - subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { }) + subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', {}) end end diff --git a/spec/guard/notifiers/notifysend_spec.rb b/spec/guard/notifiers/notifysend_spec.rb index bb3af6472..e556c30f8 100644 --- a/spec/guard/notifiers/notifysend_spec.rb +++ b/spec/guard/notifiers/notifysend_spec.rb @@ -40,7 +40,7 @@ def self.show(options) end command.should include("-t '3000'") command.should include("-h 'int:transient:1'") end - subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { }) + subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', {}) end end diff --git a/spec/guard/notifiers/rb_notifu_spec.rb b/spec/guard/notifiers/rb_notifu_spec.rb index dc7a6a9a0..920633920 100644 --- a/spec/guard/notifiers/rb_notifu_spec.rb +++ b/spec/guard/notifiers/rb_notifu_spec.rb @@ -48,7 +48,7 @@ def self.show(options) end describe '.nofify' do it 'requires the library again' do subject.should_receive(:require).with('rb-notifu').and_return true - subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { }) + subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', {}) end context 'without additional options' do @@ -64,7 +64,7 @@ def self.show(options) end :title => 'Welcome', :message => 'Welcome to Guard' }) - subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { }) + subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', {}) end end diff --git a/spec/guard/notifiers/terminal_notifier_spec.rb b/spec/guard/notifiers/terminal_notifier_spec.rb index 9b857fa8d..c45e2a0cb 100644 --- a/spec/guard/notifiers/terminal_notifier_spec.rb +++ b/spec/guard/notifiers/terminal_notifier_spec.rb @@ -29,7 +29,7 @@ def self.execute(options) end false, { :title => 'any title', :type => :success, :message => 'any message' } ) - subject.notify('success', 'any title', 'any message', 'any image', { }) + subject.notify('success', 'any title', 'any message', 'any image', {}) end it "should allow the title to be customized" do @@ -38,7 +38,7 @@ def self.execute(options) end { :title => 'any title', :message => 'any message', :type => :error } ) - subject.notify('error', 'any title', 'any message', 'any image', { }) + subject.notify('error', 'any title', 'any message', 'any image', {}) end context 'without a title set' do diff --git a/spec/guard/notifiers/terminal_title_spec.rb b/spec/guard/notifiers/terminal_title_spec.rb index a2aa6f802..c8fef3bc5 100644 --- a/spec/guard/notifiers/terminal_title_spec.rb +++ b/spec/guard/notifiers/terminal_title_spec.rb @@ -23,7 +23,7 @@ describe '.notify' do it 'set title + first line of message to terminal title' do subject.should_receive(:puts).with("\e]2;[any title] first line\a") - subject.notify('success', 'any title', "first line\nsecond line\nthird", 'any image', { }) + subject.notify('success', 'any title', "first line\nsecond line\nthird", 'any image', {}) end end diff --git a/spec/guard/notifiers/tmux_spec.rb b/spec/guard/notifiers/tmux_spec.rb index f78eaa348..136b5ba70 100644 --- a/spec/guard/notifiers/tmux_spec.rb +++ b/spec/guard/notifiers/tmux_spec.rb @@ -37,7 +37,7 @@ it 'should set the tmux status bar color to green on success' do subject.should_receive(:system).with 'tmux set status-left-bg green' - subject.notify('success', 'any title', 'any message', 'any image', { }) + subject.notify('success', 'any title', 'any message', 'any image', {}) end it 'should set the tmux status bar color to black on success when black is passed in as an option' do @@ -49,19 +49,19 @@ it 'should set the tmux status bar color to red on failure' do subject.should_receive(:system).with 'tmux set status-left-bg red' - subject.notify('failed', 'any title', 'any message', 'any image', { }) + subject.notify('failed', 'any title', 'any message', 'any image', {}) end it 'should set the tmux status bar color to yellow on pending' do subject.should_receive(:system).with 'tmux set status-left-bg yellow' - subject.notify('pending', 'any title', 'any message', 'any image', { }) + subject.notify('pending', 'any title', 'any message', 'any image', {}) end it 'should set the tmux status bar color to green on notify' do subject.should_receive(:system).with 'tmux set status-left-bg green' - subject.notify('notify', 'any title', 'any message', 'any image', { }) + subject.notify('notify', 'any title', 'any message', 'any image', {}) end it 'should set the right tmux status bar color on success when the right status bar is passed in as an option' do @@ -81,7 +81,7 @@ subject.stub :system => true subject.should_receive(:display_message).never - subject.notify('notify', 'any title', 'any message', 'any image', { }) + subject.notify('notify', 'any title', 'any message', 'any image', {}) end end diff --git a/spec/guard/runner_spec.rb b/spec/guard/runner_spec.rb index 5b2e3c596..4ea844cc5 100644 --- a/spec/guard/runner_spec.rb +++ b/spec/guard/runner_spec.rb @@ -76,8 +76,8 @@ let(:watcher_module) { ::Guard::Watcher } before do - subject.stub(:scoped_guards).and_yield(@foo_guard) - subject.stub(:clearable?) { false } + subject.stub(:_scoped_guards).and_yield(@foo_guard) + subject.stub(:_clearable?) { false } watcher_module.stub(:match_files) { [] } end @@ -87,7 +87,7 @@ end context 'when clearable' do - before { subject.stub(:clearable?) { true } } + before { subject.stub(:_clearable?) { true } } it "clear UI" do Guard::UI.should_receive(:clear) @@ -113,7 +113,7 @@ end it 'does not call run_first_task_found' do - subject.should_not_receive(:run_first_task_found) + subject.should_not_receive(:_run_first_task_found) subject.run_on_changes(*changes) end end @@ -127,7 +127,7 @@ end it 'executes the :run_first_task_found task' do - subject.should_receive(:run_first_task_found).with(@foo_guard, [:run_on_modifications, :run_on_changes, :run_on_change], modified) + subject.should_receive(:_run_first_task_found).with(@foo_guard, [:run_on_modifications, :run_on_changes, :run_on_change], modified) subject.run_on_changes(*changes) end end @@ -141,7 +141,7 @@ end it 'does not call run_first_task_found' do - subject.should_not_receive(:run_first_task_found) + subject.should_not_receive(:_run_first_task_found) subject.run_on_changes(*changes) end end @@ -155,7 +155,7 @@ end it 'executes the :run_on_additions task' do - subject.should_receive(:run_first_task_found).with(@foo_guard, [:run_on_additions, :run_on_changes, :run_on_change], added) + subject.should_receive(:_run_first_task_found).with(@foo_guard, [:run_on_additions, :run_on_changes, :run_on_change], added) subject.run_on_changes(*changes) end end @@ -169,7 +169,7 @@ end it 'does not call run_first_task_found' do - subject.should_not_receive(:run_first_task_found) + subject.should_not_receive(:_run_first_task_found) subject.run_on_changes(*changes) end end @@ -183,7 +183,7 @@ end it 'executes the :run_on_removals task' do - subject.should_receive(:run_first_task_found).with(@foo_guard, [:run_on_removals, :run_on_changes, :run_on_deletion], removed) + subject.should_receive(:_run_first_task_found).with(@foo_guard, [:run_on_removals, :run_on_changes, :run_on_deletion], removed) subject.run_on_changes(*changes) end end diff --git a/spec/guard/setuper_spec.rb b/spec/guard/setuper_spec.rb index 1e5084858..d4d2d6030 100644 --- a/spec/guard/setuper_spec.rb +++ b/spec/guard/setuper_spec.rb @@ -48,7 +48,8 @@ end it 'call setup_signal_traps' do - Guard.should_receive(:setup_signal_traps) + Guard.should_receive(:_setup_signal_traps) + subject end @@ -66,12 +67,14 @@ end it 'call setup_notifier' do - Guard.should_receive(:setup_notifier) + Guard.should_receive(:_setup_notifier) + subject end it 'call setup_interactor' do - Guard.should_receive(:setup_interactor) + Guard.should_receive(:_setup_interactor) + subject end @@ -129,7 +132,7 @@ subject { ::Guard.setup(options) } it "logs command execution if the debug option is true" do - ::Guard.should_receive(:debug_command_execution) + ::Guard.should_receive(:_debug_command_execution) subject end @@ -140,8 +143,41 @@ end end - describe '.setup_signal_traps', :speed => 'slow' do - before { ::Guard::Dsl.stub(:evaluate_guardfile) } + describe '.reset_groups' do + subject do + guard = Guard.setup(:guardfile => File.join(@fixture_path, "Guardfile")) + @group_backend = guard.add_group(:backend) + @group_backflip = guard.add_group(:backflip) + guard + end + + it "initializes a default group" do + subject.reset_groups + + subject.groups.should have(1).item + subject.groups[0].name.should eq :default + subject.groups[0].options.should eq({}) + end + end + + describe '.reset_guards' do + before { class Guard::FooBar < Guard::Plugin; end } + subject do + ::Guard.setup(:guardfile => File.join(@fixture_path, "Guardfile")).tap { |g| g.add_guard(:foo_bar) } + end + after do + ::Guard.instance_eval { remove_const(:FooBar) } + end + + it "return clear the guards array" do + subject.guards.should have(1).item + + subject.reset_guards + + subject.guards.should be_empty + end + end + describe '.evaluate_guardfile' do it 'evaluates the Guardfile' do Guard.stub(:evaluator) { guardfile_evaluator } @@ -151,6 +187,8 @@ end end + describe '._setup_signal_traps', :speed => 'slow' do + before { ::Guard.stub(:evaluate_guardfile) } unless windows? || defined?(JRUBY_VERSION) context 'when receiving SIGUSR1' do @@ -286,7 +324,7 @@ end end - describe '.setup_listener' do + describe '._setup_listener' do let(:listener) { stub.as_null_object } context "with latency option" do @@ -294,7 +332,8 @@ it "pass option to listener" do Listen.should_receive(:to).with(anything, { :relative_paths => true, :latency => 1.5 }) { listener } - ::Guard.setup_listener + + ::Guard.send :_setup_listener end end @@ -303,12 +342,13 @@ it "pass option to listener" do Listen.should_receive(:to).with(anything, { :relative_paths => true, :force_polling => true }) { listener } - ::Guard.setup_listener + + ::Guard.send :_setup_listener end end end - describe '.setup_notifier' do + describe '._setup_notifier' do context "with the notify option enabled" do before { ::Guard.stub(:options).and_return(:notify => true) } @@ -356,7 +396,7 @@ end end - describe '.setup_interactor' do + describe '._setup_interactor' do context 'with CLI options' do before do @enabled = Guard::Interactor.enabled @@ -402,38 +442,36 @@ end end - describe '.reset_groups' do - subject do - guard = Guard.setup(:guardfile => File.join(@fixture_path, "Guardfile")) - @group_backend = guard.add_group(:backend) - @group_backflip = guard.add_group(:backflip) - guard - end - - it "initializes a default group" do - subject.reset_groups + describe '._debug_command_execution' do + subject { ::Guard.setup } - subject.groups.should have(1).item - subject.groups[0].name.should eq :default - subject.groups[0].options.should eq({}) + before do + @original_system = Kernel.method(:system) + @original_command = Kernel.method(:"`") end - end - describe '.reset_guards' do - before { class Guard::FooBar < Guard::Plugin; end } - subject do - ::Guard.setup(:guardfile => File.join(@fixture_path, "Guardfile")).tap { |g| g.add_guard(:foo_bar) } - end after do - ::Guard.instance_eval { remove_const(:FooBar) } + Kernel.send(:remove_method, :system, :'`') + Kernel.send(:define_method, :system, @original_system.to_proc) + Kernel.send(:define_method, :"`", @original_command.to_proc) end - it "return clear the guards array" do - subject.guards.should have(1).item + it "outputs Kernel.#system method parameters" do + ::Guard::UI.should_receive(:debug).with("Command execution: exit 0") + subject.send :_debug_command_execution + system("exit", "0").should be_false + end - subject.reset_guards + it "outputs Kernel.#` method parameters" do + ::Guard::UI.should_receive(:debug).with("Command execution: echo test") + subject.send :_debug_command_execution + `echo test`.should eq "test\n" + end - subject.guards.should be_empty + it "outputs %x{} method parameters" do + ::Guard::UI.should_receive(:debug).with("Command execution: echo test") + subject.send :_debug_command_execution + %x{echo test}.should eq "test\n" end end diff --git a/spec/guard_spec.rb b/spec/guard_spec.rb index d9a380aa4..67f78ed51 100644 --- a/spec/guard_spec.rb +++ b/spec/guard_spec.rb @@ -42,7 +42,8 @@ end it 'does not reload Guard' do - runner.should_not_receive(:run).with(:reload, { }) + runner.should_not_receive(:run).with(:reload, {}) + subject.reload end end @@ -281,7 +282,7 @@ it 'disallows running the block concurrently to avoid inconsistent states' do subject.lock.should_receive(:synchronize) - subject.within_preserved_state &Proc.new { } + subject.within_preserved_state &Proc.new {} end it 'runs the passed block' do @@ -294,7 +295,7 @@ it 'stops the interactor before running the block and starts it again when done' do subject.interactor.should_receive(:stop) subject.interactor.should_receive(:start) - subject.within_preserved_state &Proc.new { } + subject.within_preserved_state &Proc.new {} end end @@ -304,7 +305,7 @@ it 'stops the interactor before running the block and do not starts it again when done' do subject.interactor.should_receive(:stop) subject.interactor.should_not_receive(:start) - subject.within_preserved_state &Proc.new { } + subject.within_preserved_state &Proc.new {} end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 42387b0fa..58f9cc655 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -35,7 +35,7 @@ end config.before(:all) do - ::Guard::Notifier.send(:auto_detect_notification) + ::Guard::Notifier.send(:_auto_detect_notification) @guard_notify = ENV['GUARD_NOTIFY'] @guard_notifications = ::Guard::Notifier.notifications diff --git a/spec/support/guard_helper.rb b/spec/support/guard_helper.rb index 71c4fdc10..88259ae30 100644 --- a/spec/support/guard_helper.rb +++ b/spec/support/guard_helper.rb @@ -1,27 +1,27 @@ shared_examples_for 'interactor enabled' do it 'enables the interactor' do Guard::Interactor.should_receive(:new) - Guard.setup_interactor + Guard.send :_setup_interactor end end shared_examples_for 'interactor disabled' do it 'disables the interactor' do Guard::Interactor.should_not_receive(:new) - Guard.setup_interactor + Guard.send :_setup_interactor end end shared_examples_for 'notifier enabled' do it 'enables the notifier' do Guard::Notifier.should_receive(:turn_on) - Guard.setup_notifier + Guard.send :_setup_notifier end end shared_examples_for 'notifier disabled' do it 'disables the notifier' do Guard::Notifier.should_receive(:turn_off) - Guard.setup_notifier + Guard.send :_setup_notifier end end