Permalink
Browse files

Fix param typing and specs.

  • Loading branch information...
1 parent bebdeb8 commit e887c5e31662c8d8e9e6f0ef4199de672c3282da @netzpirat netzpirat committed Oct 19, 2012
Showing with 69 additions and 60 deletions.
  1. +11 −11 lib/guard/dsl.rb
  2. +15 −15 spec/guard/dsl_spec.rb
  3. +1 −1 spec/guard/guard_spec.rb
  4. +1 −1 spec/guard/guardfile_spec.rb
  5. +12 −12 spec/guard/ui_spec.rb
  6. +29 −20 spec/guard_spec.rb
View
22 lib/guard/dsl.rb
@@ -16,7 +16,7 @@ module Guard
#
# A more advanced DSL use is the `callback` keyword that allows you to execute arbitrary
# code before or after any of the `start`, `stop`, `reload`, `run_all`, `run_on_changes`,
- # `run_on_additions`, `run_on_modifications` and `run_on_removals` Guard plugins method.
+ # `run_on_additions`, `run_on_modifications` and `run_on_removals` Guard plugins method.
# You can even insert more hooks inside these methods.
# Please [checkout the Wiki page](https://github.com/guard/guard/wiki/Hooks-and-callbacks) for more details.
#
@@ -496,33 +496,33 @@ def filter(*regexps)
#
def logger(options)
if options[:level]
- options[:level] = options[:level].to_sym
-
+ options[:level] = options[:level].to_sym
+
unless [:debug, :info, :warn, :error].include? options[:level]
::Guard::UI.warning "Invalid log level `#{ options[:level] }` ignored. Please use either :debug, :info, :warn or :error."
options.delete :level
end
end
-
- if options[:only] && options[:expect]
+
+ if options[:only] && options[:except]
::Guard::UI.warning "You cannot specify the logger options :only and :except at the same time."
options.delete :only
- options.delete :expect
+ options.delete :except
end
-
+
if options[:only] && !(options[:only].class == Regexp)
::Guard::UI.warning "Invalid log option `#{ options[:only] }` ignored. Please specify a Regexp for :only."
options.delete :only
end
- if options[:expect] && !(options[:expect].class == Regexp)
- ::Guard::UI.warning "Invalid log option `#{ options[:expect] }` ignored. Please specify a Regexp for :except."
- options.delete :expect
+ if options[:except] && !(options[:except].class == Regexp)
+ ::Guard::UI.warning "Invalid log option `#{ options[:except] }` ignored. Please specify a Regexp for :except."
+ options.delete :except
end
::Guard::UI.options = ::Guard::UI.options.merge options
end
-
+
end
end
View
30 spec/guard/dsl_spec.rb
@@ -513,7 +513,7 @@ def self.call(guard_class, event, args)
describe "#logger" do
after { Guard::UI.options = { :level => :info, :template => ':time - :severity - :message', :time_format => '%H:%M:%S' } }
-
+
context 'with valid options' do
it "sets the logger log level" do
described_class.evaluate_guardfile(:guardfile_contents => "logger :level => :error")
@@ -529,23 +529,23 @@ def self.call(guard_class, event, args)
described_class.evaluate_guardfile(:guardfile_contents => "logger :template => ':message - :severity'")
Guard::UI.options[:template].should eql ':message - :severity'
end
-
+
it "sets the logger time format" do
described_class.evaluate_guardfile(:guardfile_contents => "logger :time_format => '%Y'")
Guard::UI.options[:time_format].should eql '%Y'
end
-
+
it "sets the logger only filter" do
described_class.evaluate_guardfile(:guardfile_contents => "logger :only => /cucumber/i")
Guard::UI.options[:only].should eql /cucumber/i
end
-
- it "sets the logger only filter" do
- described_class.evaluate_guardfile(:guardfile_contents => "logger :expect => /jasmine/i")
- Guard::UI.options[:expect].should eql /jasmine/i
+
+ it "sets the logger except filter" do
+ described_class.evaluate_guardfile(:guardfile_contents => "logger :except=> /jasmine/i")
+ Guard::UI.options[:except].should eql /jasmine/i
end
end
-
+
context 'with invalid options' do
context 'for the log level' do
it 'shows a warning' do
@@ -559,17 +559,17 @@ def self.call(guard_class, event, args)
end
end
- context 'when having both the :only and :expect options' do
+ context 'when having both the :only and :except options' do
it 'shows a warning' do
Guard::UI.should_receive(:warning).with "You cannot specify the logger options :only and :except at the same time."
- described_class.evaluate_guardfile(:guardfile_contents => "logger :only => /jasmine/, :expect => /rspec/")
-
+ described_class.evaluate_guardfile(:guardfile_contents => "logger :only => /jasmine/, :except=> /rspec/")
+
end
it 'removes the options' do
- described_class.evaluate_guardfile(:guardfile_contents => "logger :only => /jasmine/, :expect => /rspec/")
+ described_class.evaluate_guardfile(:guardfile_contents => "logger :only => /jasmine/, :except=> /rspec/")
Guard::UI.options[:only].should be_nil
- Guard::UI.options[:expect].should be_nil
+ Guard::UI.options[:except].should be_nil
end
end
@@ -588,11 +588,11 @@ def self.call(guard_class, event, args)
context 'for the log :except option' do
it 'shows a warning' do
Guard::UI.should_receive(:warning).with "Invalid log option `11` ignored. Please specify a Regexp for :except."
- described_class.evaluate_guardfile(:guardfile_contents => "logger :expect => 11")
+ described_class.evaluate_guardfile(:guardfile_contents => "logger :except=> 11")
end
it 'does not set the invalid value' do
- described_class.evaluate_guardfile(:guardfile_contents => "logger :expect => 'hi'")
+ described_class.evaluate_guardfile(:guardfile_contents => "logger :except=> 'hi'")
Guard::UI.options[:except].should be_nil
end
end
View
2 spec/guard/guard_spec.rb
@@ -5,7 +5,7 @@
before do
::Guard::UI.stub(:info)
end
-
+
describe '#initialize' do
it 'assigns the defined watchers' do
View
2 spec/guard/guardfile_spec.rb
@@ -5,7 +5,7 @@
before do
::Guard::UI.stub(:info)
end
-
+
it "has a valid Guardfile template" do
File.exists?(Guard::GUARDFILE_TEMPLATE).should be_true
end
View
24 spec/guard/ui_spec.rb
@@ -2,53 +2,53 @@
describe Guard::UI do
after { Guard::UI.options = { :level => :info, :template => ':time - :severity - :message', :time_format => '%H:%M:%S' } }
-
+
before do
Guard::UI.logger.stub(:info)
Guard::UI.logger.stub(:warn)
Guard::UI.logger.stub(:error)
Guard::UI.logger.stub(:deprecation)
Guard::UI.logger.stub(:debug)
end
-
+
describe '.logger' do
it 'returns the logger instance' do
Guard::UI.logger.should be_an_instance_of Lumberjack::Logger
end
end
-
+
describe '.options' do
it 'returns the default logger options' do
Guard::UI.options.should eql({ :level => :info, :template => ':time - :severity - :message', :time_format => '%H:%M:%S' })
end
end
-
+
describe '.options=' do
it 'sets the logger options' do
Guard::UI.options = { :hi => :ho }
Guard::UI.options.should eql({ :hi => :ho })
end
end
-
+
describe '.info' do
it 'resets the line with the :reset option' do
Guard::UI.should_receive :reset_line
Guard::UI.info('Info message', { :reset => true })
end
-
+
it 'logs the message to with the info severity' do
Guard::UI.logger.should_receive(:info).with('Info message', 'Guard::UiSpec')
Guard::UI.info 'Info message'
end
-
+
context 'with the :only option' do
before { Guard::UI.options[:only] = /A/ }
-
+
it 'shows only the matching messages' do
Guard::UI.logger.should_receive(:info).with('Info message', 'A')
Guard::UI.logger.should_not_receive(:info).with('Info message', 'B')
Guard::UI.logger.should_not_receive(:info).with('Info message', 'C')
-
+
Guard::UI.info 'Info message', :plugin => 'A'
Guard::UI.info 'Info message', :plugin => 'B'
Guard::UI.info 'Info message', :plugin => 'C'
@@ -69,7 +69,7 @@
end
end
end
-
+
describe '.warning' do
it 'resets the line with the :reset option' do
Guard::UI.should_receive :reset_line
@@ -109,7 +109,7 @@
end
end
end
-
+
describe '.error' do
it 'resets the line with the :reset option' do
Guard::UI.should_receive :reset_line
@@ -149,7 +149,7 @@
end
end
end
-
+
describe '.deprecation' do
it 'resets the line with the :reset option' do
Guard::UI.should_receive :reset_line
View
49 spec/guard_spec.rb
@@ -3,13 +3,11 @@
describe Guard do
before do
::Guard::Interactor.stub(:fabricate)
-
+
::Guard::UI.stub(:info)
::Guard::UI.stub(:error)
end
-
- after { Guard.options[:debug] = false }
-
+
describe ".setup" do
let(:options) { { :my_opts => true, :guardfile => File.join(@fixture_path, "Guardfile") } }
subject { ::Guard.setup(options) }
@@ -41,17 +39,6 @@
::Guard.listener.directory.should eq '/usr'
end
- it "logs command execution if the debug option is true" do
- ::Guard.should_receive(:debug_command_execution)
-
- ::Guard.setup(:debug => true)
- end
-
- it "sets the log level to :debug if the debug option is true" do
- ::Guard.setup(:debug => true)
- ::Guard::UI.options[:level].should eql :debug
- end
-
it "call setup_signal_traps" do
::Guard.should_receive(:setup_signal_traps)
subject
@@ -76,18 +63,34 @@
::Guard.should_receive(:setup_interactor)
subject
end
-
+
context 'when deprecations should be shown' do
let(:options) { { :show_deprecations => true, :guardfile => File.join(@fixture_path, "Guardfile") } }
subject { ::Guard.setup(options) }
let(:runner) { mock('runner') }
-
+
it 'calls the runner show deprecations' do
::Guard::Runner.should_receive(:new).and_return runner
runner.should_receive(:deprecation_warning)
subject
end
end
+
+ context 'with the debug mode turned on' do
+ let(:options) { { :debug => true, :guardfile => File.join(@fixture_path, "Guardfile") } }
+ subject { ::Guard.setup(options) }
+ after { Guard.options[:debug] = false }
+
+ it "logs command execution if the debug option is true" do
+ ::Guard.should_receive(:debug_command_execution)
+ subject
+ end
+
+ it "sets the log level to :debug if the debug option is true" do
+ subject
+ ::Guard::UI.options[:level].should eql :debug
+ end
+ end
end
describe ".setup_signal_traps" do
@@ -285,7 +288,7 @@
describe '#reload' do
let(:runner) { stub(:run => true) }
subject { ::Guard.setup }
-
+
before do
::Guard.stub(:runner) { runner }
::Guard::Dsl.stub(:reevaluate_guardfile)
@@ -749,21 +752,27 @@ class Inline < Guard
end
after do
+ Guard.options[:debug] = false
Kernel.send(:remove_method, :system, :'`')
Kernel.send(:define_method, :system, @original_system.to_proc)
Kernel.send(:define_method, :"`", @original_command.to_proc)
end
it "outputs Kernel.#system method parameters" do
- ::Guard.setup(:debug => true)
::Guard::UI.should_receive(:debug).with("Command execution: exit 0")
+ ::Guard.setup(:debug => true)
system("exit", "0").should be_false
end
it "outputs Kernel.#` method parameters" do
+ ::Guard::UI.should_receive(:debug).with("Command execution: echo test")
::Guard.setup(:debug => true)
- ::Guard::UI.should_receive(:debug).twice.with("Command execution: echo test")
`echo test`.should == "test\n"
+ end
+
+ it "outputs %x{} method parameters" do
+ ::Guard::UI.should_receive(:debug).with("Command execution: echo test")
+ ::Guard.setup(:debug => true)
%x{echo test}.should == "test\n"
end

0 comments on commit e887c5e

Please sign in to comment.