Merge branch 'master' into hook
Conflicts: lib/guard/guard.rb spec/guard_spec.rb
This commit is contained in:
commit
5b8ae609da
@ -1,4 +1,4 @@
|
||||
guard('rspec', :version => 2) do
|
||||
guard('rspec', :cli => '-f doc', :version => 2) do
|
||||
watch(%r{^spec/(.*)_spec\.rb})
|
||||
watch(%r{^lib/(.*)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
|
||||
watch('spec/spec_helper.rb') { "spec" }
|
||||
|
@ -34,9 +34,7 @@ module Guard
|
||||
UI.error "No guards found in Guardfile, please add at least one."
|
||||
else
|
||||
listener.on_change do |files|
|
||||
if Watcher.match_files?(guards, files)
|
||||
run { run_on_change_for_all_guards(files) }
|
||||
end
|
||||
run { run_on_change_for_all_guards(files) } if Watcher.match_files?(guards, files)
|
||||
end
|
||||
|
||||
UI.info "Guard is now watching at '#{Dir.pwd}'"
|
||||
@ -50,11 +48,12 @@ module Guard
|
||||
paths = Watcher.match_files(guard, files)
|
||||
supervised_task(guard, :run_on_change, paths) unless paths.empty?
|
||||
end
|
||||
|
||||
# Reparse the whole directory to catch new files modified during the guards run
|
||||
new_modified_files = listener.modified_files([Dir.pwd + '/'], :all => true)
|
||||
listener.update_last_event
|
||||
unless new_modified_files.empty?
|
||||
run { run_on_change_for_all_guards(new_modified_files) }
|
||||
run { run_on_change_for_all_guards(new_modified_files) } if Watcher.match_files?(guards, files)
|
||||
end
|
||||
end
|
||||
|
||||
@ -97,7 +96,7 @@ module Guard
|
||||
end
|
||||
|
||||
def locate_guard(name)
|
||||
`gem which guard/#{name}`.chomp
|
||||
Gem.source_index.find_name("guard-#{name}").last.full_gem_path
|
||||
rescue
|
||||
UI.error "Could not find 'guard-#{name}' gem path."
|
||||
end
|
||||
|
@ -46,7 +46,6 @@ module Guard
|
||||
false
|
||||
end
|
||||
|
||||
|
||||
def self.mac?
|
||||
Config::CONFIG['target_os'] =~ /darwin/i
|
||||
end
|
||||
|
@ -1,5 +1,4 @@
|
||||
require 'spec_helper'
|
||||
require 'guard/dsl'
|
||||
|
||||
describe Guard::Dsl do
|
||||
subject { Guard::Dsl }
|
||||
@ -8,14 +7,14 @@ describe Guard::Dsl do
|
||||
::Guard.stub!(:add_guard)
|
||||
end
|
||||
|
||||
it "should write an error message when no Guardfile is found" do
|
||||
it "displays an error message when no Guardfile is found" do
|
||||
Dir.stub!(:pwd).and_return("no_guardfile_here")
|
||||
|
||||
Guard::UI.should_receive(:error).with("No Guardfile in current folder, please create one.")
|
||||
lambda { subject.evaluate_guardfile }.should raise_error
|
||||
end
|
||||
|
||||
it "should write an error message when Guardfile is not valid" do
|
||||
it "displays an error message when Guardfile is not valid" do
|
||||
mock_guardfile_content("This Guardfile is invalid!")
|
||||
|
||||
Guard::UI.should_receive(:error).with(/Invalid Guardfile, original error is:\n/)
|
||||
@ -23,15 +22,23 @@ describe Guard::Dsl do
|
||||
end
|
||||
|
||||
describe ".guardfile_include?" do
|
||||
it "should detect a guard specified as a string" do
|
||||
it "detects a guard specified by a string with simple quotes" do
|
||||
mock_guardfile_content("guard 'test'")
|
||||
|
||||
subject.guardfile_include?('test').should be_true
|
||||
end
|
||||
|
||||
it "should detect a guard specified as a symbol" do
|
||||
mock_guardfile_content("guard :test")
|
||||
it "detects a guard specified by a string with double quotes" do
|
||||
mock_guardfile_content('guard "test"')
|
||||
subject.guardfile_include?('test').should be_true
|
||||
end
|
||||
|
||||
it "detects a guard specified by a symbol" do
|
||||
mock_guardfile_content("guard :test")
|
||||
subject.guardfile_include?('test').should be_true
|
||||
end
|
||||
|
||||
it "detects a guard wrapped in parentheses" do
|
||||
mock_guardfile_content("guard(:test)")
|
||||
subject.guardfile_include?('test').should be_true
|
||||
end
|
||||
end
|
||||
|
@ -1,27 +1,27 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Guard::Listener do
|
||||
subject { described_class }
|
||||
subject { Guard::Listener }
|
||||
|
||||
describe ".select_and_init" do
|
||||
before(:each) { @target_os = Config::CONFIG['target_os'] }
|
||||
after(:each) { Config::CONFIG['target_os'] = @target_os }
|
||||
|
||||
it "should use darwin listener on Mac OS X" do
|
||||
it "uses darwin listener on Mac OS X" do
|
||||
Config::CONFIG['target_os'] = 'darwin10.4.0'
|
||||
Guard::Darwin.stub(:usable?).and_return(true)
|
||||
Guard::Darwin.should_receive(:new)
|
||||
subject.select_and_init
|
||||
end
|
||||
|
||||
it "should use polling listener on Windows" do
|
||||
it "uses polling listener on Windows" do
|
||||
Config::CONFIG['target_os'] = 'win32'
|
||||
Guard::Polling.stub(:usable?).and_return(true)
|
||||
Guard::Polling.should_receive(:new)
|
||||
subject.select_and_init
|
||||
end
|
||||
|
||||
it "should use linux listener on Linux" do
|
||||
it "uses linux listener on Linux" do
|
||||
Config::CONFIG['target_os'] = 'linux'
|
||||
Guard::Linux.stub(:usable?).and_return(true)
|
||||
Guard::Linux.should_receive(:new)
|
||||
@ -32,7 +32,7 @@ describe Guard::Listener do
|
||||
describe "#update_last_event" do
|
||||
subject { described_class.new }
|
||||
|
||||
it "should update last_event with time.now" do
|
||||
it "updates last_event with time.now" do
|
||||
time = Time.now
|
||||
subject.update_last_event
|
||||
subject.last_event.should >= time
|
||||
|
@ -5,17 +5,17 @@ describe Guard::Darwin do
|
||||
subject { Guard::Darwin }
|
||||
|
||||
if linux?
|
||||
it "should not be usable on linux" do
|
||||
it "isn't usable on linux" do
|
||||
subject.should_not be_usable
|
||||
end
|
||||
end
|
||||
|
||||
if mac?
|
||||
it "should be usable on 10.6" do
|
||||
it "is usable on 10.6" do
|
||||
subject.should be_usable
|
||||
end
|
||||
|
||||
describe "watch" do
|
||||
describe "#on_change" do
|
||||
before(:each) do
|
||||
@results = []
|
||||
@listener = Guard::Darwin.new
|
||||
@ -24,7 +24,7 @@ describe Guard::Darwin do
|
||||
end
|
||||
end
|
||||
|
||||
it "should catch new file" do
|
||||
it "catches new file" do
|
||||
file = @fixture_path.join("newfile.rb")
|
||||
File.exists?(file).should be_false
|
||||
start
|
||||
@ -34,7 +34,7 @@ describe Guard::Darwin do
|
||||
@results.should == ['spec/fixtures/newfile.rb']
|
||||
end
|
||||
|
||||
it "should catch file update" do
|
||||
it "catches file update" do
|
||||
file = @fixture_path.join("folder1/file1.txt")
|
||||
File.exists?(file).should be_true
|
||||
start
|
||||
@ -43,7 +43,7 @@ describe Guard::Darwin do
|
||||
@results.should == ['spec/fixtures/folder1/file1.txt']
|
||||
end
|
||||
|
||||
it "should catch files update" do
|
||||
it "catches files update" do
|
||||
file1 = @fixture_path.join("folder1/file1.txt")
|
||||
file2 = @fixture_path.join("folder1/folder2/file2.txt")
|
||||
File.exists?(file1).should be_true
|
||||
@ -60,13 +60,13 @@ describe Guard::Darwin do
|
||||
private
|
||||
|
||||
def start
|
||||
sleep 1
|
||||
sleep 0.6
|
||||
Thread.new { @listener.start }
|
||||
sleep 1
|
||||
sleep 0.6
|
||||
end
|
||||
|
||||
def stop
|
||||
sleep 1
|
||||
sleep 0.6
|
||||
@listener.stop
|
||||
end
|
||||
|
||||
|
@ -6,17 +6,17 @@ describe Guard::Linux do
|
||||
subject { Guard::Linux }
|
||||
|
||||
if mac?
|
||||
it "should not be usable on 10.6" do
|
||||
it "isn't usable on 10.6" do
|
||||
subject.should_not be_usable
|
||||
end
|
||||
end
|
||||
|
||||
if linux?
|
||||
it "should be usable on linux" do
|
||||
it "is usable on linux" do
|
||||
subject.should be_usable
|
||||
end
|
||||
|
||||
describe "start" do
|
||||
describe "#start" do
|
||||
before(:each) do
|
||||
@listener = Guard::Linux.new
|
||||
end
|
||||
@ -40,7 +40,7 @@ describe Guard::Linux do
|
||||
|
||||
end
|
||||
|
||||
describe "watch" do
|
||||
describe "#on_change" do
|
||||
before(:each) do
|
||||
@results = []
|
||||
@listener = Guard::Linux.new
|
||||
|
@ -11,35 +11,37 @@ describe Guard::Polling do
|
||||
end
|
||||
end
|
||||
|
||||
it "should catch new file" do
|
||||
file = @fixture_path.join("newfile.rb")
|
||||
File.exists?(file).should be_false
|
||||
start
|
||||
FileUtils.touch file
|
||||
stop
|
||||
File.delete file
|
||||
@results.should == ['spec/fixtures/newfile.rb']
|
||||
end
|
||||
describe "#on_change" do
|
||||
it "catches new file" do
|
||||
file = @fixture_path.join("newfile.rb")
|
||||
File.exists?(file).should be_false
|
||||
start
|
||||
FileUtils.touch file
|
||||
stop
|
||||
File.delete file
|
||||
@results.should == ['spec/fixtures/newfile.rb']
|
||||
end
|
||||
|
||||
it "should catch file update" do
|
||||
file = @fixture_path.join("folder1/file1.txt")
|
||||
File.exists?(file).should be_true
|
||||
start
|
||||
FileUtils.touch file
|
||||
stop
|
||||
@results.should == ['spec/fixtures/folder1/file1.txt']
|
||||
end
|
||||
it "catches file update" do
|
||||
file = @fixture_path.join("folder1/file1.txt")
|
||||
File.exists?(file).should be_true
|
||||
start
|
||||
FileUtils.touch file
|
||||
stop
|
||||
@results.should == ['spec/fixtures/folder1/file1.txt']
|
||||
end
|
||||
|
||||
it "should catch files update" do
|
||||
file1 = @fixture_path.join("folder1/file1.txt")
|
||||
file2 = @fixture_path.join("folder1/folder2/file2.txt")
|
||||
File.exists?(file1).should be_true
|
||||
File.exists?(file2).should be_true
|
||||
start
|
||||
FileUtils.touch file1
|
||||
FileUtils.touch file2
|
||||
stop
|
||||
@results.sort.should == ['spec/fixtures/folder1/file1.txt', 'spec/fixtures/folder1/folder2/file2.txt']
|
||||
it "catches files update" do
|
||||
file1 = @fixture_path.join("folder1/file1.txt")
|
||||
file2 = @fixture_path.join("folder1/folder2/file2.txt")
|
||||
File.exists?(file1).should be_true
|
||||
File.exists?(file2).should be_true
|
||||
start
|
||||
FileUtils.touch file1
|
||||
FileUtils.touch file2
|
||||
stop
|
||||
@results.sort.should == ['spec/fixtures/folder1/file1.txt', 'spec/fixtures/folder1/folder2/file2.txt']
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -3,12 +3,15 @@ require 'spec_helper'
|
||||
describe Guard::Notifier do
|
||||
subject { Guard::Notifier }
|
||||
|
||||
describe "notify" do
|
||||
before(:each) { ENV["GUARD_ENV"] = 'special_test' }
|
||||
describe ".notify" do
|
||||
before(:each) do
|
||||
@saved_guard_env = ENV["GUARD_ENV"]
|
||||
ENV["GUARD_ENV"] = 'dont_mute_notify'
|
||||
end
|
||||
|
||||
if mac?
|
||||
require 'growl'
|
||||
it "should use Growl on Mac OS X" do
|
||||
it "uses Growl on Mac OS X" do
|
||||
Growl.should_receive(:notify).with("great",
|
||||
:title => "Guard",
|
||||
:icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
|
||||
@ -20,7 +23,7 @@ describe Guard::Notifier do
|
||||
|
||||
if linux?
|
||||
require 'libnotify'
|
||||
it "should use Libnotify on Linux" do
|
||||
it "uses Libnotify on Linux" do
|
||||
Libnotify.should_receive(:show).with(
|
||||
:body => "great",
|
||||
:summary => 'Guard',
|
||||
@ -30,12 +33,12 @@ describe Guard::Notifier do
|
||||
end
|
||||
end
|
||||
|
||||
context "turned off" do
|
||||
describe ".turn_off" do
|
||||
before(:each) { subject.turn_off }
|
||||
|
||||
if mac?
|
||||
require 'growl'
|
||||
it "should do nothing" do
|
||||
it "does nothing" do
|
||||
Growl.should_not_receive(:notify)
|
||||
subject.notify 'great', :title => 'Guard'
|
||||
end
|
||||
@ -43,14 +46,14 @@ describe Guard::Notifier do
|
||||
|
||||
if linux?
|
||||
require 'libnotify'
|
||||
it "should do nothing" do
|
||||
it "does nothing" do
|
||||
Libnotify.should_not_receive(:show)
|
||||
subject.notify 'great', :title => 'Guard'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
after(:each) { ENV["GUARD_ENV"] = 'test' }
|
||||
after(:each) { ENV["GUARD_ENV"] = @saved_guard_env }
|
||||
end
|
||||
|
||||
end
|
@ -3,26 +3,30 @@ require 'guard/guard'
|
||||
|
||||
describe Guard::Watcher do
|
||||
|
||||
describe "pattern" do
|
||||
it "should be required" do
|
||||
expect { Guard::Watcher.new }.to raise_error(ArgumentError)
|
||||
end
|
||||
describe "#initialize" do
|
||||
describe "pattern parameter" do
|
||||
it "is required" do
|
||||
expect { Guard::Watcher.new }.to raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "can be a string" do
|
||||
Guard::Watcher.new('spec_helper.rb').pattern.should == 'spec_helper.rb'
|
||||
end
|
||||
it "can be a string" do
|
||||
Guard::Watcher.new('spec_helper.rb').pattern.should == 'spec_helper.rb'
|
||||
end
|
||||
|
||||
it "can be a regexp" do
|
||||
Guard::Watcher.new(/spec_helper\.rb/).pattern.should == /spec_helper\.rb/
|
||||
end
|
||||
it "can be a regexp" do
|
||||
Guard::Watcher.new(/spec_helper\.rb/).pattern.should == /spec_helper\.rb/
|
||||
end
|
||||
|
||||
describe "string looking like a regex" do
|
||||
before(:each) { Guard::UI.should_receive(:info).any_number_of_times }
|
||||
describe "can be a string looking like a regex (deprecated)" do
|
||||
before(:each) { Guard::UI.should_receive(:info).any_number_of_times }
|
||||
|
||||
specify { Guard::Watcher.new('^spec_helper.rb').pattern.should == /^spec_helper.rb/ }
|
||||
specify { Guard::Watcher.new('spec_helper.rb$').pattern.should == /spec_helper.rb$/ }
|
||||
specify { Guard::Watcher.new('spec_helper\.rb').pattern.should == /spec_helper\.rb/ }
|
||||
specify { Guard::Watcher.new('.*_spec.rb').pattern.should == /.*_spec.rb/ }
|
||||
it "and is automatically casted to a regex" do
|
||||
Guard::Watcher.new('^spec_helper.rb').pattern.should == /^spec_helper.rb/
|
||||
Guard::Watcher.new('spec_helper.rb$').pattern.should == /spec_helper.rb$/
|
||||
Guard::Watcher.new('spec_helper\.rb').pattern.should == /spec_helper\.rb/
|
||||
Guard::Watcher.new('.*_spec.rb').pattern.should == /.*_spec.rb/
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -44,7 +44,7 @@ describe Guard do
|
||||
end
|
||||
|
||||
describe ".locate_guard" do
|
||||
it "should return guard-rspec gem path" do
|
||||
it "returns guard-rspec gem path" do
|
||||
guard_path = Guard.locate_guard('rspec')
|
||||
guard_path.should match(/^.*\/guard-rspec-.*$/)
|
||||
guard_path.should == guard_path.chomp
|
||||
@ -64,15 +64,15 @@ describe Guard do
|
||||
@g.stub!(:regular_with_arg).with("given_path") { "i'm a success" }
|
||||
end
|
||||
|
||||
it "should not fire the guard with a supervised method without argument" do
|
||||
it "doesn't fire the guard with a supervised method without argument" do
|
||||
lambda { subject.supervised_task(@g, :regular) }.should_not change(subject.guards, :size)
|
||||
end
|
||||
|
||||
it "should not fire the guard with a supervised method with argument" do
|
||||
it "doesn't fire the guard with a supervised method with argument" do
|
||||
lambda { subject.supervised_task(@g, :regular_with_arg, "given_path") }.should_not change(subject.guards, :size)
|
||||
end
|
||||
|
||||
it "should return the result of the supervised method" do
|
||||
it "returns the result of the supervised method" do
|
||||
::Guard.supervised_task(@g, :regular).should be_true
|
||||
::Guard.supervised_task(@g, :regular_with_arg, "given_path").should == "i'm a success"
|
||||
end
|
||||
@ -87,12 +87,12 @@ describe Guard do
|
||||
describe "tasks that raise an exception" do
|
||||
before(:each) { @g.stub!(:failing) { raise "I break your system" } }
|
||||
|
||||
it "should fire the guard" do
|
||||
it "fires the guard" do
|
||||
lambda { subject.supervised_task(@g, :failing) }.should change(subject.guards, :size).by(-1)
|
||||
subject.guards.should_not include(@g)
|
||||
end
|
||||
|
||||
it "should return the exception object" do
|
||||
it "returns the exception object" do
|
||||
failing_result = ::Guard.supervised_task(@g, :failing)
|
||||
failing_result.should be_kind_of(Exception)
|
||||
failing_result.message.should == 'I break your system'
|
||||
@ -106,6 +106,11 @@ describe Guard do
|
||||
end
|
||||
end
|
||||
|
||||
describe ".locate_guard" do
|
||||
it "returns the path of the guard gem" do
|
||||
Guard.locate_guard('rspec').should == Gem.source_index.find_name("guard-rspec").last.full_gem_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user