Skip to content

Commit

Permalink
Merge ed1bb0f into 8f8f01e
Browse files Browse the repository at this point in the history
  • Loading branch information
aspiers committed Apr 4, 2013
2 parents 8f8f01e + ed1bb0f commit 692140e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -16,6 +16,7 @@ bin/fsevent_watch_guard
Makefile

.guard_result
coverage/

## MAC OS
.DS_Store
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -43,5 +43,6 @@ end
#
group :test do
gem 'rspec'
gem 'guard-rspec' # this is required by guard_spec.rb
gem 'coveralls', :require => false
end
29 changes: 19 additions & 10 deletions lib/guard/notifiers/tmux.rb
Expand Up @@ -65,7 +65,7 @@ def notify(type, title, message, image, options = { })
color = tmux_color(type, options)
color_location = options[:color_location] || DEFAULTS[:color_location]

system("#{ DEFAULTS[:client] } set #{ color_location } #{ color }")
run_client "set #{ color_location } #{ color }"

show_message = options[:display_message] || DEFAULTS[:display_message]
display_message(type, title, message, options) if show_message
Expand Down Expand Up @@ -98,10 +98,10 @@ def display_message(type, title, message, options = { })
formatted_message = message.split("\n").join(separator)
display_message = message_format % [title, formatted_message]

system("#{ DEFAULTS[:client] } set display-time #{ display_time * 1000 }")
system("#{ DEFAULTS[:client] } set message-fg #{ message_color }")
system("#{ DEFAULTS[:client] } set message-bg #{ color }")
system("#{ DEFAULTS[:client] } display-message '#{ display_message }'")
run_client "set display-time #{ display_time * 1000 }"
run_client "set message-fg #{ message_color }"
run_client "set message-bg #{ color }"
run_client "display-message '#{ display_message }'"
end

# Get the Tmux color for the notification type.
Expand Down Expand Up @@ -138,31 +138,40 @@ def turn_on(options = { })
@options_stored = true
end

system("#{ DEFAULTS[:client] } set quiet on")
run_client "set quiet on"
end

# Notification stopping. Restore the previous Tmux state
# if available (existing options are restored, new options
# are unset) and unquite the Tmux output.
# are unset) and unquiet the Tmux output.
#
def turn_off(options = { })
if @options_stored
@options_store.each do |key, value|
if value
system("#{ DEFAULTS[:client] } set #{ key } #{ value }")
run_client "set #{ key } #{ value }"
else
system("#{ DEFAULTS[:client] } set -u #{ key }")
run_client "set -u #{ key }"
end
end

reset_options_store
end

system("#{ DEFAULTS[:client] } set quiet off")
run_client 'set quiet off'
end

private

def system(args)
args += " >/dev/null 2>&1" if ENV['GUARD_ENV'] == 'test'
super
end

def run_client(args)
system("#{ DEFAULTS[:client] } #{args}")
end

# Reset the internal Tmux options store defaults.
#
def reset_options_store
Expand Down
6 changes: 2 additions & 4 deletions lib/guard/runner.rb
Expand Up @@ -50,8 +50,8 @@ def deprecation_warning
#
def run(task, scopes = {})
Lumberjack.unit_of_work do
scoped_guards(scopes) do |guard|
run_supervised_task(guard, task)
scoped_guards(scopes) do |guard|
run_supervised_task(guard, task) if guard.respond_to?(task)
end
end
end
Expand Down Expand Up @@ -101,8 +101,6 @@ def run_supervised_task(guard, task, *args)
result
end

rescue NoMethodError
# Do nothing
rescue Exception => ex
::Guard::UI.error("#{ guard.class.name } failed to achieve its <#{ task.to_s }>, exception was:" +
"\n#{ ex.class }: #{ ex.message }\n#{ ex.backtrace.join("\n") }")
Expand Down
7 changes: 5 additions & 2 deletions spec/guard/runner_spec.rb
Expand Up @@ -68,8 +68,9 @@
describe '#run' do
let(:scopes) { { :group => foo_group } }

it 'executes a supervised task on all registered guards' do
[foo_guard, bar1_guard, bar2_guard].each do |g|
it 'executes a supervised task on all registered guards implementing that task' do
[foo_guard, bar1_guard].each do |g|
g.stub(:my_task)
subject.should_receive(:run_supervised_task).with(g, :my_task)
end
subject.run(:my_task)
Expand All @@ -94,6 +95,7 @@
let(:scopes) { { :plugins => [bar1_guard] } }

it 'executes the supervised task on the specified guard only' do
bar1_guard.stub(:my_task)
subject.should_receive(:run_supervised_task).with(bar1_guard, :my_task)

subject.should_not_receive(:run_supervised_task).with(foo_guard, :my_task)
Expand All @@ -107,6 +109,7 @@
let(:scopes) { { :groups => [foo_group] } }

it 'executes the task on each guard in the specified group only' do
foo_guard.stub(:my_task)
subject.should_receive(:run_supervised_task).with(foo_guard, :my_task)

subject.should_not_receive(:run_supervised_task).with(bar1_guard, :my_task)
Expand Down
2 changes: 1 addition & 1 deletion spec/guard_spec.rb
Expand Up @@ -135,7 +135,7 @@
end
end

describe ".setup_signal_traps" do
describe ".setup_signal_traps", :speed => 'slow' do
before { ::Guard::Dsl.stub(:evaluate_guardfile) }

unless windows? || defined?(JRUBY_VERSION)
Expand Down

0 comments on commit 692140e

Please sign in to comment.