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
|
||||
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!")
|
||||
|
||||
Guard::UI.should_receive(:error).with(/Invalid Guardfile, original error is:\n/)
|
||||
@ -22,22 +22,22 @@ describe Guard::Dsl do
|
||||
end
|
||||
|
||||
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'")
|
||||
subject.guardfile_include?('test').should be_true
|
||||
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"')
|
||||
subject.guardfile_include?('test').should be_true
|
||||
end
|
||||
|
||||
it "detects a guard specified by a symbol" do
|
||||
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
|
||||
it "detects a Guard wrapped in parentheses" do
|
||||
mock_guardfile_content("guard(:test)")
|
||||
subject.guardfile_include?('test').should be_true
|
||||
end
|
||||
@ -59,13 +59,13 @@ describe Guard::Dsl do
|
||||
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_not_receive(:add_guard).with('another', anything, {})
|
||||
subject.evaluate_guardfile(:group => ['x'])
|
||||
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('another', anything, {})
|
||||
subject.evaluate_guardfile(:group => ['x', 'y'])
|
||||
@ -73,21 +73,21 @@ describe Guard::Dsl do
|
||||
end
|
||||
|
||||
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'")
|
||||
|
||||
::Guard.should_receive(:add_guard).with('test', [], {})
|
||||
subject.evaluate_guardfile
|
||||
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")
|
||||
|
||||
::Guard.should_receive(:add_guard).with(:test, [], {})
|
||||
subject.evaluate_guardfile
|
||||
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'")
|
||||
|
||||
::Guard.should_receive(:add_guard).with('test', anything, { :opt_a => 1, :opt_b => 'fancy' })
|
||||
@ -96,7 +96,7 @@ describe Guard::Dsl do
|
||||
end
|
||||
|
||||
describe "#watch" do
|
||||
it "should receive watchers when specified" do
|
||||
it "should receive the watchers when specified" do
|
||||
mock_guardfile_content("
|
||||
guard 'test' do
|
||||
watch('a') { 'b' }
|
||||
|
@ -2,6 +2,7 @@ require 'spec_helper'
|
||||
|
||||
describe Guard::Interactor do
|
||||
subject { Guard::Interactor }
|
||||
|
||||
let(:guard) { mock "guard" }
|
||||
|
||||
before :each do
|
||||
@ -10,18 +11,24 @@ describe Guard::Interactor do
|
||||
Guard.stub!(:listener).and_return(mock(:start => nil, :stop => nil))
|
||||
end
|
||||
|
||||
it ".run_all should send :run_all to all guards" do
|
||||
guard.should_receive(:run_all)
|
||||
subject.run_all
|
||||
describe ".run_all" do
|
||||
it "sends :run_all to all guards" do
|
||||
guard.should_receive(:run_all)
|
||||
subject.run_all
|
||||
end
|
||||
end
|
||||
|
||||
it ".stop should send :stop to all guards" do
|
||||
guard.should_receive(:stop)
|
||||
lambda { subject.stop }.should raise_error(SystemExit)
|
||||
describe ".stop" do
|
||||
it "sends :stop to all guards" do
|
||||
guard.should_receive(:stop)
|
||||
lambda { subject.stop }.should raise_error(SystemExit)
|
||||
end
|
||||
end
|
||||
|
||||
it ".reload should send :reload to all guards" do
|
||||
guard.should_receive(:reload)
|
||||
subject.reload
|
||||
describe ".reload" do
|
||||
it "sends :reload to all guards" do
|
||||
guard.should_receive(:reload)
|
||||
subject.reload
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -3,27 +3,25 @@ require 'spec_helper'
|
||||
describe Guard::Listener do
|
||||
subject { Guard::Listener }
|
||||
|
||||
after(:all) { sleep 1 }
|
||||
|
||||
describe ".select_and_init" do
|
||||
before(:each) { @target_os = Config::CONFIG['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'
|
||||
Guard::Darwin.stub(:usable?).and_return(true)
|
||||
Guard::Darwin.should_receive(:new)
|
||||
subject.select_and_init
|
||||
end
|
||||
|
||||
it "uses windows listener on Windows" do
|
||||
it "uses the Windows listener on Windows" do
|
||||
Config::CONFIG['target_os'] = 'mingw'
|
||||
Guard::Windows.stub(:usable?).and_return(true)
|
||||
Guard::Windows.should_receive(:new)
|
||||
subject.select_and_init
|
||||
end
|
||||
|
||||
it "uses linux listener on Linux" do
|
||||
it "uses the Linux listener on Linux" do
|
||||
Config::CONFIG['target_os'] = 'linux'
|
||||
Guard::Linux.stub(:usable?).and_return(true)
|
||||
Guard::Linux.should_receive(:new)
|
||||
@ -34,7 +32,7 @@ describe Guard::Listener do
|
||||
describe "#update_last_event" do
|
||||
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
|
||||
subject.update_last_event
|
||||
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
|
||||
FileUtils.touch([file1, file2, file3])
|
||||
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])
|
||||
subject.modified_files([@fixture_path.join("folder1/")], {}).should == []
|
||||
sleep 1
|
||||
end
|
||||
end
|
||||
|
||||
@ -83,10 +82,11 @@ describe Guard::Listener do
|
||||
it "identifies the files for the second time" do
|
||||
FileUtils.touch([file1, file2, file3])
|
||||
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])
|
||||
File.open(file1, "w") { |f| f.write("changed content") }
|
||||
subject.modified_files([@fixture_path.join("folder1/")], {}).should =~ ["spec/fixtures/folder1/file1.txt"]
|
||||
sleep 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -24,7 +24,7 @@ describe Guard::Darwin do
|
||||
end
|
||||
end
|
||||
|
||||
it "catches new file" do
|
||||
it "catches a 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 "catches file update" do
|
||||
it "catches a single 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 "catches files update" do
|
||||
it "catches multiple file updates" do
|
||||
file1 = @fixture_path.join("folder1/file1.txt")
|
||||
file2 = @fixture_path.join("folder1/folder2/file2.txt")
|
||||
File.exists?(file1).should be_true
|
||||
@ -60,14 +60,15 @@ describe Guard::Darwin do
|
||||
private
|
||||
|
||||
def start
|
||||
sleep 0.6
|
||||
sleep 1
|
||||
Thread.new { @listener.start }
|
||||
sleep 0.6
|
||||
sleep 1
|
||||
end
|
||||
|
||||
def stop
|
||||
sleep 0.6
|
||||
sleep 1
|
||||
@listener.stop
|
||||
sleep 1
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -21,12 +21,12 @@ describe Guard::Linux do
|
||||
@listener = Guard::Linux.new
|
||||
end
|
||||
|
||||
it "should call watch_change if first start" do
|
||||
it "calls watch_change on the first start" do
|
||||
@listener.should_receive(:watch_change)
|
||||
start
|
||||
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)
|
||||
start
|
||||
stop
|
||||
@ -49,7 +49,7 @@ describe Guard::Linux do
|
||||
end
|
||||
end
|
||||
|
||||
it "should catch new file" do
|
||||
it "catches a new file" do
|
||||
file = @fixture_path.join("newfile.rb")
|
||||
File.exists?(file).should be_false
|
||||
start
|
||||
@ -59,7 +59,7 @@ describe Guard::Linux do
|
||||
@results.should == ['spec/fixtures/newfile.rb']
|
||||
end
|
||||
|
||||
it "should catch file update" do
|
||||
it "catches a single file update" do
|
||||
file = @fixture_path.join("folder1/file1.txt")
|
||||
File.exists?(file).should be_true
|
||||
start
|
||||
@ -68,7 +68,7 @@ describe Guard::Linux do
|
||||
@results.should == ['spec/fixtures/folder1/file1.txt']
|
||||
end
|
||||
|
||||
it "should catch files update" do
|
||||
it "catches multiple file updates" do
|
||||
file1 = @fixture_path.join("folder1/file1.txt")
|
||||
file2 = @fixture_path.join("folder1/folder2/file2.txt")
|
||||
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']
|
||||
end
|
||||
|
||||
it "should catch deleted file" do
|
||||
it "catches a deleted file" do
|
||||
file = @fixture_path.join("folder1/file1.txt")
|
||||
File.exists?(file).should be_true
|
||||
start
|
||||
@ -90,7 +90,7 @@ describe Guard::Linux do
|
||||
@results.should == ['spec/fixtures/folder1/file1.txt']
|
||||
end
|
||||
|
||||
it "should catch moved file" do
|
||||
it "catches a moved file" do
|
||||
file1 = @fixture_path.join("folder1/file1.txt")
|
||||
file2 = @fixture_path.join("folder1/movedfile1.txt")
|
||||
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']
|
||||
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.exists?(file).should be_true
|
||||
start
|
||||
|
@ -12,7 +12,7 @@ describe Guard::Polling do
|
||||
end
|
||||
|
||||
describe "#on_change" do
|
||||
it "catches new file" do
|
||||
it "catches a new file" do
|
||||
file = @fixture_path.join("newfile.rb")
|
||||
File.exists?(file).should be_false
|
||||
start
|
||||
@ -22,7 +22,7 @@ describe Guard::Polling do
|
||||
@results.should == ['spec/fixtures/newfile.rb']
|
||||
end
|
||||
|
||||
it "catches file update" do
|
||||
it "catches a single file update" do
|
||||
file = @fixture_path.join("folder1/file1.txt")
|
||||
File.exists?(file).should be_true
|
||||
start
|
||||
@ -31,7 +31,7 @@ describe Guard::Polling do
|
||||
@results.should == ['spec/fixtures/folder1/file1.txt']
|
||||
end
|
||||
|
||||
it "catches files update" do
|
||||
it "catches multiple file updates" do
|
||||
file1 = @fixture_path.join("folder1/file1.txt")
|
||||
file2 = @fixture_path.join("folder1/folder2/file2.txt")
|
||||
File.exists?(file1).should be_true
|
||||
@ -47,6 +47,7 @@ describe Guard::Polling do
|
||||
private
|
||||
|
||||
def start
|
||||
sleep 1
|
||||
Thread.new { @listener.start }
|
||||
sleep 1
|
||||
end
|
||||
@ -54,6 +55,7 @@ private
|
||||
def stop
|
||||
sleep 1
|
||||
@listener.stop
|
||||
sleep 1
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -30,7 +30,7 @@ describe Guard::Windows do
|
||||
end
|
||||
end
|
||||
|
||||
it "catches new file" do
|
||||
it "catches a new file" do
|
||||
file = @fixture_path.join("newfile.rb")
|
||||
if File.exists?(file)
|
||||
begin
|
||||
@ -49,7 +49,7 @@ describe Guard::Windows do
|
||||
@results.should == ['spec/fixtures/newfile.rb']
|
||||
end
|
||||
|
||||
it "catches file update" do
|
||||
it "catches a single file update" do
|
||||
file = @fixture_path.join("folder1/file1.txt")
|
||||
File.exists?(file).should be_true
|
||||
start
|
||||
@ -58,7 +58,7 @@ describe Guard::Windows do
|
||||
@results.should == ['spec/fixtures/folder1/file1.txt']
|
||||
end
|
||||
|
||||
it "catches files update" do
|
||||
it "catches multiple file updates" do
|
||||
file1 = @fixture_path.join("folder1/file1.txt")
|
||||
file2 = @fixture_path.join("folder1/folder2/file2.txt")
|
||||
File.exists?(file1).should be_true
|
||||
@ -75,14 +75,15 @@ describe Guard::Windows do
|
||||
private
|
||||
|
||||
def start
|
||||
sleep 0.6
|
||||
sleep 1
|
||||
Thread.new { @listener.start }
|
||||
sleep 0.6
|
||||
sleep 1
|
||||
end
|
||||
|
||||
def stop
|
||||
sleep 0.6
|
||||
sleep 1
|
||||
@listener.stop
|
||||
sleep 1
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -40,12 +40,12 @@ describe Guard::Notifier do
|
||||
|
||||
describe ".turn_off" do
|
||||
if mac? && growl_installed?
|
||||
it "does nothing" do
|
||||
it "prevents the notifications" do
|
||||
Growl.should_not_receive(:notify)
|
||||
subject.notify 'great', :title => 'Guard'
|
||||
end
|
||||
elsif linux? && libnotify_installed?
|
||||
it "does nothing" do
|
||||
it "prevents the notifications" do
|
||||
Libnotify.should_not_receive(:show)
|
||||
subject.notify 'great', :title => 'Guard'
|
||||
end
|
||||
|
@ -4,23 +4,27 @@ require 'guard/guard'
|
||||
describe Guard::Watcher do
|
||||
|
||||
describe "#initialize" do
|
||||
describe "pattern parameter" do
|
||||
it "is required" do
|
||||
expect { Guard::Watcher.new }.to raise_error(ArgumentError)
|
||||
it "requires a pattern parameter" do
|
||||
expect { Guard::Watcher.new }.to raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
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'
|
||||
end
|
||||
end
|
||||
|
||||
it "can be a string" do
|
||||
Guard::Watcher.new('spec_helper.rb').pattern.should == 'spec_helper.rb'
|
||||
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
|
||||
|
||||
it "can be a regexp" do
|
||||
Guard::Watcher.new(/spec_helper\.rb/).pattern.should == /spec_helper\.rb/
|
||||
end
|
||||
|
||||
describe "can be a string looking like a regex (deprecated)" do
|
||||
context "that is a string looking like a regex (deprecated)" do
|
||||
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/
|
||||
@ -30,12 +34,12 @@ describe Guard::Watcher do
|
||||
end
|
||||
end
|
||||
|
||||
describe "action" do
|
||||
it "should set action to nil by default" do
|
||||
describe "#action" do
|
||||
it "sets the action to nothing by default" do
|
||||
Guard::Watcher.new(/spec_helper\.rb/).action.should be_nil
|
||||
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" }
|
||||
Guard::Watcher.new(%r{^lib/(.*).rb}, action).action.should == action
|
||||
end
|
||||
@ -44,25 +48,25 @@ describe Guard::Watcher do
|
||||
describe ".match_files" do
|
||||
before(:all) { @guard = Guard::Guard.new }
|
||||
|
||||
describe "a watcher's with no action" do
|
||||
context "regex pattern" do
|
||||
context "with a watcher without action" do
|
||||
context "that is a regex pattern" do
|
||||
before(:all) { @guard.watchers = [Guard::Watcher.new(/.*_spec\.rb/)] }
|
||||
|
||||
it "should return paths as they came" do
|
||||
Guard::Watcher.match_files(@guard, ['guard_rocks_spec.rb']).should == ['guard_rocks_spec.rb']
|
||||
it "returns the paths that matches the regex" do
|
||||
Guard::Watcher.match_files(@guard, ['guard_rocks_spec.rb', 'guard_rocks.rb']).should == ['guard_rocks_spec.rb']
|
||||
end
|
||||
end
|
||||
|
||||
context "string pattern" do
|
||||
context "that is a string pattern" do
|
||||
before(:all) { @guard.watchers = [Guard::Watcher.new('guard_rocks_spec.rb')] }
|
||||
|
||||
it "should return paths as they came" do
|
||||
Guard::Watcher.match_files(@guard, ['guard_rocks_spec.rb']).should == ['guard_rocks_spec.rb']
|
||||
it "returns the path that matches the string" do
|
||||
Guard::Watcher.match_files(@guard, ['guard_rocks_spec.rb', 'guard_rocks.rb']).should == ['guard_rocks_spec.rb']
|
||||
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
|
||||
@guard.watchers = [
|
||||
Guard::Watcher.new('spec_helper.rb', lambda { 'spec' }),
|
||||
@ -74,27 +78,32 @@ describe Guard::Watcher do
|
||||
]
|
||||
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']
|
||||
end
|
||||
it "should return nothing if action.call doesn't respond_to :empty?" do
|
||||
Guard::Watcher.match_files(@guard, ['addition.rb']).should == []
|
||||
end
|
||||
it "should return action.call.to_a if result respond_to :empty?" do
|
||||
|
||||
it "returns multiple files specified within the action" do
|
||||
Guard::Watcher.match_files(@guard, ['hash.rb']).should == ['foo', 'bar']
|
||||
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']
|
||||
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 == []
|
||||
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 == []
|
||||
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
|
||||
@guard.watchers = [
|
||||
Guard::Watcher.new(%r{lib/(.*)\.rb}, lambda { |m| "spec/#{m[1]}_spec.rb" }),
|
||||
@ -106,30 +115,35 @@ describe Guard::Watcher do
|
||||
]
|
||||
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']
|
||||
end
|
||||
it "should return nothing if action.call doesn't respond_to :empty?" do
|
||||
Guard::Watcher.match_files(@guard, ['addition.rb']).should == []
|
||||
end
|
||||
it "should return action.call.to_a if result respond_to :empty?" do
|
||||
|
||||
it "returns multiple files specified within the action" do
|
||||
Guard::Watcher.match_files(@guard, ['hash.rb']).should == ['foo', 'bar']
|
||||
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']
|
||||
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 == []
|
||||
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 == []
|
||||
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" })] }
|
||||
|
||||
it "should display an error" do
|
||||
it "displays the error" do
|
||||
Guard::UI.should_receive(:error).with("Problem with watch action!")
|
||||
Guard::Watcher.match_files(@guard, ['evil.rb'])
|
||||
end
|
||||
@ -143,38 +157,53 @@ describe Guard::Watcher do
|
||||
@guards = [@guard1, @guard2]
|
||||
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 }
|
||||
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 }
|
||||
end
|
||||
end
|
||||
|
||||
describe "#match_file?" do
|
||||
describe "string pattern" do
|
||||
describe "normal string" do
|
||||
context "with a string pattern" do
|
||||
context "that is a normal string" do
|
||||
subject { Guard::Watcher.new('guard_rocks_spec.rb') }
|
||||
|
||||
specify { subject.match_file?('lib/my_wonderful_lib.rb').should be_false }
|
||||
specify { subject.match_file?('guard_rocks_spec.rb').should be_true }
|
||||
context "with a watcher that matches a file" do
|
||||
specify { subject.match_file?('guard_rocks_spec.rb').should be_true }
|
||||
end
|
||||
|
||||
context "with no watcher that matches a file" do
|
||||
specify { subject.match_file?('lib/my_wonderful_lib.rb').should be_false }
|
||||
end
|
||||
end
|
||||
|
||||
describe "string representing a regexp converted (while deprecation is active)" do
|
||||
context "that is a string representing a regexp (deprecated)" do
|
||||
subject { Guard::Watcher.new('^guard_rocks_spec\.rb$') }
|
||||
|
||||
specify { subject.match_file?('lib/my_wonderful_lib.rb').should be_false }
|
||||
specify { subject.match_file?('guard_rocks_spec.rb').should be_true }
|
||||
context "with a watcher that matches a file" do
|
||||
specify { subject.match_file?('guard_rocks_spec.rb').should be_true }
|
||||
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
|
||||
|
||||
describe "regexp pattern" do
|
||||
context "that is a regexp pattern" do
|
||||
subject { Guard::Watcher.new(/.*_spec\.rb/) }
|
||||
|
||||
specify { subject.match_file?('lib/my_wonderful_lib.rb').should be_false }
|
||||
specify { subject.match_file?('guard_rocks_spec.rb').should be_true }
|
||||
context "with a watcher that matches a file" do
|
||||
specify { subject.match_file?('guard_rocks_spec.rb').should be_true }
|
||||
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
|
||||
|
@ -2,134 +2,135 @@ require 'spec_helper'
|
||||
|
||||
describe Guard do
|
||||
|
||||
describe "Class Methods" do
|
||||
describe ".setup" do
|
||||
subject { ::Guard.setup }
|
||||
describe ".setup" do
|
||||
subject { ::Guard.setup }
|
||||
|
||||
it "should retrieve itself for chaining" do
|
||||
subject.should be_kind_of(Module)
|
||||
end
|
||||
|
||||
it "should init guards array" do
|
||||
::Guard.guards.should be_kind_of(Array)
|
||||
end
|
||||
|
||||
it "should init options" do
|
||||
opts = { :my_opts => true }
|
||||
::Guard.setup(opts).options.should include(:my_opts)
|
||||
end
|
||||
|
||||
it "should init listener" do
|
||||
::Guard.listener.should be_kind_of(Guard::Listener)
|
||||
end
|
||||
|
||||
it "should turn on by default" do
|
||||
ENV["GUARD_NOTIFY"] = nil
|
||||
::Guard::Notifier.should_receive(:turn_on)
|
||||
::Guard.setup(:notify => true)
|
||||
end
|
||||
|
||||
it "should turn off notifier if notify option is false" do
|
||||
::Guard::Notifier.should_receive(:turn_off)
|
||||
::Guard.setup(:notify => false)
|
||||
end
|
||||
|
||||
it "should turn off notifier if env[GUARD_NOTIFY] is false" do
|
||||
ENV["GUARD_NOTIFY"] = 'false'
|
||||
::Guard::Notifier.should_receive(:turn_off)
|
||||
::Guard.setup(:notify => true)
|
||||
end
|
||||
it "returns itself for chaining" do
|
||||
subject.should be ::Guard
|
||||
end
|
||||
|
||||
describe ".get_guard_class" do
|
||||
it "should report an error if the class is not found" do
|
||||
::Guard::UI.should_receive(:error)
|
||||
Guard.get_guard_class('notAGuardClass')
|
||||
end
|
||||
it "initializes the Guards" do
|
||||
::Guard.guards.should be_kind_of(Array)
|
||||
end
|
||||
|
||||
context 'loaded some nested classes' do
|
||||
it "should find and return loaded class" do
|
||||
Guard.should_receive(:try_to_load_gem) { |className|
|
||||
className.should == 'classname'
|
||||
class Guard::Classname
|
||||
end
|
||||
}
|
||||
Guard.get_guard_class('classname').should == Guard::Classname
|
||||
end
|
||||
end
|
||||
it "initializes the options" do
|
||||
opts = { :my_opts => true }
|
||||
::Guard.setup(opts).options.should include(:my_opts)
|
||||
end
|
||||
|
||||
context 'loaded some inline classes ' do
|
||||
it 'should return inline class' do
|
||||
module Guard
|
||||
class Inline < Guard
|
||||
end
|
||||
it "initializes the listener" do
|
||||
::Guard.listener.should be_kind_of(Guard::Listener)
|
||||
end
|
||||
|
||||
it "turns on the notifier by default" do
|
||||
ENV["GUARD_NOTIFY"] = nil
|
||||
::Guard::Notifier.should_receive(:turn_on)
|
||||
::Guard.setup(:notify => true)
|
||||
end
|
||||
|
||||
it "turns off the notifier if the notify option is false" do
|
||||
::Guard::Notifier.should_receive(:turn_off)
|
||||
::Guard.setup(:notify => false)
|
||||
end
|
||||
|
||||
it "turns off the notifier if environment variable GUARD_NOTIFY is false" do
|
||||
ENV["GUARD_NOTIFY"] = 'false'
|
||||
::Guard::Notifier.should_receive(:turn_off)
|
||||
::Guard.setup(:notify => true)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".get_guard_class" do
|
||||
it "reports an error if the class is not found" do
|
||||
::Guard::UI.should_receive(:error)
|
||||
Guard.get_guard_class('notAGuardClass')
|
||||
end
|
||||
|
||||
context 'with a nested Guard class' do
|
||||
it "returns the Guard class" do
|
||||
Guard.should_receive(:try_to_load_gem) { |classname|
|
||||
classname.should == 'classname'
|
||||
class Guard::Classname
|
||||
end
|
||||
}
|
||||
Guard.get_guard_class('classname').should == Guard::Classname
|
||||
end
|
||||
end
|
||||
|
||||
Guard.get_guard_class('inline').should == Guard::Inline
|
||||
context 'with an inline Guard class' do
|
||||
it 'returns the Guard class' do
|
||||
module Guard
|
||||
class Inline < Guard
|
||||
end
|
||||
end
|
||||
|
||||
Guard.get_guard_class('inline').should == Guard::Inline
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".locate_guard" 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
|
||||
describe ".locate_guard" do
|
||||
it "returns the path of a Guard gem" do
|
||||
if Gem::Version.create(Gem::VERSION) >= Gem::Version.create('1.8.0')
|
||||
gem_location = Gem::Specification.find_by_name("guard-rspec").full_gem_path
|
||||
else
|
||||
gem_location = Gem.source_index.find_name("guard-rspec").last.full_gem_path
|
||||
end
|
||||
|
||||
Guard.locate_guard('rspec').should == gem_location
|
||||
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 ".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
|
||||
context "with a task that succeed" do
|
||||
context 'without any arguments' 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
|
||||
it "doesn't fire the Guard" 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
|
||||
it "returns the result of the task" 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)
|
||||
context 'with arguments' do
|
||||
before(:each) do
|
||||
@g.stub!(:regular_with_arg).with("given_path") { "I'm a success" }
|
||||
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'
|
||||
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
|
||||
|
||||
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')
|
||||
gem_location = Gem::Specification.find_by_name("guard-rspec").full_gem_path
|
||||
else
|
||||
gem_location = Gem.source_index.find_name("guard-rspec").last.full_gem_path
|
||||
end
|
||||
context "with a task that raises an exception" do
|
||||
before(:each) { @g.stub!(:failing) { raise "I break your system" } }
|
||||
|
||||
Guard.locate_guard('rspec').should == gem_location
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user