Permalink
Browse files

Apply global scope if local scope is empty.

  • Loading branch information...
1 parent 4c034a5 commit 535f4d422ca4d9e08eaae134371568fd4c3d277d @netzpirat netzpirat committed Dec 19, 2012
Showing with 41 additions and 5 deletions.
  1. +7 −5 lib/guard/ui.rb
  2. +34 −0 spec/guard/ui_spec.rb
View
@@ -131,14 +131,16 @@ def clearable
# @param [Hash] scopes hash with a guard or a group scope
#
def action_with_scopes(action, scopes)
- if scopes[:plugins]
- scope_message ||= scopes[:plugins].join(',')
- end
+ plugins = scopes[:plugins] || []
+ groups = scopes[:groups] || []
- if scopes[:groups]
- scope_message ||= scopes[:groups].join(',')
+ if plugins.empty? && groups.empty?
+ plugins = ::Guard.scope[:plugins] || []
+ groups = ::Guard.scope[:groups] || []
end
+ scope_message ||= plugins.join(',') unless plugins.empty?
+ scope_message ||= groups.join(',') unless groups.empty?
scope_message ||= 'all'
info "#{ action } #{ scope_message }"
View
@@ -276,4 +276,38 @@
end
end
+ describe '.action_with_scopes' do
+ context 'with a plugins scope' do
+ it 'shows the plugin scoped action' do
+ Guard::UI.should_receive(:info).with('Reload rspec,jasmine')
+ Guard::UI.action_with_scopes('Reload', { :plugins => [:rspec, :jasmine] })
+ end
+ end
+
+ context 'with a groups scope' do
+ it 'shows the group scoped action' do
+ Guard::UI.should_receive(:info).with('Reload frontend')
+ Guard::UI.action_with_scopes('Reload', { :groups => [:frontend] })
+ end
+ end
+
+ context 'without a scope' do
+ context 'with a global plugin scope' do
+ it 'shows the global plugin scoped action' do
+ Guard.scope = { :groups => [:test] }
+ Guard::UI.should_receive(:info).with('Reload test')
+ Guard::UI.action_with_scopes('Reload', {})
+ end
+ end
+
+ context 'with a global group scope' do
+ it 'shows the global group scoped action' do
+ Guard.scope = { :groups => [:backend] }
+ Guard::UI.should_receive(:info).with('Reload backend')
+ Guard::UI.action_with_scopes('Reload', {})
+ end
+ end
+ end
+ end
+
end

0 comments on commit 535f4d4

Please sign in to comment.