Cleaning up all specs.
I basically went through all specs and applied the following rules: * Use `describe` for methods and `context` for contexts. * All class methods starts with `.` and instance methods with `#`. * Removed all `it should`, because the specs _have to_. * Applied a consistant naming on all listener specs. * Make fixture usage more fail save by giving generous sleep times. * Make all behaviour description non-technical and easy to understand. The goal of this excercise was to have a documentation that is easy readable and describes the behaviour and not the implementation. Try it out by using the RSpec documentation format!
This commit is contained in:
parent
34a77dea1a
commit
5f0c815256
@ -14,7 +14,7 @@ describe Guard::Dsl do
|
|||||||
lambda { subject.evaluate_guardfile }.should raise_error
|
lambda { subject.evaluate_guardfile }.should raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
it "displays an error message when Guardfile is not valid" do
|
it "displays an error message when the Guardfile is not valid" do
|
||||||
mock_guardfile_content("This Guardfile is invalid!")
|
mock_guardfile_content("This Guardfile is invalid!")
|
||||||
|
|
||||||
Guard::UI.should_receive(:error).with(/Invalid Guardfile, original error is:\n/)
|
Guard::UI.should_receive(:error).with(/Invalid Guardfile, original error is:\n/)
|
||||||
@ -22,22 +22,22 @@ describe Guard::Dsl do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe ".guardfile_include?" do
|
describe ".guardfile_include?" do
|
||||||
it "detects a guard specified by a string with simple quotes" do
|
it "detects a Guard specified by a string with simple quotes" do
|
||||||
mock_guardfile_content("guard 'test'")
|
mock_guardfile_content("guard 'test'")
|
||||||
subject.guardfile_include?('test').should be_true
|
subject.guardfile_include?('test').should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "detects a guard specified by a string with double quotes" do
|
it "detects a Guard specified by a string with double quotes" do
|
||||||
mock_guardfile_content('guard "test"')
|
mock_guardfile_content('guard "test"')
|
||||||
subject.guardfile_include?('test').should be_true
|
subject.guardfile_include?('test').should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "detects a guard specified by a symbol" do
|
it "detects a Guard specified by a symbol" do
|
||||||
mock_guardfile_content("guard :test")
|
mock_guardfile_content("guard :test")
|
||||||
subject.guardfile_include?('test').should be_true
|
subject.guardfile_include?('test').should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "detects a guard wrapped in parentheses" do
|
it "detects a Guard wrapped in parentheses" do
|
||||||
mock_guardfile_content("guard(:test)")
|
mock_guardfile_content("guard(:test)")
|
||||||
subject.guardfile_include?('test').should be_true
|
subject.guardfile_include?('test').should be_true
|
||||||
end
|
end
|
||||||
@ -59,13 +59,13 @@ describe Guard::Dsl do
|
|||||||
end")
|
end")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should evaluates only the specified group" do
|
it "evaluates only the specified group" do
|
||||||
::Guard.should_receive(:add_guard).with('test', anything, {})
|
::Guard.should_receive(:add_guard).with('test', anything, {})
|
||||||
::Guard.should_not_receive(:add_guard).with('another', anything, {})
|
::Guard.should_not_receive(:add_guard).with('another', anything, {})
|
||||||
subject.evaluate_guardfile(:group => ['x'])
|
subject.evaluate_guardfile(:group => ['x'])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should evaluates only the specified groups" do
|
it "evaluates only the specified groups" do
|
||||||
::Guard.should_receive(:add_guard).with('test', anything, {})
|
::Guard.should_receive(:add_guard).with('test', anything, {})
|
||||||
::Guard.should_receive(:add_guard).with('another', anything, {})
|
::Guard.should_receive(:add_guard).with('another', anything, {})
|
||||||
subject.evaluate_guardfile(:group => ['x', 'y'])
|
subject.evaluate_guardfile(:group => ['x', 'y'])
|
||||||
@ -73,21 +73,21 @@ describe Guard::Dsl do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "#guard" do
|
describe "#guard" do
|
||||||
it "should load a guard specified as a string from the DSL" do
|
it "loads a Guard specified as a string from the DSL" do
|
||||||
mock_guardfile_content("guard 'test'")
|
mock_guardfile_content("guard 'test'")
|
||||||
|
|
||||||
::Guard.should_receive(:add_guard).with('test', [], {})
|
::Guard.should_receive(:add_guard).with('test', [], {})
|
||||||
subject.evaluate_guardfile
|
subject.evaluate_guardfile
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should load a guard specified as a symbol from the DSL" do
|
it "loads a Guard specified as a symbol from the DSL" do
|
||||||
mock_guardfile_content("guard :test")
|
mock_guardfile_content("guard :test")
|
||||||
|
|
||||||
::Guard.should_receive(:add_guard).with(:test, [], {})
|
::Guard.should_receive(:add_guard).with(:test, [], {})
|
||||||
subject.evaluate_guardfile
|
subject.evaluate_guardfile
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should receive options when specified" do
|
it "receives the options when specified" do
|
||||||
mock_guardfile_content("guard 'test', :opt_a => 1, :opt_b => 'fancy'")
|
mock_guardfile_content("guard 'test', :opt_a => 1, :opt_b => 'fancy'")
|
||||||
|
|
||||||
::Guard.should_receive(:add_guard).with('test', anything, { :opt_a => 1, :opt_b => 'fancy' })
|
::Guard.should_receive(:add_guard).with('test', anything, { :opt_a => 1, :opt_b => 'fancy' })
|
||||||
@ -96,7 +96,7 @@ describe Guard::Dsl do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "#watch" do
|
describe "#watch" do
|
||||||
it "should receive watchers when specified" do
|
it "should receive the watchers when specified" do
|
||||||
mock_guardfile_content("
|
mock_guardfile_content("
|
||||||
guard 'test' do
|
guard 'test' do
|
||||||
watch('a') { 'b' }
|
watch('a') { 'b' }
|
||||||
|
@ -2,6 +2,7 @@ require 'spec_helper'
|
|||||||
|
|
||||||
describe Guard::Interactor do
|
describe Guard::Interactor do
|
||||||
subject { Guard::Interactor }
|
subject { Guard::Interactor }
|
||||||
|
|
||||||
let(:guard) { mock "guard" }
|
let(:guard) { mock "guard" }
|
||||||
|
|
||||||
before :each do
|
before :each do
|
||||||
@ -10,18 +11,24 @@ describe Guard::Interactor do
|
|||||||
Guard.stub!(:listener).and_return(mock(:start => nil, :stop => nil))
|
Guard.stub!(:listener).and_return(mock(:start => nil, :stop => nil))
|
||||||
end
|
end
|
||||||
|
|
||||||
it ".run_all should send :run_all to all guards" do
|
describe ".run_all" do
|
||||||
|
it "sends :run_all to all guards" do
|
||||||
guard.should_receive(:run_all)
|
guard.should_receive(:run_all)
|
||||||
subject.run_all
|
subject.run_all
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it ".stop should send :stop to all guards" do
|
describe ".stop" do
|
||||||
|
it "sends :stop to all guards" do
|
||||||
guard.should_receive(:stop)
|
guard.should_receive(:stop)
|
||||||
lambda { subject.stop }.should raise_error(SystemExit)
|
lambda { subject.stop }.should raise_error(SystemExit)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it ".reload should send :reload to all guards" do
|
describe ".reload" do
|
||||||
|
it "sends :reload to all guards" do
|
||||||
guard.should_receive(:reload)
|
guard.should_receive(:reload)
|
||||||
subject.reload
|
subject.reload
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
@ -3,27 +3,25 @@ require 'spec_helper'
|
|||||||
describe Guard::Listener do
|
describe Guard::Listener do
|
||||||
subject { Guard::Listener }
|
subject { Guard::Listener }
|
||||||
|
|
||||||
after(:all) { sleep 1 }
|
|
||||||
|
|
||||||
describe ".select_and_init" do
|
describe ".select_and_init" do
|
||||||
before(:each) { @target_os = Config::CONFIG['target_os'] }
|
before(:each) { @target_os = Config::CONFIG['target_os'] }
|
||||||
after(:each) { Config::CONFIG['target_os'] = @target_os }
|
after(:each) { Config::CONFIG['target_os'] = @target_os }
|
||||||
|
|
||||||
it "uses darwin listener on Mac OS X" do
|
it "uses the Darwin listener on Mac OS X" do
|
||||||
Config::CONFIG['target_os'] = 'darwin10.4.0'
|
Config::CONFIG['target_os'] = 'darwin10.4.0'
|
||||||
Guard::Darwin.stub(:usable?).and_return(true)
|
Guard::Darwin.stub(:usable?).and_return(true)
|
||||||
Guard::Darwin.should_receive(:new)
|
Guard::Darwin.should_receive(:new)
|
||||||
subject.select_and_init
|
subject.select_and_init
|
||||||
end
|
end
|
||||||
|
|
||||||
it "uses windows listener on Windows" do
|
it "uses the Windows listener on Windows" do
|
||||||
Config::CONFIG['target_os'] = 'mingw'
|
Config::CONFIG['target_os'] = 'mingw'
|
||||||
Guard::Windows.stub(:usable?).and_return(true)
|
Guard::Windows.stub(:usable?).and_return(true)
|
||||||
Guard::Windows.should_receive(:new)
|
Guard::Windows.should_receive(:new)
|
||||||
subject.select_and_init
|
subject.select_and_init
|
||||||
end
|
end
|
||||||
|
|
||||||
it "uses linux listener on Linux" do
|
it "uses the Linux listener on Linux" do
|
||||||
Config::CONFIG['target_os'] = 'linux'
|
Config::CONFIG['target_os'] = 'linux'
|
||||||
Guard::Linux.stub(:usable?).and_return(true)
|
Guard::Linux.stub(:usable?).and_return(true)
|
||||||
Guard::Linux.should_receive(:new)
|
Guard::Linux.should_receive(:new)
|
||||||
@ -34,7 +32,7 @@ describe Guard::Listener do
|
|||||||
describe "#update_last_event" do
|
describe "#update_last_event" do
|
||||||
subject { described_class.new }
|
subject { described_class.new }
|
||||||
|
|
||||||
it "updates last_event with time.now" do
|
it "updates the last event to the current time" do
|
||||||
time = Time.now
|
time = Time.now
|
||||||
subject.update_last_event
|
subject.update_last_event
|
||||||
subject.last_event.to_i.should >= time.to_i
|
subject.last_event.to_i.should >= time.to_i
|
||||||
@ -71,9 +69,10 @@ describe Guard::Listener do
|
|||||||
it "ignores the files for the second time" do
|
it "ignores the files for the second time" do
|
||||||
FileUtils.touch([file1, file2, file3])
|
FileUtils.touch([file1, file2, file3])
|
||||||
subject.modified_files([@fixture_path.join("folder1/")], {}).should =~ ["spec/fixtures/folder1/deletedfile1.txt", "spec/fixtures/folder1/file1.txt"]
|
subject.modified_files([@fixture_path.join("folder1/")], {}).should =~ ["spec/fixtures/folder1/deletedfile1.txt", "spec/fixtures/folder1/file1.txt"]
|
||||||
sleep 0.6
|
sleep 1
|
||||||
FileUtils.touch([file1, file2, file3])
|
FileUtils.touch([file1, file2, file3])
|
||||||
subject.modified_files([@fixture_path.join("folder1/")], {}).should == []
|
subject.modified_files([@fixture_path.join("folder1/")], {}).should == []
|
||||||
|
sleep 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -83,10 +82,11 @@ describe Guard::Listener do
|
|||||||
it "identifies the files for the second time" do
|
it "identifies the files for the second time" do
|
||||||
FileUtils.touch([file1, file2, file3])
|
FileUtils.touch([file1, file2, file3])
|
||||||
subject.modified_files([@fixture_path.join("folder1/")], {}).should =~ ["spec/fixtures/folder1/deletedfile1.txt", "spec/fixtures/folder1/file1.txt"]
|
subject.modified_files([@fixture_path.join("folder1/")], {}).should =~ ["spec/fixtures/folder1/deletedfile1.txt", "spec/fixtures/folder1/file1.txt"]
|
||||||
sleep 0.6
|
sleep 1
|
||||||
FileUtils.touch([file2, file3])
|
FileUtils.touch([file2, file3])
|
||||||
File.open(file1, "w") { |f| f.write("changed content") }
|
File.open(file1, "w") { |f| f.write("changed content") }
|
||||||
subject.modified_files([@fixture_path.join("folder1/")], {}).should =~ ["spec/fixtures/folder1/file1.txt"]
|
subject.modified_files([@fixture_path.join("folder1/")], {}).should =~ ["spec/fixtures/folder1/file1.txt"]
|
||||||
|
sleep 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -24,7 +24,7 @@ describe Guard::Darwin do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "catches new file" do
|
it "catches a new file" do
|
||||||
file = @fixture_path.join("newfile.rb")
|
file = @fixture_path.join("newfile.rb")
|
||||||
File.exists?(file).should be_false
|
File.exists?(file).should be_false
|
||||||
start
|
start
|
||||||
@ -34,7 +34,7 @@ describe Guard::Darwin do
|
|||||||
@results.should == ['spec/fixtures/newfile.rb']
|
@results.should == ['spec/fixtures/newfile.rb']
|
||||||
end
|
end
|
||||||
|
|
||||||
it "catches file update" do
|
it "catches a single file update" do
|
||||||
file = @fixture_path.join("folder1/file1.txt")
|
file = @fixture_path.join("folder1/file1.txt")
|
||||||
File.exists?(file).should be_true
|
File.exists?(file).should be_true
|
||||||
start
|
start
|
||||||
@ -43,7 +43,7 @@ describe Guard::Darwin do
|
|||||||
@results.should == ['spec/fixtures/folder1/file1.txt']
|
@results.should == ['spec/fixtures/folder1/file1.txt']
|
||||||
end
|
end
|
||||||
|
|
||||||
it "catches files update" do
|
it "catches multiple file updates" do
|
||||||
file1 = @fixture_path.join("folder1/file1.txt")
|
file1 = @fixture_path.join("folder1/file1.txt")
|
||||||
file2 = @fixture_path.join("folder1/folder2/file2.txt")
|
file2 = @fixture_path.join("folder1/folder2/file2.txt")
|
||||||
File.exists?(file1).should be_true
|
File.exists?(file1).should be_true
|
||||||
@ -60,14 +60,15 @@ describe Guard::Darwin do
|
|||||||
private
|
private
|
||||||
|
|
||||||
def start
|
def start
|
||||||
sleep 0.6
|
sleep 1
|
||||||
Thread.new { @listener.start }
|
Thread.new { @listener.start }
|
||||||
sleep 0.6
|
sleep 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def stop
|
def stop
|
||||||
sleep 0.6
|
sleep 1
|
||||||
@listener.stop
|
@listener.stop
|
||||||
|
sleep 1
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -21,12 +21,12 @@ describe Guard::Linux do
|
|||||||
@listener = Guard::Linux.new
|
@listener = Guard::Linux.new
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should call watch_change if first start" do
|
it "calls watch_change on the first start" do
|
||||||
@listener.should_receive(:watch_change)
|
@listener.should_receive(:watch_change)
|
||||||
start
|
start
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not call watch_change if start after stop" do
|
it "doesn't call watch_change on subsequent starts after a stop" do
|
||||||
@listener.stub!(:stop)
|
@listener.stub!(:stop)
|
||||||
start
|
start
|
||||||
stop
|
stop
|
||||||
@ -49,7 +49,7 @@ describe Guard::Linux do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should catch new file" do
|
it "catches a new file" do
|
||||||
file = @fixture_path.join("newfile.rb")
|
file = @fixture_path.join("newfile.rb")
|
||||||
File.exists?(file).should be_false
|
File.exists?(file).should be_false
|
||||||
start
|
start
|
||||||
@ -59,7 +59,7 @@ describe Guard::Linux do
|
|||||||
@results.should == ['spec/fixtures/newfile.rb']
|
@results.should == ['spec/fixtures/newfile.rb']
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should catch file update" do
|
it "catches a single file update" do
|
||||||
file = @fixture_path.join("folder1/file1.txt")
|
file = @fixture_path.join("folder1/file1.txt")
|
||||||
File.exists?(file).should be_true
|
File.exists?(file).should be_true
|
||||||
start
|
start
|
||||||
@ -68,7 +68,7 @@ describe Guard::Linux do
|
|||||||
@results.should == ['spec/fixtures/folder1/file1.txt']
|
@results.should == ['spec/fixtures/folder1/file1.txt']
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should catch files update" do
|
it "catches multiple file updates" do
|
||||||
file1 = @fixture_path.join("folder1/file1.txt")
|
file1 = @fixture_path.join("folder1/file1.txt")
|
||||||
file2 = @fixture_path.join("folder1/folder2/file2.txt")
|
file2 = @fixture_path.join("folder1/folder2/file2.txt")
|
||||||
File.exists?(file1).should be_true
|
File.exists?(file1).should be_true
|
||||||
@ -80,7 +80,7 @@ describe Guard::Linux do
|
|||||||
@results.should == ['spec/fixtures/folder1/file1.txt', 'spec/fixtures/folder1/folder2/file2.txt']
|
@results.should == ['spec/fixtures/folder1/file1.txt', 'spec/fixtures/folder1/folder2/file2.txt']
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should catch deleted file" do
|
it "catches a deleted file" do
|
||||||
file = @fixture_path.join("folder1/file1.txt")
|
file = @fixture_path.join("folder1/file1.txt")
|
||||||
File.exists?(file).should be_true
|
File.exists?(file).should be_true
|
||||||
start
|
start
|
||||||
@ -90,7 +90,7 @@ describe Guard::Linux do
|
|||||||
@results.should == ['spec/fixtures/folder1/file1.txt']
|
@results.should == ['spec/fixtures/folder1/file1.txt']
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should catch moved file" do
|
it "catches a moved file" do
|
||||||
file1 = @fixture_path.join("folder1/file1.txt")
|
file1 = @fixture_path.join("folder1/file1.txt")
|
||||||
file2 = @fixture_path.join("folder1/movedfile1.txt")
|
file2 = @fixture_path.join("folder1/movedfile1.txt")
|
||||||
File.exists?(file1).should be_true
|
File.exists?(file1).should be_true
|
||||||
@ -102,7 +102,7 @@ describe Guard::Linux do
|
|||||||
@results.should == ['spec/fixtures/folder1/file1.txt', 'spec/fixtures/folder1/movedfile1.txt']
|
@results.should == ['spec/fixtures/folder1/file1.txt', 'spec/fixtures/folder1/movedfile1.txt']
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not process change if stopped" do
|
it "doesn't process a change when it is stopped" do
|
||||||
file = @fixture_path.join("folder1/file1.txt")
|
file = @fixture_path.join("folder1/file1.txt")
|
||||||
File.exists?(file).should be_true
|
File.exists?(file).should be_true
|
||||||
start
|
start
|
||||||
|
@ -12,7 +12,7 @@ describe Guard::Polling do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "#on_change" do
|
describe "#on_change" do
|
||||||
it "catches new file" do
|
it "catches a new file" do
|
||||||
file = @fixture_path.join("newfile.rb")
|
file = @fixture_path.join("newfile.rb")
|
||||||
File.exists?(file).should be_false
|
File.exists?(file).should be_false
|
||||||
start
|
start
|
||||||
@ -22,7 +22,7 @@ describe Guard::Polling do
|
|||||||
@results.should == ['spec/fixtures/newfile.rb']
|
@results.should == ['spec/fixtures/newfile.rb']
|
||||||
end
|
end
|
||||||
|
|
||||||
it "catches file update" do
|
it "catches a single file update" do
|
||||||
file = @fixture_path.join("folder1/file1.txt")
|
file = @fixture_path.join("folder1/file1.txt")
|
||||||
File.exists?(file).should be_true
|
File.exists?(file).should be_true
|
||||||
start
|
start
|
||||||
@ -31,7 +31,7 @@ describe Guard::Polling do
|
|||||||
@results.should == ['spec/fixtures/folder1/file1.txt']
|
@results.should == ['spec/fixtures/folder1/file1.txt']
|
||||||
end
|
end
|
||||||
|
|
||||||
it "catches files update" do
|
it "catches multiple file updates" do
|
||||||
file1 = @fixture_path.join("folder1/file1.txt")
|
file1 = @fixture_path.join("folder1/file1.txt")
|
||||||
file2 = @fixture_path.join("folder1/folder2/file2.txt")
|
file2 = @fixture_path.join("folder1/folder2/file2.txt")
|
||||||
File.exists?(file1).should be_true
|
File.exists?(file1).should be_true
|
||||||
@ -47,6 +47,7 @@ describe Guard::Polling do
|
|||||||
private
|
private
|
||||||
|
|
||||||
def start
|
def start
|
||||||
|
sleep 1
|
||||||
Thread.new { @listener.start }
|
Thread.new { @listener.start }
|
||||||
sleep 1
|
sleep 1
|
||||||
end
|
end
|
||||||
@ -54,6 +55,7 @@ private
|
|||||||
def stop
|
def stop
|
||||||
sleep 1
|
sleep 1
|
||||||
@listener.stop
|
@listener.stop
|
||||||
|
sleep 1
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -30,7 +30,7 @@ describe Guard::Windows do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "catches new file" do
|
it "catches a new file" do
|
||||||
file = @fixture_path.join("newfile.rb")
|
file = @fixture_path.join("newfile.rb")
|
||||||
if File.exists?(file)
|
if File.exists?(file)
|
||||||
begin
|
begin
|
||||||
@ -49,7 +49,7 @@ describe Guard::Windows do
|
|||||||
@results.should == ['spec/fixtures/newfile.rb']
|
@results.should == ['spec/fixtures/newfile.rb']
|
||||||
end
|
end
|
||||||
|
|
||||||
it "catches file update" do
|
it "catches a single file update" do
|
||||||
file = @fixture_path.join("folder1/file1.txt")
|
file = @fixture_path.join("folder1/file1.txt")
|
||||||
File.exists?(file).should be_true
|
File.exists?(file).should be_true
|
||||||
start
|
start
|
||||||
@ -58,7 +58,7 @@ describe Guard::Windows do
|
|||||||
@results.should == ['spec/fixtures/folder1/file1.txt']
|
@results.should == ['spec/fixtures/folder1/file1.txt']
|
||||||
end
|
end
|
||||||
|
|
||||||
it "catches files update" do
|
it "catches multiple file updates" do
|
||||||
file1 = @fixture_path.join("folder1/file1.txt")
|
file1 = @fixture_path.join("folder1/file1.txt")
|
||||||
file2 = @fixture_path.join("folder1/folder2/file2.txt")
|
file2 = @fixture_path.join("folder1/folder2/file2.txt")
|
||||||
File.exists?(file1).should be_true
|
File.exists?(file1).should be_true
|
||||||
@ -75,14 +75,15 @@ describe Guard::Windows do
|
|||||||
private
|
private
|
||||||
|
|
||||||
def start
|
def start
|
||||||
sleep 0.6
|
sleep 1
|
||||||
Thread.new { @listener.start }
|
Thread.new { @listener.start }
|
||||||
sleep 0.6
|
sleep 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def stop
|
def stop
|
||||||
sleep 0.6
|
sleep 1
|
||||||
@listener.stop
|
@listener.stop
|
||||||
|
sleep 1
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -40,12 +40,12 @@ describe Guard::Notifier do
|
|||||||
|
|
||||||
describe ".turn_off" do
|
describe ".turn_off" do
|
||||||
if mac? && growl_installed?
|
if mac? && growl_installed?
|
||||||
it "does nothing" do
|
it "prevents the notifications" do
|
||||||
Growl.should_not_receive(:notify)
|
Growl.should_not_receive(:notify)
|
||||||
subject.notify 'great', :title => 'Guard'
|
subject.notify 'great', :title => 'Guard'
|
||||||
end
|
end
|
||||||
elsif linux? && libnotify_installed?
|
elsif linux? && libnotify_installed?
|
||||||
it "does nothing" do
|
it "prevents the notifications" do
|
||||||
Libnotify.should_not_receive(:show)
|
Libnotify.should_not_receive(:show)
|
||||||
subject.notify 'great', :title => 'Guard'
|
subject.notify 'great', :title => 'Guard'
|
||||||
end
|
end
|
||||||
|
@ -4,23 +4,27 @@ require 'guard/guard'
|
|||||||
describe Guard::Watcher do
|
describe Guard::Watcher do
|
||||||
|
|
||||||
describe "#initialize" do
|
describe "#initialize" do
|
||||||
describe "pattern parameter" do
|
it "requires a pattern parameter" do
|
||||||
it "is required" do
|
|
||||||
expect { Guard::Watcher.new }.to raise_error(ArgumentError)
|
expect { Guard::Watcher.new }.to raise_error(ArgumentError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can be a string" do
|
context "with a pattern parameter" do
|
||||||
|
context "that is a string" do
|
||||||
|
it "keeps the string pattern unmodified" do
|
||||||
Guard::Watcher.new('spec_helper.rb').pattern.should == 'spec_helper.rb'
|
Guard::Watcher.new('spec_helper.rb').pattern.should == 'spec_helper.rb'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can be a regexp" do
|
|
||||||
Guard::Watcher.new(/spec_helper\.rb/).pattern.should == /spec_helper\.rb/
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "can be a string looking like a regex (deprecated)" do
|
context "that is a regexp" do
|
||||||
|
it "keeps the regex pattern unmodified" do
|
||||||
|
Guard::Watcher.new(/spec_helper\.rb/).pattern.should == /spec_helper\.rb/
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "that is a string looking like a regex (deprecated)" do
|
||||||
before(:each) { Guard::UI.should_receive(:info).any_number_of_times }
|
before(:each) { Guard::UI.should_receive(:info).any_number_of_times }
|
||||||
|
|
||||||
it "and is automatically casted to a regex" do
|
it "converts the string automatically 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_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/
|
||||||
@ -30,12 +34,12 @@ describe Guard::Watcher do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "action" do
|
describe "#action" do
|
||||||
it "should set action to nil by default" do
|
it "sets the action to nothing by default" do
|
||||||
Guard::Watcher.new(/spec_helper\.rb/).action.should be_nil
|
Guard::Watcher.new(/spec_helper\.rb/).action.should be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should set action with a block" do
|
it "sets the action to the supplied block" do
|
||||||
action = lambda { |m| "spec/#{m[1]}_spec.rb" }
|
action = lambda { |m| "spec/#{m[1]}_spec.rb" }
|
||||||
Guard::Watcher.new(%r{^lib/(.*).rb}, action).action.should == action
|
Guard::Watcher.new(%r{^lib/(.*).rb}, action).action.should == action
|
||||||
end
|
end
|
||||||
@ -44,25 +48,25 @@ describe Guard::Watcher do
|
|||||||
describe ".match_files" do
|
describe ".match_files" do
|
||||||
before(:all) { @guard = Guard::Guard.new }
|
before(:all) { @guard = Guard::Guard.new }
|
||||||
|
|
||||||
describe "a watcher's with no action" do
|
context "with a watcher without action" do
|
||||||
context "regex pattern" do
|
context "that is a regex pattern" do
|
||||||
before(:all) { @guard.watchers = [Guard::Watcher.new(/.*_spec\.rb/)] }
|
before(:all) { @guard.watchers = [Guard::Watcher.new(/.*_spec\.rb/)] }
|
||||||
|
|
||||||
it "should return paths as they came" do
|
it "returns the paths that matches the regex" do
|
||||||
Guard::Watcher.match_files(@guard, ['guard_rocks_spec.rb']).should == ['guard_rocks_spec.rb']
|
Guard::Watcher.match_files(@guard, ['guard_rocks_spec.rb', 'guard_rocks.rb']).should == ['guard_rocks_spec.rb']
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "string pattern" do
|
context "that is a string pattern" do
|
||||||
before(:all) { @guard.watchers = [Guard::Watcher.new('guard_rocks_spec.rb')] }
|
before(:all) { @guard.watchers = [Guard::Watcher.new('guard_rocks_spec.rb')] }
|
||||||
|
|
||||||
it "should return paths as they came" do
|
it "returns the path that matches the string" do
|
||||||
Guard::Watcher.match_files(@guard, ['guard_rocks_spec.rb']).should == ['guard_rocks_spec.rb']
|
Guard::Watcher.match_files(@guard, ['guard_rocks_spec.rb', 'guard_rocks.rb']).should == ['guard_rocks_spec.rb']
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "a watcher's action with an arity equal to 0" do
|
context "with a watcher action without parameter" do
|
||||||
before(:all) do
|
before(:all) do
|
||||||
@guard.watchers = [
|
@guard.watchers = [
|
||||||
Guard::Watcher.new('spec_helper.rb', lambda { 'spec' }),
|
Guard::Watcher.new('spec_helper.rb', lambda { 'spec' }),
|
||||||
@ -74,27 +78,32 @@ describe Guard::Watcher do
|
|||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return paths specified in the watcher's action" do
|
it "returns a single file specified within the action" do
|
||||||
Guard::Watcher.match_files(@guard, ['spec_helper.rb']).should == ['spec']
|
Guard::Watcher.match_files(@guard, ['spec_helper.rb']).should == ['spec']
|
||||||
end
|
end
|
||||||
it "should return nothing if action.call doesn't respond_to :empty?" do
|
|
||||||
Guard::Watcher.match_files(@guard, ['addition.rb']).should == []
|
it "returns multiple files specified within the action" do
|
||||||
end
|
|
||||||
it "should return action.call.to_a if result respond_to :empty?" do
|
|
||||||
Guard::Watcher.match_files(@guard, ['hash.rb']).should == ['foo', 'bar']
|
Guard::Watcher.match_files(@guard, ['hash.rb']).should == ['foo', 'bar']
|
||||||
end
|
end
|
||||||
it "should return files including files from array if paths are an array" do
|
|
||||||
|
it "returns multiple files by combining the results of different actions" do
|
||||||
Guard::Watcher.match_files(@guard, ['spec_helper.rb', 'array.rb']).should == ['spec', 'foo', 'bar']
|
Guard::Watcher.match_files(@guard, ['spec_helper.rb', 'array.rb']).should == ['spec', 'foo', 'bar']
|
||||||
end
|
end
|
||||||
it "should return nothing if action.call return ''" do
|
|
||||||
|
it "returns nothing if the action returns something other than a string or an array of strings" do
|
||||||
|
Guard::Watcher.match_files(@guard, ['addition.rb']).should == []
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns nothing if the action response is empty" do
|
||||||
Guard::Watcher.match_files(@guard, ['blank.rb']).should == []
|
Guard::Watcher.match_files(@guard, ['blank.rb']).should == []
|
||||||
end
|
end
|
||||||
it "should return nothing if action.call return nil" do
|
|
||||||
|
it "returns nothing if the action returns nothing" do
|
||||||
Guard::Watcher.match_files(@guard, ['uptime.rb']).should == []
|
Guard::Watcher.match_files(@guard, ['uptime.rb']).should == []
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "a watcher's action with an arity equal to 1" do
|
context "with a watcher action that takes a parameter" do
|
||||||
before(:all) do
|
before(:all) do
|
||||||
@guard.watchers = [
|
@guard.watchers = [
|
||||||
Guard::Watcher.new(%r{lib/(.*)\.rb}, lambda { |m| "spec/#{m[1]}_spec.rb" }),
|
Guard::Watcher.new(%r{lib/(.*)\.rb}, lambda { |m| "spec/#{m[1]}_spec.rb" }),
|
||||||
@ -106,30 +115,35 @@ describe Guard::Watcher do
|
|||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return paths after watcher's action has been called against them" do
|
it "returns a substituted single file specified within the action" do
|
||||||
Guard::Watcher.match_files(@guard, ['lib/my_wonderful_lib.rb']).should == ['spec/my_wonderful_lib_spec.rb']
|
Guard::Watcher.match_files(@guard, ['lib/my_wonderful_lib.rb']).should == ['spec/my_wonderful_lib_spec.rb']
|
||||||
end
|
end
|
||||||
it "should return nothing if action.call doesn't respond_to :empty?" do
|
|
||||||
Guard::Watcher.match_files(@guard, ['addition.rb']).should == []
|
it "returns multiple files specified within the action" do
|
||||||
end
|
|
||||||
it "should return action.call.to_a if result respond_to :empty?" do
|
|
||||||
Guard::Watcher.match_files(@guard, ['hash.rb']).should == ['foo', 'bar']
|
Guard::Watcher.match_files(@guard, ['hash.rb']).should == ['foo', 'bar']
|
||||||
end
|
end
|
||||||
it "should return files including files from array if paths are an array" do
|
|
||||||
|
it "returns multiple files by combining the results of different actions" do
|
||||||
Guard::Watcher.match_files(@guard, ['lib/my_wonderful_lib.rb', 'array.rb']).should == ['spec/my_wonderful_lib_spec.rb', 'foo', 'bar']
|
Guard::Watcher.match_files(@guard, ['lib/my_wonderful_lib.rb', 'array.rb']).should == ['spec/my_wonderful_lib_spec.rb', 'foo', 'bar']
|
||||||
end
|
end
|
||||||
it "should return nothing if action.call return ''" do
|
|
||||||
|
it "returns nothing if the action returns something other than a string or an array of strings" do
|
||||||
|
Guard::Watcher.match_files(@guard, ['addition.rb']).should == []
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns nothing if the action response is empty" do
|
||||||
Guard::Watcher.match_files(@guard, ['blank.rb']).should == []
|
Guard::Watcher.match_files(@guard, ['blank.rb']).should == []
|
||||||
end
|
end
|
||||||
it "should return nothing if action.call return nil" do
|
|
||||||
|
it "returns nothing if the action returns nothing" do
|
||||||
Guard::Watcher.match_files(@guard, ['uptime.rb']).should == []
|
Guard::Watcher.match_files(@guard, ['uptime.rb']).should == []
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "an exception is raised" do
|
context "with an exception that is raised" do
|
||||||
before(:all) { @guard.watchers = [Guard::Watcher.new('evil.rb', lambda { raise "EVIL" })] }
|
before(:all) { @guard.watchers = [Guard::Watcher.new('evil.rb', lambda { raise "EVIL" })] }
|
||||||
|
|
||||||
it "should display an error" do
|
it "displays the error" do
|
||||||
Guard::UI.should_receive(:error).with("Problem with watch action!")
|
Guard::UI.should_receive(:error).with("Problem with watch action!")
|
||||||
Guard::Watcher.match_files(@guard, ['evil.rb'])
|
Guard::Watcher.match_files(@guard, ['evil.rb'])
|
||||||
end
|
end
|
||||||
@ -143,38 +157,53 @@ describe Guard::Watcher do
|
|||||||
@guards = [@guard1, @guard2]
|
@guards = [@guard1, @guard2]
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "with at least on watcher that match a file given" do
|
context "with a watcher that matches a file" do
|
||||||
specify { Guard::Watcher.match_files?(@guards, ['lib/my_wonderful_lib.rb', 'guard_rocks_spec.rb']).should be_true }
|
specify { Guard::Watcher.match_files?(@guards, ['lib/my_wonderful_lib.rb', 'guard_rocks_spec.rb']).should be_true }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "with no watcher matching a file given" do
|
context "with no watcher that matches a file" do
|
||||||
specify { Guard::Watcher.match_files?(@guards, ['lib/my_wonderful_lib.rb']).should be_false }
|
specify { Guard::Watcher.match_files?(@guards, ['lib/my_wonderful_lib.rb']).should be_false }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#match_file?" do
|
describe "#match_file?" do
|
||||||
describe "string pattern" do
|
context "with a string pattern" do
|
||||||
describe "normal string" do
|
context "that is a normal string" do
|
||||||
subject { Guard::Watcher.new('guard_rocks_spec.rb') }
|
subject { Guard::Watcher.new('guard_rocks_spec.rb') }
|
||||||
|
|
||||||
specify { subject.match_file?('lib/my_wonderful_lib.rb').should be_false }
|
context "with a watcher that matches a file" do
|
||||||
specify { subject.match_file?('guard_rocks_spec.rb').should be_true }
|
specify { subject.match_file?('guard_rocks_spec.rb').should be_true }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "string representing a regexp converted (while deprecation is active)" do
|
context "with no watcher that matches a file" do
|
||||||
|
specify { subject.match_file?('lib/my_wonderful_lib.rb').should be_false }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "that is a string representing a regexp (deprecated)" do
|
||||||
subject { Guard::Watcher.new('^guard_rocks_spec\.rb$') }
|
subject { Guard::Watcher.new('^guard_rocks_spec\.rb$') }
|
||||||
|
|
||||||
specify { subject.match_file?('lib/my_wonderful_lib.rb').should be_false }
|
context "with a watcher that matches a file" do
|
||||||
specify { subject.match_file?('guard_rocks_spec.rb').should be_true }
|
specify { subject.match_file?('guard_rocks_spec.rb').should be_true }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with no watcher that matches a file" do
|
||||||
|
specify { subject.match_file?('lib/my_wonderful_lib.rb').should be_false }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "regexp pattern" do
|
context "that is a regexp pattern" do
|
||||||
subject { Guard::Watcher.new(/.*_spec\.rb/) }
|
subject { Guard::Watcher.new(/.*_spec\.rb/) }
|
||||||
|
|
||||||
specify { subject.match_file?('lib/my_wonderful_lib.rb').should be_false }
|
context "with a watcher that matches a file" do
|
||||||
specify { subject.match_file?('guard_rocks_spec.rb').should be_true }
|
specify { subject.match_file?('guard_rocks_spec.rb').should be_true }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with no watcher that matches a file" do
|
||||||
|
specify { subject.match_file?('lib/my_wonderful_lib.rb').should be_false }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
@ -2,39 +2,38 @@ require 'spec_helper'
|
|||||||
|
|
||||||
describe Guard do
|
describe Guard do
|
||||||
|
|
||||||
describe "Class Methods" do
|
|
||||||
describe ".setup" do
|
describe ".setup" do
|
||||||
subject { ::Guard.setup }
|
subject { ::Guard.setup }
|
||||||
|
|
||||||
it "should retrieve itself for chaining" do
|
it "returns itself for chaining" do
|
||||||
subject.should be_kind_of(Module)
|
subject.should be ::Guard
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should init guards array" do
|
it "initializes the Guards" do
|
||||||
::Guard.guards.should be_kind_of(Array)
|
::Guard.guards.should be_kind_of(Array)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should init options" do
|
it "initializes the options" do
|
||||||
opts = { :my_opts => true }
|
opts = { :my_opts => true }
|
||||||
::Guard.setup(opts).options.should include(:my_opts)
|
::Guard.setup(opts).options.should include(:my_opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should init listener" do
|
it "initializes the listener" do
|
||||||
::Guard.listener.should be_kind_of(Guard::Listener)
|
::Guard.listener.should be_kind_of(Guard::Listener)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should turn on by default" do
|
it "turns on the notifier by default" do
|
||||||
ENV["GUARD_NOTIFY"] = nil
|
ENV["GUARD_NOTIFY"] = nil
|
||||||
::Guard::Notifier.should_receive(:turn_on)
|
::Guard::Notifier.should_receive(:turn_on)
|
||||||
::Guard.setup(:notify => true)
|
::Guard.setup(:notify => true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should turn off notifier if notify option is false" do
|
it "turns off the notifier if the notify option is false" do
|
||||||
::Guard::Notifier.should_receive(:turn_off)
|
::Guard::Notifier.should_receive(:turn_off)
|
||||||
::Guard.setup(:notify => false)
|
::Guard.setup(:notify => false)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should turn off notifier if env[GUARD_NOTIFY] is false" do
|
it "turns off the notifier if environment variable GUARD_NOTIFY is false" do
|
||||||
ENV["GUARD_NOTIFY"] = 'false'
|
ENV["GUARD_NOTIFY"] = 'false'
|
||||||
::Guard::Notifier.should_receive(:turn_off)
|
::Guard::Notifier.should_receive(:turn_off)
|
||||||
::Guard.setup(:notify => true)
|
::Guard.setup(:notify => true)
|
||||||
@ -42,15 +41,15 @@ describe Guard do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe ".get_guard_class" do
|
describe ".get_guard_class" do
|
||||||
it "should report an error if the class is not found" do
|
it "reports an error if the class is not found" do
|
||||||
::Guard::UI.should_receive(:error)
|
::Guard::UI.should_receive(:error)
|
||||||
Guard.get_guard_class('notAGuardClass')
|
Guard.get_guard_class('notAGuardClass')
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'loaded some nested classes' do
|
context 'with a nested Guard class' do
|
||||||
it "should find and return loaded class" do
|
it "returns the Guard class" do
|
||||||
Guard.should_receive(:try_to_load_gem) { |className|
|
Guard.should_receive(:try_to_load_gem) { |classname|
|
||||||
className.should == 'classname'
|
classname.should == 'classname'
|
||||||
class Guard::Classname
|
class Guard::Classname
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
@ -58,8 +57,8 @@ describe Guard do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'loaded some inline classes ' do
|
context 'with an inline Guard class' do
|
||||||
it 'should return inline class' do
|
it 'returns the Guard class' do
|
||||||
module Guard
|
module Guard
|
||||||
class Inline < Guard
|
class Inline < Guard
|
||||||
end
|
end
|
||||||
@ -71,58 +70,7 @@ describe Guard do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe ".locate_guard" do
|
describe ".locate_guard" do
|
||||||
it "returns guard-rspec gem path" do
|
it "returns the path of a Guard gem" do
|
||||||
guard_path = Guard.locate_guard('rspec')
|
|
||||||
guard_path.should match(/^.*\/guard-rspec-.*$/)
|
|
||||||
guard_path.should == guard_path.chomp
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe ".supervised_task" do
|
|
||||||
subject { ::Guard.setup }
|
|
||||||
before(:each) do
|
|
||||||
@g = mock(Guard::Guard).as_null_object
|
|
||||||
subject.guards.push(@g)
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "tasks that succeed" do
|
|
||||||
before(:each) do
|
|
||||||
@g.stub!(:regular) { true }
|
|
||||||
@g.stub!(:regular_with_arg).with("given_path") { "i'm a success" }
|
|
||||||
end
|
|
||||||
|
|
||||||
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 "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 "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
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "tasks that raise an exception" do
|
|
||||||
before(:each) { @g.stub!(:failing) { raise "I break your system" } }
|
|
||||||
|
|
||||||
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 "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'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe ".locate_guard" do
|
|
||||||
it "returns the path of the guard gem" do
|
|
||||||
if Gem::Version.create(Gem::VERSION) >= Gem::Version.create('1.8.0')
|
if Gem::Version.create(Gem::VERSION) >= Gem::Version.create('1.8.0')
|
||||||
gem_location = Gem::Specification.find_by_name("guard-rspec").full_gem_path
|
gem_location = Gem::Specification.find_by_name("guard-rspec").full_gem_path
|
||||||
else
|
else
|
||||||
@ -132,6 +80,59 @@ describe Guard do
|
|||||||
Guard.locate_guard('rspec').should == gem_location
|
Guard.locate_guard('rspec').should == gem_location
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe ".supervised_task" do
|
||||||
|
subject { ::Guard.setup }
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
@g = mock(Guard::Guard).as_null_object
|
||||||
|
subject.guards.push(@g)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a task that succeed" do
|
||||||
|
context 'without any arguments' do
|
||||||
|
before(:each) do
|
||||||
|
@g.stub!(:regular) { true }
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't fire the Guard" do
|
||||||
|
lambda { subject.supervised_task(@g, :regular) }.should_not change(subject.guards, :size)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the result of the task" do
|
||||||
|
::Guard.supervised_task(@g, :regular).should be_true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with arguments' do
|
||||||
|
before(:each) do
|
||||||
|
@g.stub!(:regular_with_arg).with("given_path") { "I'm a success" }
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't fire the Guard" do
|
||||||
|
lambda { subject.supervised_task(@g, :regular_with_arg, "given_path") }.should_not change(subject.guards, :size)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the result of the task" do
|
||||||
|
::Guard.supervised_task(@g, :regular_with_arg, "given_path").should == "I'm a success"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a task that raises an exception" do
|
||||||
|
before(:each) { @g.stub!(:failing) { raise "I break your system" } }
|
||||||
|
|
||||||
|
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 "returns the exception" do
|
||||||
|
failing_result = ::Guard.supervised_task(@g, :failing)
|
||||||
|
failing_result.should be_kind_of(Exception)
|
||||||
|
failing_result.message.should == 'I break your system'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user