Permalink
Browse files

Improve commands implementation, docs & specs

  • Loading branch information...
rymai committed Mar 17, 2013
1 parent 9825dd2 commit 55b774809db85d9b71d821b82e08d05b9c1329c3
View
@@ -488,14 +488,12 @@ def deprecated_options_warning
# => { :plugins => [:rspec], :groups => [:backend] }
#
def convert_scopes(scopes)
- if scopes[:guard]
- scopes[:plugins] = [scopes[:guard]]
- scopes.delete(:guard)
+ if plugin = scopes.delete(:guard)
+ scopes[:plugins] = [plugin]
end
- if scopes[:group]
- scopes[:groups] = [scopes[:group]]
- scopes.delete(:group)
+ if group = scopes.delete(:group)
+ scopes[:groups] = [group]
end
scopes
@@ -19,7 +19,7 @@ class Interactor
def process(*entries)
scopes, rest = ::Guard::Interactor.convert_scope(entries)
- if rest.length == 0
+ if rest.empty?
::Guard.run_all scopes
else
output.puts "Unkown scope #{ rest.join(', ') }"
@@ -8,23 +8,20 @@ class Interactor
description 'Trigger a file change.'
banner <<-BANNER
- Usage: change <scope>
+ Usage: change <file> <other_file>
- Runs the Guard plugin `run_on_changes` action.
-
- You may want to specify an optional scope to the action,
- either the name of a Guard plugin or a plugin group.
+ Pass the given files to the Guard plugin `run_on_changes` action.
BANNER
def process(*entries)
- scopes, rest = ::Guard::Interactor.convert_scope(entries)
+ scopes, files = ::Guard::Interactor.convert_scope(entries)
- if rest.length != 0
+ if files.empty?
+ output.puts 'Please specify a file.'
+ else
::Guard.within_preserved_state do
- ::Guard.runner.run_on_changes(rest, [], [])
+ ::Guard.runner.run_on_changes(files, [], [])
end
- else
- output.puts 'Please specify a file.'
end
end
@@ -19,7 +19,7 @@ class Interactor
def process(*entries)
scopes, rest = ::Guard::Interactor.convert_scope(entries)
- if rest.length == 0
+ if rest.empty?
::Guard.reload scopes
else
output.puts "Unkown scope #{ rest.join(', ') }"
@@ -16,10 +16,10 @@ class Interactor
def process(*entries)
scope, rest = ::Guard::Interactor.convert_scope(entries)
- if rest.length == 0
- ::Guard.scope = scope
+ if scope[:plugins].empty? && scope[:groups].empty?
+ output.puts 'Usage: scope <scope>'
else
- output.puts "Unkown scope #{ rest.join(', ') }"
+ ::Guard.scope = scope
end
end
@@ -10,7 +10,7 @@ class Interactor
description 'Show all Guard plugins.'
banner <<-BANNER
- Usage: show <scope>
+ Usage: show
Show all defined Guard plugins and their options.
BANNER
@@ -11,14 +11,14 @@
describe '#perform' do
context 'with a file' do
- it 'runs the :run_all action with the given scope' do
+ it 'runs the :run_on_changes action with the given scope' do
::Guard.runner.should_receive(:run_on_changes).with(['foo'], [], [])
Pry.run_command 'change foo'
end
end
context 'with multiple files' do
- it 'runs the :run_all action with the given scope' do
+ it 'runs the :run_on_changes action with the given scope' do
::Guard.runner.should_receive(:run_on_changes).with(['foo', 'bar', 'baz'], [], [])
Pry.run_command 'change foo bar baz'
end
@@ -0,0 +1,46 @@
+require 'spec_helper'
+
+describe 'Guard::Interactor::SCOPE' do
+
+ before do
+ Guard.stub(:scope=)
+ Guard.stub(:setup_interactor)
+ Pry.output.stub(puts: true)
+ stub_const 'Guard::Bar', Class.new(Guard::Guard)
+ end
+
+ let(:guard) { ::Guard.setup }
+ let(:foo_group) { guard.add_group(:foo) }
+ let(:bar_guard) { guard.add_guard(:bar, [], [], { :group => :foo }) }
+
+ describe '#perform' do
+ context 'without scope' do
+ it 'does not call :scope=' do
+ Guard.should_not_receive(:scope=)
+ Pry.output.should_receive(:puts).with 'Usage: scope <scope>'
+ Pry.run_command 'scope'
+ end
+ end
+
+ context 'with a valid Guard group scope' do
+ it 'runs the :scope= action with the given scope' do
+ Guard.should_receive(:scope=).with({ :groups => [foo_group], :plugins => [] })
+ Pry.run_command 'scope foo'
+ end
+ end
+
+ context 'with a valid Guard plugin scope' do
+ it 'runs the :scope= action with the given scope' do
+ Guard.should_receive(:scope=).with({ :plugins => [bar_guard], :groups => [] })
+ Pry.run_command 'scope bar'
+ end
+ end
+
+ context 'with an invalid scope' do
+ it 'does not run the action' do
+ Guard.should_not_receive(:scope=)
+ Pry.run_command 'scope baz'
+ end
+ end
+ end
+end
View
@@ -44,8 +44,6 @@
if ::Guard.options
::Guard.options[:debug] = false
end
-
- Guard.scope = { :plugins => [], :groups => [] }
end
config.after(:all) do

0 comments on commit 55b7748

Please sign in to comment.