Permalink
Browse files

Add missing specs.

  • Loading branch information...
netzpirat committed Sep 26, 2012
1 parent 707a1b0 commit b49a00bb0891e74f45d9b8e64020a283d756f2f3
@@ -22,7 +22,7 @@ def process(*entries)
if rest.length == 0
::Guard.run_all scopes
else
- puts "Unkown scope #{ rest.join(', ') }"
+ output.puts "Unkown scope #{ rest.join(', ') }"
end
end
end
@@ -19,8 +19,12 @@ class Interactor
def process(*entries)
scopes, rest = ::Guard::Interactor.convert_scope(entries)
- ::Guard.within_preserved_state do
- ::Guard.runner.run_on_changes(rest, [], [])
+ if rest.length != 0
+ ::Guard.within_preserved_state do
+ ::Guard.runner.run_on_changes(rest, [], [])
+ end
+ else
+ output.puts 'Please specify a file.'
end
end
@@ -22,7 +22,7 @@ def process(*entries)
if rest.length == 0
::Guard.reload scopes
else
- puts "Unkown scope #{ rest.join(', ') }"
+ output.puts "Unkown scope #{ rest.join(', ') }"
end
end
View
@@ -21,6 +21,8 @@ class Interactor
HISTORY_FILE = '~/.guard_history'
def initialize
+ return if ENV['GUARD_ENV'] == 'test'
+
Pry.config.history.file = HISTORY_FILE
Pry.config.hooks.add_hook :when_started, :load_guard_rc do
@@ -67,8 +69,8 @@ def stop
# Converts and validates a plain text scope
# to a valid plugin or group scope.
#
- # @param [String] entries the text scope
- # @return [Array<Hash}, Array] the plugin or group scope, the unknown entries
+ # @param [Array<String>] entries the text scope
+ # @return [Hash, Array<String>] the plugin or group scope, the unknown entries
#
def self.convert_scope(entries)
scopes = { }
@@ -0,0 +1,46 @@
+require 'spec_helper'
+
+describe 'Guard::Interactor::ALL' do
+
+ before(:all) { class ::Guard::Bar < ::Guard::Guard; end }
+ after(:all) { ::Guard.instance_eval { remove_const(:Bar) } }
+
+ before(:each) do
+ Guard.stub(:run_all)
+ Guard.stub(:setup_interactor)
+ 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 'runs the :run_all action' do
+ Guard.should_receive(:run_all).with({})
+ Pry.run_command 'all'
+ end
+ end
+
+ context 'with a valid Guard group scope' do
+ it 'runs the :run_all action with the given scope' do
+ Guard.should_receive(:run_all).with({ :group => foo_group })
+ Pry.run_command 'all foo'
+ end
+ end
+
+ context 'with a valid Guard plugin scope' do
+ it 'runs the :run_all action with the given scope' do
+ Guard.should_receive(:run_all).with({ :guard => bar_guard })
+ Pry.run_command 'all bar'
+ end
+ end
+
+ context 'with an invalid scope' do
+ it 'does not run the action' do
+ Guard.should_not_receive(:run_all)
+ Pry.run_command 'all baz'
+ end
+ end
+ end
+end
@@ -0,0 +1,33 @@
+require 'spec_helper'
+
+describe 'Guard::Interactor::CHANGE' do
+
+ let!(:guard) { ::Guard.setup }
+
+ before do
+ Guard.runner.stub(:run_on_changes)
+ end
+
+ describe '#perform' do
+ context 'with a file' do
+ it 'runs the :run_all 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
+ ::Guard.runner.should_receive(:run_on_changes).with(['foo', 'bar', 'baz'], [], [])
+ Pry.run_command 'change foo bar baz'
+ end
+ end
+
+ context 'without a file' do
+ it 'does not run the :run_on_changes action' do
+ ::Guard.runner.should_not_receive(:run_on_changes)
+ Pry.run_command 'change'
+ end
+ end
+ end
+end
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+describe 'Guard::Interactor::NOTIFICATION' do
+
+ before do
+ ::Guard::Notifier.stub(:toggle)
+ end
+
+ describe '#perform' do
+ it 'toggles the Guard notifier' do
+ ::Guard::Notifier.should_receive(:toggle)
+ Pry.run_command 'notification'
+ end
+ end
+end
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+describe 'Guard::Interactor::PAUSE' do
+
+ before do
+ ::Guard::stub(:pause)
+ end
+
+ describe '#perform' do
+ it 'pauses Guard' do
+ ::Guard.should_receive(:pause)
+ Pry.run_command 'pause'
+ end
+ end
+end
@@ -0,0 +1,46 @@
+require 'spec_helper'
+
+describe 'Guard::Interactor::RELOAD' do
+
+ before(:all) { class ::Guard::Bar < ::Guard::Guard; end }
+ after(:all) { ::Guard.instance_eval { remove_const(:Bar) } }
+
+ before(:each) do
+ Guard.stub(:reload)
+ Guard.stub(:setup_interactor)
+ 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 'runs the :reload action' do
+ Guard.should_receive(:reload).with({})
+ Pry.run_command 'reload'
+ end
+ end
+
+ context 'with a valid Guard group scope' do
+ it 'runs the :reload action with the given scope' do
+ Guard.should_receive(:reload).with({ :group => foo_group })
+ Pry.run_command 'reload foo'
+ end
+ end
+
+ context 'with a valid Guard plugin scope' do
+ it 'runs the :reload action with the given scope' do
+ Guard.should_receive(:reload).with({ :guard => bar_guard })
+ Pry.run_command 'reload bar'
+ end
+ end
+
+ context 'with an invalid scope' do
+ it 'does not run the action' do
+ Guard.should_not_receive(:reload)
+ Pry.run_command 'reload baz'
+ end
+ end
+ end
+end
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+describe 'Guard::Interactor::SHOW' do
+
+ before do
+ ::Guard::DslDescriber::stub(:show)
+ end
+
+ describe '#perform' do
+ it 'shows the DSL description' do
+ ::Guard::DslDescriber.should_receive(:show)
+ Pry.run_command 'show'
+ end
+ end
+end
@@ -1,6 +1,46 @@
require 'spec_helper'
describe Guard::Interactor do
- subject { Guard::Interactor.new }
+ describe '.convert_scope' do
+ before(:all) do
+ class Guard::Foo < Guard::Guard; end
+ class Guard::Bar < Guard::Guard; end
+ end
+
+ before(:each) do
+ guard = ::Guard.setup
+ @backend_group = guard.add_group(:backend)
+ @frontend_group = guard.add_group(:frontend)
+ @foo_guard = guard.add_guard(:foo, [], [], { :group => :backend })
+ @bar_guard = guard.add_guard(:bar, [], [], { :group => :frontend })
+ end
+
+ after(:all) do
+ ::Guard.instance_eval do
+ remove_const(:Foo)
+ remove_const(:Bar)
+ end
+ end
+
+ it 'returns a group scope' do
+ scopes, _ = Guard::Interactor.convert_scope %w(backend)
+ scopes.should eql({ :group => @backend_group })
+ scopes, _ = Guard::Interactor.convert_scope %w(frontend)
+ scopes.should eql({ :group => @frontend_group })
+ end
+
+ it 'returns a plugin scope' do
+ scopes, _ = Guard::Interactor.convert_scope %w(foo)
+ scopes.should eql({ :guard => @foo_guard })
+ scopes, _ = Guard::Interactor.convert_scope %w(bar)
+ scopes.should eql({ :guard => @bar_guard })
+ end
+
+ it 'returns the unkown scopes' do
+ _, unkown = Guard::Interactor.convert_scope %w(unkown scope)
+ unkown.should eql %w(unkown scope)
+ end
+
+ end
end

0 comments on commit b49a00b

Please sign in to comment.