2010-10-30 16:26:09 +00:00
|
|
|
require 'spec_helper'
|
2011-04-29 22:40:12 +00:00
|
|
|
require 'guard/guard'
|
2010-10-30 16:26:09 +00:00
|
|
|
|
|
|
|
describe Guard::Dsl do
|
2011-05-27 15:56:18 +00:00
|
|
|
subject { described_class }
|
2011-04-29 22:40:12 +00:00
|
|
|
class Guard::Dummy < Guard::Guard; end
|
|
|
|
|
2010-10-30 20:42:17 +00:00
|
|
|
before(:each) do
|
2011-05-28 15:52:50 +00:00
|
|
|
@local_guardfile_path = File.join(Dir.pwd, 'Guardfile')
|
2011-06-21 18:43:30 +00:00
|
|
|
@home_guardfile_path = File.expand_path(File.join("~", ".Guardfile"))
|
2011-08-31 07:47:03 +00:00
|
|
|
@user_config_path = File.expand_path(File.join("~", ".guard.rb"))
|
2011-05-27 15:56:18 +00:00
|
|
|
::Guard.stub!(:options).and_return(:debug => true)
|
2011-07-02 08:01:45 +00:00
|
|
|
::Guard.stub!(:guards).and_return([mock('Guard')])
|
2010-10-30 16:26:09 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-08-31 07:47:03 +00:00
|
|
|
def self.disable_user_config
|
|
|
|
before(:each) { File.stub(:exist?).with(@user_config_path) { false } }
|
|
|
|
end
|
|
|
|
|
2011-05-05 09:05:58 +00:00
|
|
|
describe "it should select the correct data source for Guardfile" do
|
2011-07-02 08:01:45 +00:00
|
|
|
before(:each) { ::Guard::Dsl.stub!(:instance_eval_guardfile) }
|
2011-08-31 07:47:03 +00:00
|
|
|
disable_user_config
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-05-05 09:05:58 +00:00
|
|
|
it "should use a string for initializing" do
|
|
|
|
Guard::UI.should_not_receive(:error)
|
2011-05-27 15:56:18 +00:00
|
|
|
lambda { subject.evaluate_guardfile(:guardfile_contents => valid_guardfile_string) }.should_not raise_error
|
|
|
|
subject.guardfile_contents.should == valid_guardfile_string
|
2011-05-05 09:05:58 +00:00
|
|
|
end
|
2011-07-29 07:05:40 +00:00
|
|
|
|
2011-08-16 22:26:03 +00:00
|
|
|
it "should use a given file over the default loc" do
|
2011-05-27 15:56:18 +00:00
|
|
|
fake_guardfile('/abc/Guardfile', "guard :foo")
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-05-05 09:05:58 +00:00
|
|
|
Guard::UI.should_not_receive(:error)
|
2011-05-27 15:56:18 +00:00
|
|
|
lambda { subject.evaluate_guardfile(:guardfile => '/abc/Guardfile') }.should_not raise_error
|
|
|
|
subject.guardfile_contents.should == "guard :foo"
|
2011-05-05 09:05:58 +00:00
|
|
|
end
|
2011-05-27 15:56:18 +00:00
|
|
|
|
2011-05-05 09:05:58 +00:00
|
|
|
it "should use a default file if no other options are given" do
|
2011-05-28 15:52:50 +00:00
|
|
|
fake_guardfile(@local_guardfile_path, "guard :bar")
|
2011-05-27 15:56:18 +00:00
|
|
|
|
2011-05-05 09:05:58 +00:00
|
|
|
Guard::UI.should_not_receive(:error)
|
2011-05-27 15:56:18 +00:00
|
|
|
lambda { subject.evaluate_guardfile }.should_not raise_error
|
|
|
|
subject.guardfile_contents.should == "guard :bar"
|
2011-05-05 09:05:58 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-05-27 15:56:18 +00:00
|
|
|
it "should use a string over any other method" do
|
|
|
|
fake_guardfile('/abc/Guardfile', "guard :foo")
|
2011-05-28 15:52:50 +00:00
|
|
|
fake_guardfile(@local_guardfile_path, "guard :bar")
|
2011-05-05 09:05:58 +00:00
|
|
|
|
|
|
|
Guard::UI.should_not_receive(:error)
|
2011-05-27 15:56:18 +00:00
|
|
|
lambda { subject.evaluate_guardfile(:guardfile_contents => valid_guardfile_string) }.should_not raise_error
|
|
|
|
subject.guardfile_contents.should == valid_guardfile_string
|
2011-05-05 09:05:58 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-05-27 15:56:18 +00:00
|
|
|
it "should use the given Guardfile over default Guardfile" do
|
|
|
|
fake_guardfile('/abc/Guardfile', "guard :foo")
|
2011-05-28 15:52:50 +00:00
|
|
|
fake_guardfile(@local_guardfile_path, "guard :bar")
|
2011-05-05 09:05:58 +00:00
|
|
|
|
|
|
|
Guard::UI.should_not_receive(:error)
|
2011-05-27 15:56:18 +00:00
|
|
|
lambda { subject.evaluate_guardfile(:guardfile => '/abc/Guardfile') }.should_not raise_error
|
|
|
|
subject.guardfile_contents.should == "guard :foo"
|
2011-05-05 09:05:58 +00:00
|
|
|
end
|
2011-08-31 07:47:03 +00:00
|
|
|
|
|
|
|
it 'should append the user config file if present' do
|
|
|
|
fake_guardfile('/abc/Guardfile', "guard :foo")
|
|
|
|
fake_guardfile(@user_config_path, "guard :bar")
|
|
|
|
Guard::UI.should_not_receive(:error)
|
|
|
|
lambda { subject.evaluate_guardfile(:guardfile => '/abc/Guardfile') }.should_not raise_error
|
|
|
|
subject.guardfile_contents_with_user_config.should == "guard :foo\nguard :bar"
|
|
|
|
end
|
|
|
|
|
2010-10-30 16:26:09 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-04-16 21:13:29 +00:00
|
|
|
it "displays an error message when no Guardfile is found" do
|
2011-05-28 15:52:50 +00:00
|
|
|
subject.stub(:guardfile_default_path).and_return("no_guardfile_here")
|
|
|
|
Guard::UI.should_receive(:error).with("No Guardfile found, please create one with `guard init`.")
|
2010-10-30 16:26:09 +00:00
|
|
|
lambda { subject.evaluate_guardfile }.should raise_error
|
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-07-02 08:01:45 +00:00
|
|
|
it "displays an error message when no guard are defined in Guardfile" do
|
|
|
|
::Guard::Dsl.stub!(:instance_eval_guardfile)
|
|
|
|
::Guard.stub!(:guards).and_return([])
|
|
|
|
Guard::UI.should_receive(:error)
|
|
|
|
subject.evaluate_guardfile(:guardfile_contents => valid_guardfile_string)
|
|
|
|
end
|
|
|
|
|
2011-08-16 22:26:03 +00:00
|
|
|
describe "correctly reads data from its valid data source" do
|
2011-07-02 08:01:45 +00:00
|
|
|
before(:each) { ::Guard::Dsl.stub!(:instance_eval_guardfile) }
|
2011-08-31 07:47:03 +00:00
|
|
|
disable_user_config
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-08-16 22:26:03 +00:00
|
|
|
it "reads correctly from a string" do
|
2011-05-27 15:56:18 +00:00
|
|
|
lambda { subject.evaluate_guardfile(:guardfile_contents => valid_guardfile_string) }.should_not raise_error
|
2011-05-05 09:05:58 +00:00
|
|
|
subject.guardfile_contents.should == valid_guardfile_string
|
2010-12-17 17:37:24 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-08-16 22:26:03 +00:00
|
|
|
it "reads correctly from a Guardfile" do
|
2011-05-27 15:56:18 +00:00
|
|
|
fake_guardfile('/abc/Guardfile', "guard :foo" )
|
2011-05-05 09:05:58 +00:00
|
|
|
|
2011-05-27 15:56:18 +00:00
|
|
|
lambda { subject.evaluate_guardfile(:guardfile => '/abc/Guardfile') }.should_not raise_error
|
|
|
|
subject.guardfile_contents.should == "guard :foo"
|
2011-04-16 21:13:29 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-08-16 22:26:03 +00:00
|
|
|
it "reads correctly from a Guardfile" do
|
2011-05-27 15:56:18 +00:00
|
|
|
fake_guardfile(File.join(Dir.pwd, 'Guardfile'), valid_guardfile_string)
|
|
|
|
|
|
|
|
lambda { subject.evaluate_guardfile }.should_not raise_error
|
2011-05-05 09:05:58 +00:00
|
|
|
subject.guardfile_contents.should == valid_guardfile_string
|
2010-12-17 17:37:24 +00:00
|
|
|
end
|
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-08-16 22:26:03 +00:00
|
|
|
describe "correctly throws errors when initializing with invalid data" do
|
2011-07-02 08:01:45 +00:00
|
|
|
before(:each) { ::Guard::Dsl.stub!(:instance_eval_guardfile) }
|
2011-05-27 15:56:18 +00:00
|
|
|
|
2011-08-16 22:26:03 +00:00
|
|
|
it "raises error when there's a problem reading a file" do
|
2011-05-05 09:05:58 +00:00
|
|
|
File.stub!(:exist?).with('/def/Guardfile') { true }
|
2011-05-27 15:56:18 +00:00
|
|
|
File.stub!(:read).with('/def/Guardfile') { raise Errno::EACCES.new("permission error") }
|
2011-05-05 09:05:58 +00:00
|
|
|
|
|
|
|
Guard::UI.should_receive(:error).with(/^Error reading file/)
|
2011-05-27 15:56:18 +00:00
|
|
|
lambda { subject.evaluate_guardfile(:guardfile => '/def/Guardfile') }.should raise_error
|
|
|
|
end
|
2011-05-05 09:05:58 +00:00
|
|
|
|
2011-08-16 22:26:03 +00:00
|
|
|
it "raises error when given Guardfile doesn't exist" do
|
2011-05-05 09:05:58 +00:00
|
|
|
File.stub!(:exist?).with('/def/Guardfile') { false }
|
|
|
|
|
|
|
|
Guard::UI.should_receive(:error).with(/No Guardfile exists at/)
|
2011-05-27 15:56:18 +00:00
|
|
|
lambda { subject.evaluate_guardfile(:guardfile => '/def/Guardfile') }.should raise_error
|
2011-05-05 09:05:58 +00:00
|
|
|
end
|
|
|
|
|
2011-08-16 22:26:03 +00:00
|
|
|
it "raises error when resorting to use default, finds no default" do
|
2011-05-28 15:52:50 +00:00
|
|
|
File.stub!(:exist?).with(@local_guardfile_path) { false }
|
|
|
|
File.stub!(:exist?).with(@home_guardfile_path) { false }
|
2011-05-05 09:05:58 +00:00
|
|
|
|
2011-05-28 15:52:50 +00:00
|
|
|
Guard::UI.should_receive(:error).with("No Guardfile found, please create one with `guard init`.")
|
2011-05-27 15:56:18 +00:00
|
|
|
lambda { subject.evaluate_guardfile }.should raise_error
|
2011-05-05 09:05:58 +00:00
|
|
|
end
|
|
|
|
|
2011-08-16 22:26:03 +00:00
|
|
|
it "raises error when guardfile_content ends up empty or nil" do
|
2011-07-29 07:05:40 +00:00
|
|
|
Guard::UI.should_receive(:error).with(/The command file/)
|
2011-05-27 15:56:18 +00:00
|
|
|
lambda { subject.evaluate_guardfile(:guardfile_contents => "") }.should raise_error
|
2011-07-29 07:05:40 +00:00
|
|
|
end
|
|
|
|
|
2011-08-16 22:26:03 +00:00
|
|
|
it "doesn't raise error when guardfile_content is nil (skipped)" do
|
2011-07-29 07:05:40 +00:00
|
|
|
Guard::UI.should_not_receive(:error)
|
|
|
|
lambda { subject.evaluate_guardfile(:guardfile_contents => nil) }.should_not raise_error
|
2011-05-05 09:05:58 +00:00
|
|
|
end
|
|
|
|
end
|
2011-05-27 15:56:18 +00:00
|
|
|
|
2011-04-16 21:13:29 +00:00
|
|
|
it "displays an error message when Guardfile is not valid" do
|
2011-05-05 09:05:58 +00:00
|
|
|
Guard::UI.should_receive(:error).with(/Invalid Guardfile, original error is:/)
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-05-27 15:56:18 +00:00
|
|
|
lambda { subject.evaluate_guardfile(:guardfile_contents => invalid_guardfile_string ) }.should raise_error
|
2010-10-30 16:26:09 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-07-28 22:22:53 +00:00
|
|
|
describe ".reevaluate_guardfile" do
|
2011-07-02 08:01:45 +00:00
|
|
|
before(:each) { ::Guard::Dsl.stub!(:instance_eval_guardfile) }
|
|
|
|
|
|
|
|
it "resets already definded guards before calling evaluate_guardfile" do
|
2011-07-15 06:33:13 +00:00
|
|
|
Guard::Notifier.turn_off
|
2011-07-02 08:01:45 +00:00
|
|
|
subject.evaluate_guardfile(:guardfile_contents => invalid_guardfile_string)
|
|
|
|
::Guard.guards.should_not be_empty
|
|
|
|
::Guard::Dsl.should_receive(:evaluate_guardfile)
|
2011-07-28 22:22:53 +00:00
|
|
|
subject.reevaluate_guardfile
|
2011-07-02 08:01:45 +00:00
|
|
|
::Guard.guards.should be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-28 15:52:50 +00:00
|
|
|
describe ".guardfile_default_path" do
|
2011-05-24 21:32:02 +00:00
|
|
|
let(:local_path) { File.join(Dir.pwd, 'Guardfile') }
|
2011-06-21 18:43:30 +00:00
|
|
|
let(:user_path) { File.expand_path(File.join("~", '.Guardfile')) }
|
2011-07-02 08:01:45 +00:00
|
|
|
before(:each) { File.stub(:exist? => false) }
|
2011-05-25 18:23:02 +00:00
|
|
|
|
2011-05-24 21:32:02 +00:00
|
|
|
context "when there is a local Guardfile" do
|
|
|
|
it "returns the path to the local Guardfile" do
|
|
|
|
File.stub(:exist?).with(local_path).and_return(true)
|
2011-05-28 15:52:50 +00:00
|
|
|
subject.guardfile_default_path.should == local_path
|
2011-05-24 21:32:02 +00:00
|
|
|
end
|
|
|
|
end
|
2011-05-25 18:23:02 +00:00
|
|
|
|
2011-05-24 21:32:02 +00:00
|
|
|
context "when there is a Guardfile in the user's home directory" do
|
|
|
|
it "returns the path to the user Guardfile" do
|
|
|
|
File.stub(:exist?).with(user_path).and_return(true)
|
2011-05-28 15:52:50 +00:00
|
|
|
subject.guardfile_default_path.should == user_path
|
2011-05-24 21:32:02 +00:00
|
|
|
end
|
|
|
|
end
|
2011-05-25 18:23:02 +00:00
|
|
|
|
2011-05-24 21:32:02 +00:00
|
|
|
context "when there's both a local and user Guardfile" do
|
|
|
|
it "returns the path to the local Guardfile" do
|
|
|
|
File.stub(:exist?).with(local_path).and_return(true)
|
|
|
|
File.stub(:exist?).with(user_path).and_return(true)
|
2011-05-28 15:52:50 +00:00
|
|
|
subject.guardfile_default_path.should == local_path
|
2011-05-24 21:32:02 +00:00
|
|
|
end
|
|
|
|
end
|
2010-10-30 16:26:09 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-12-17 17:37:24 +00:00
|
|
|
describe ".guardfile_include?" do
|
2011-05-05 09:05:58 +00:00
|
|
|
it "detects a guard specified by a string with double quotes" do
|
2011-05-27 15:56:18 +00:00
|
|
|
subject.stub(:guardfile_contents => 'guard "test" {watch("c")}')
|
|
|
|
|
2011-04-16 21:13:29 +00:00
|
|
|
subject.guardfile_include?('test').should be_true
|
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-05-05 09:05:58 +00:00
|
|
|
it "detects a guard specified by a string with single quote" do
|
2011-05-27 15:56:18 +00:00
|
|
|
subject.stub(:guardfile_contents => 'guard \'test\' {watch("c")}')
|
|
|
|
|
2010-12-17 17:37:24 +00:00
|
|
|
subject.guardfile_include?('test').should be_true
|
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-04-16 21:13:29 +00:00
|
|
|
it "detects a guard specified by a symbol" do
|
2011-05-27 15:56:18 +00:00
|
|
|
subject.stub(:guardfile_contents => 'guard :test {watch("c")}')
|
|
|
|
|
2011-04-16 21:13:29 +00:00
|
|
|
subject.guardfile_include?('test').should be_true
|
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-04-16 21:13:29 +00:00
|
|
|
it "detects a guard wrapped in parentheses" do
|
2011-05-27 15:56:18 +00:00
|
|
|
subject.stub(:guardfile_contents => 'guard(:test) {watch("c")}')
|
|
|
|
|
2010-12-17 17:37:24 +00:00
|
|
|
subject.guardfile_include?('test').should be_true
|
|
|
|
end
|
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-09-01 11:30:25 +00:00
|
|
|
describe "#ignore_paths" do
|
|
|
|
disable_user_config
|
|
|
|
|
|
|
|
it "adds the paths to the listener's ignore_paths" do
|
|
|
|
::Guard.stub!(:listener).and_return(mock('Listener'))
|
|
|
|
::Guard.listener.should_receive(:ignore_paths).and_return(ignore_paths = ['faz'])
|
|
|
|
|
|
|
|
subject.evaluate_guardfile(:guardfile_contents => "ignore_paths 'foo', 'bar'")
|
|
|
|
ignore_paths.should == ['faz', 'foo', 'bar']
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-12-17 17:13:31 +00:00
|
|
|
describe "#group" do
|
2011-08-31 07:47:03 +00:00
|
|
|
disable_user_config
|
|
|
|
|
2011-08-16 22:26:03 +00:00
|
|
|
it "evaluates only the specified string group" do
|
2011-08-17 08:45:20 +00:00
|
|
|
::Guard.should_receive(:add_guard).with(:pow, [], [], { :group => :default })
|
|
|
|
::Guard.should_receive(:add_guard).with(:test, [], [], { :group => :w })
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-08-16 22:26:03 +00:00
|
|
|
subject.evaluate_guardfile(:guardfile_contents => valid_guardfile_string, :group => ['w'])
|
2010-12-17 17:13:31 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-08-16 22:26:03 +00:00
|
|
|
it "evaluates only the specified symbol group" do
|
2011-08-17 08:45:20 +00:00
|
|
|
::Guard.should_receive(:add_guard).with(:pow, [], [], { :group => :default })
|
|
|
|
::Guard.should_receive(:add_guard).with(:test, [], [], { :group => :w })
|
2011-08-16 22:26:03 +00:00
|
|
|
|
|
|
|
subject.evaluate_guardfile(:guardfile_contents => valid_guardfile_string, :group => [:w])
|
2010-12-17 17:13:31 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-04-16 21:02:13 +00:00
|
|
|
it "evaluates only the specified groups" do
|
2011-08-17 08:45:20 +00:00
|
|
|
::Guard.should_receive(:add_guard).with(:pow, [], [], { :group => :default })
|
|
|
|
::Guard.should_receive(:add_guard).with(:rspec, [], [], { :group => :x })
|
|
|
|
::Guard.should_receive(:add_guard).with(:ronn, [], [], { :group => :x })
|
|
|
|
::Guard.should_receive(:add_guard).with(:less, [], [], { :group => :y })
|
2011-08-16 22:26:03 +00:00
|
|
|
|
|
|
|
subject.evaluate_guardfile(:guardfile_contents => valid_guardfile_string, :group => [:x, :y])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "evaluates always guard outside any group (even when a group is given)" do
|
2011-08-17 08:45:20 +00:00
|
|
|
::Guard.should_receive(:add_guard).with(:pow, [], [], { :group => :default })
|
|
|
|
::Guard.should_receive(:add_guard).with(:test, [], [], { :group => :w })
|
2011-08-16 22:26:03 +00:00
|
|
|
|
|
|
|
subject.evaluate_guardfile(:guardfile_contents => valid_guardfile_string, :group => [:w])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "evaluates all groups when no group option is specified" do
|
2011-08-17 08:45:20 +00:00
|
|
|
::Guard.should_receive(:add_guard).with(:pow, [], [], { :group => :default })
|
|
|
|
::Guard.should_receive(:add_guard).with(:test, [], [], { :group => :w })
|
|
|
|
::Guard.should_receive(:add_guard).with(:rspec, [], [], { :group => :x })
|
|
|
|
::Guard.should_receive(:add_guard).with(:ronn, [], [], { :group => :x })
|
|
|
|
::Guard.should_receive(:add_guard).with(:less, [], [], { :group => :y })
|
2011-08-16 22:26:03 +00:00
|
|
|
|
|
|
|
subject.evaluate_guardfile(:guardfile_contents => valid_guardfile_string)
|
2010-12-17 17:13:31 +00:00
|
|
|
end
|
2010-12-17 15:31:39 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-12-17 17:13:31 +00:00
|
|
|
describe "#guard" do
|
2011-08-31 07:47:03 +00:00
|
|
|
disable_user_config
|
|
|
|
|
2011-08-16 22:26:03 +00:00
|
|
|
it "loads a guard specified as a quoted string from the DSL" do
|
2011-08-17 08:45:20 +00:00
|
|
|
::Guard.should_receive(:add_guard).with(:test, [], [], { :group => :default })
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-05-05 09:05:58 +00:00
|
|
|
subject.evaluate_guardfile(:guardfile_contents => "guard 'test'")
|
2010-12-17 17:13:31 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-08-16 22:26:03 +00:00
|
|
|
it "loads a guard specified as a double quoted string from the DSL" do
|
2011-08-17 08:45:20 +00:00
|
|
|
::Guard.should_receive(:add_guard).with(:test, [], [], { :group => :default })
|
2011-08-16 22:26:03 +00:00
|
|
|
|
|
|
|
subject.evaluate_guardfile(:guardfile_contents => 'guard "test"')
|
2010-12-17 17:13:31 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-04-16 21:02:13 +00:00
|
|
|
it "loads a guard specified as a symbol from the DSL" do
|
2011-08-17 08:45:20 +00:00
|
|
|
::Guard.should_receive(:add_guard).with(:test, [], [], { :group => :default })
|
2011-05-27 15:56:18 +00:00
|
|
|
|
2011-05-05 09:05:58 +00:00
|
|
|
subject.evaluate_guardfile(:guardfile_contents => "guard :test")
|
2010-12-17 17:37:24 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-08-16 22:26:03 +00:00
|
|
|
it "loads a guard specified as a symbol and called with parens from the DSL" do
|
2011-08-17 08:45:20 +00:00
|
|
|
::Guard.should_receive(:add_guard).with(:test, [], [], { :group => :default })
|
2011-05-27 15:56:18 +00:00
|
|
|
|
2011-05-05 09:05:58 +00:00
|
|
|
subject.evaluate_guardfile(:guardfile_contents => "guard(:test)")
|
2010-12-17 17:37:24 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-08-16 22:26:03 +00:00
|
|
|
it "receives options when specified, from normal arg" do
|
2011-08-17 08:45:20 +00:00
|
|
|
::Guard.should_receive(:add_guard).with(:test, [], [], { :opt_a => 1, :opt_b => 'fancy', :group => :default })
|
2011-05-27 15:56:18 +00:00
|
|
|
|
2011-05-05 09:05:58 +00:00
|
|
|
subject.evaluate_guardfile(:guardfile_contents => "guard 'test', :opt_a => 1, :opt_b => 'fancy'")
|
2010-10-30 16:26:09 +00:00
|
|
|
end
|
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-12-17 17:13:31 +00:00
|
|
|
describe "#watch" do
|
2011-08-31 07:47:03 +00:00
|
|
|
disable_user_config
|
|
|
|
|
2010-12-17 17:13:31 +00:00
|
|
|
it "should receive watchers when specified" do
|
2011-08-17 08:45:20 +00:00
|
|
|
::Guard.should_receive(:add_guard).with(:dummy, anything, anything, { :group => :default }) do |name, watchers, callbacks, options|
|
2010-12-17 17:13:31 +00:00
|
|
|
watchers.size.should == 2
|
|
|
|
watchers[0].pattern.should == 'a'
|
|
|
|
watchers[0].action.call.should == proc { 'b' }.call
|
|
|
|
watchers[1].pattern.should == 'c'
|
2011-05-05 09:05:58 +00:00
|
|
|
watchers[1].action.should == nil
|
2011-04-16 21:02:13 +00:00
|
|
|
end
|
2011-08-16 23:34:27 +00:00
|
|
|
subject.evaluate_guardfile(:guardfile_contents => "
|
|
|
|
guard :dummy do
|
|
|
|
watch('a') { 'b' }
|
|
|
|
watch('c')
|
|
|
|
end")
|
2011-04-16 21:02:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#callback" do
|
|
|
|
it "creates callbacks for the guard" do
|
|
|
|
class MyCustomCallback
|
2011-04-29 22:40:12 +00:00
|
|
|
def self.call(guard_class, event, args)
|
|
|
|
# do nothing
|
|
|
|
end
|
2011-04-16 21:02:13 +00:00
|
|
|
end
|
|
|
|
|
2011-08-17 08:45:20 +00:00
|
|
|
::Guard.should_receive(:add_guard).with(:dummy, anything, anything, { :group => :default }) do |name, watchers, callbacks, options|
|
2011-04-16 21:02:13 +00:00
|
|
|
callbacks.should have(2).items
|
2011-04-29 22:40:12 +00:00
|
|
|
callbacks[0][:events].should == :start_end
|
|
|
|
callbacks[0][:listener].call(Guard::Dummy, :start_end, 'foo').should == "Guard::Dummy executed 'start_end' hook with foo!"
|
|
|
|
callbacks[1][:events].should == [:start_begin, :run_all_begin]
|
|
|
|
callbacks[1][:listener].should == MyCustomCallback
|
2010-12-17 17:13:31 +00:00
|
|
|
end
|
2011-08-16 23:34:27 +00:00
|
|
|
subject.evaluate_guardfile(:guardfile_contents => '
|
|
|
|
guard :dummy do
|
|
|
|
callback(:start_end) { |guard_class, event, args| "#{guard_class} executed \'#{event}\' hook with #{args}!" }
|
|
|
|
callback(MyCustomCallback, [:start_begin, :run_all_begin])
|
|
|
|
end')
|
2010-12-17 17:13:31 +00:00
|
|
|
end
|
2010-10-30 16:26:09 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-10-30 16:26:09 +00:00
|
|
|
private
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-05-05 09:05:58 +00:00
|
|
|
def fake_guardfile(name, contents)
|
|
|
|
File.stub!(:exist?).with(name) { true }
|
2011-05-27 15:56:18 +00:00
|
|
|
File.stub!(:read).with(name) { contents }
|
2011-05-05 09:05:58 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-05-05 09:05:58 +00:00
|
|
|
def valid_guardfile_string
|
2011-08-16 22:26:03 +00:00
|
|
|
"
|
|
|
|
guard :pow
|
|
|
|
|
|
|
|
group 'w' do
|
|
|
|
guard 'test'
|
2011-06-01 19:00:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
group :x do
|
2011-08-16 22:26:03 +00:00
|
|
|
guard 'rspec'
|
|
|
|
guard :ronn
|
2011-05-05 09:05:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
group 'y' do
|
2011-08-16 22:26:03 +00:00
|
|
|
guard 'less'
|
2011-05-05 09:05:58 +00:00
|
|
|
end
|
2011-08-16 22:26:03 +00:00
|
|
|
"
|
2010-10-30 16:26:09 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-05-05 09:05:58 +00:00
|
|
|
def invalid_guardfile_string
|
2011-05-27 15:56:18 +00:00
|
|
|
"Bad Guardfile"
|
2011-05-05 09:05:58 +00:00
|
|
|
end
|
2010-10-30 16:26:09 +00:00
|
|
|
end
|