Ensure that scoped groups and group name are symbolized before checking for inclusion.
This is useful since Dsl.evaluate_guardfile can be called directly (hence, options are note passed by Thor, which stringify options).
This commit is contained in:
parent
1ee70fbe2e
commit
0b945f10ec
@ -106,13 +106,13 @@ module Guard
|
|||||||
|
|
||||||
def group(name, &guard_definition)
|
def group(name, &guard_definition)
|
||||||
@groups = @@options[:group] || []
|
@groups = @@options[:group] || []
|
||||||
guard_definition.call if guard_definition && (@groups.empty? || @groups.include?(name.to_s))
|
guard_definition.call if guard_definition && (@groups.empty? || @groups.map(&:to_sym).include?(name.to_sym))
|
||||||
end
|
end
|
||||||
|
|
||||||
def guard(name, options = {}, &watch_definition)
|
def guard(name, options = {}, &watch_definition)
|
||||||
@watchers = []
|
@watchers = []
|
||||||
watch_definition.call if watch_definition
|
watch_definition.call if watch_definition
|
||||||
::Guard.add_guard(name, @watchers, options)
|
::Guard.add_guard(name.to_sym, @watchers, @guard_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def watch(pattern, &action)
|
def watch(pattern, &action)
|
||||||
|
@ -18,7 +18,7 @@ describe Guard::Dsl do
|
|||||||
subject.guardfile_contents.should == valid_guardfile_string
|
subject.guardfile_contents.should == valid_guardfile_string
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should use a -command file over the default loc" do
|
it "should use a given file over the default loc" do
|
||||||
fake_guardfile('/abc/Guardfile', "guard :foo")
|
fake_guardfile('/abc/Guardfile', "guard :foo")
|
||||||
|
|
||||||
Guard::UI.should_not_receive(:error)
|
Guard::UI.should_not_receive(:error)
|
||||||
@ -66,22 +66,22 @@ describe Guard::Dsl do
|
|||||||
subject.evaluate_guardfile(:guardfile_contents => valid_guardfile_string)
|
subject.evaluate_guardfile(:guardfile_contents => valid_guardfile_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "it should correctly read data from its valid data source" do
|
describe "correctly reads data from its valid data source" do
|
||||||
before(:each) { ::Guard::Dsl.stub!(:instance_eval_guardfile) }
|
before(:each) { ::Guard::Dsl.stub!(:instance_eval_guardfile) }
|
||||||
|
|
||||||
it "should read correctly from a string" do
|
it "reads correctly from a string" do
|
||||||
lambda { subject.evaluate_guardfile(:guardfile_contents => valid_guardfile_string) }.should_not raise_error
|
lambda { subject.evaluate_guardfile(:guardfile_contents => valid_guardfile_string) }.should_not raise_error
|
||||||
subject.guardfile_contents.should == valid_guardfile_string
|
subject.guardfile_contents.should == valid_guardfile_string
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should read correctly from a Guardfile" do
|
it "reads correctly from a Guardfile" do
|
||||||
fake_guardfile('/abc/Guardfile', "guard :foo" )
|
fake_guardfile('/abc/Guardfile', "guard :foo" )
|
||||||
|
|
||||||
lambda { subject.evaluate_guardfile(:guardfile => '/abc/Guardfile') }.should_not raise_error
|
lambda { subject.evaluate_guardfile(:guardfile => '/abc/Guardfile') }.should_not raise_error
|
||||||
subject.guardfile_contents.should == "guard :foo"
|
subject.guardfile_contents.should == "guard :foo"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should read correctly from a Guardfile" do
|
it "reads correctly from a Guardfile" do
|
||||||
fake_guardfile(File.join(Dir.pwd, 'Guardfile'), valid_guardfile_string)
|
fake_guardfile(File.join(Dir.pwd, 'Guardfile'), valid_guardfile_string)
|
||||||
|
|
||||||
lambda { subject.evaluate_guardfile }.should_not raise_error
|
lambda { subject.evaluate_guardfile }.should_not raise_error
|
||||||
@ -89,10 +89,10 @@ describe Guard::Dsl do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "It should correctly throw errors when initializing with invalid data" do
|
describe "correctly throws errors when initializing with invalid data" do
|
||||||
before(:each) { ::Guard::Dsl.stub!(:instance_eval_guardfile) }
|
before(:each) { ::Guard::Dsl.stub!(:instance_eval_guardfile) }
|
||||||
|
|
||||||
it "should raise error when there's a problem reading a file" do
|
it "raises error when there's a problem reading a file" do
|
||||||
File.stub!(:exist?).with('/def/Guardfile') { true }
|
File.stub!(:exist?).with('/def/Guardfile') { true }
|
||||||
File.stub!(:read).with('/def/Guardfile') { raise Errno::EACCES.new("permission error") }
|
File.stub!(:read).with('/def/Guardfile') { raise Errno::EACCES.new("permission error") }
|
||||||
|
|
||||||
@ -100,14 +100,14 @@ describe Guard::Dsl do
|
|||||||
lambda { subject.evaluate_guardfile(:guardfile => '/def/Guardfile') }.should raise_error
|
lambda { subject.evaluate_guardfile(:guardfile => '/def/Guardfile') }.should raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should raise error when -guardfile doesn't exist" do
|
it "raises error when given Guardfile doesn't exist" do
|
||||||
File.stub!(:exist?).with('/def/Guardfile') { false }
|
File.stub!(:exist?).with('/def/Guardfile') { false }
|
||||||
|
|
||||||
Guard::UI.should_receive(:error).with(/No Guardfile exists at/)
|
Guard::UI.should_receive(:error).with(/No Guardfile exists at/)
|
||||||
lambda { subject.evaluate_guardfile(:guardfile => '/def/Guardfile') }.should raise_error
|
lambda { subject.evaluate_guardfile(:guardfile => '/def/Guardfile') }.should raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should raise error when resorting to use default, finds no default" do
|
it "raises error when resorting to use default, finds no default" do
|
||||||
File.stub!(:exist?).with(@local_guardfile_path) { false }
|
File.stub!(:exist?).with(@local_guardfile_path) { false }
|
||||||
File.stub!(:exist?).with(@home_guardfile_path) { false }
|
File.stub!(:exist?).with(@home_guardfile_path) { false }
|
||||||
|
|
||||||
@ -115,12 +115,12 @@ describe Guard::Dsl do
|
|||||||
lambda { subject.evaluate_guardfile }.should raise_error
|
lambda { subject.evaluate_guardfile }.should raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should raise error when guardfile_content ends up empty or nil" do
|
it "raises error when guardfile_content ends up empty or nil" do
|
||||||
Guard::UI.should_receive(:error).with(/The command file/)
|
Guard::UI.should_receive(:error).with(/The command file/)
|
||||||
lambda { subject.evaluate_guardfile(:guardfile_contents => "") }.should raise_error
|
lambda { subject.evaluate_guardfile(:guardfile_contents => "") }.should raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not raise error when guardfile_content is nil (skipped)" do
|
it "doesn't raise error when guardfile_content is nil (skipped)" do
|
||||||
Guard::UI.should_not_receive(:error)
|
Guard::UI.should_not_receive(:error)
|
||||||
lambda { subject.evaluate_guardfile(:guardfile_contents => nil) }.should_not raise_error
|
lambda { subject.evaluate_guardfile(:guardfile_contents => nil) }.should_not raise_error
|
||||||
end
|
end
|
||||||
@ -200,48 +200,74 @@ describe Guard::Dsl do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "#group" do
|
describe "#group" do
|
||||||
it "should evaluates only the specified string group" do
|
it "evaluates only the specified string group" do
|
||||||
::Guard.should_receive(:add_guard).with('test', anything, {})
|
::Guard.should_receive(:add_guard).with(:pow, [], {})
|
||||||
lambda { subject.evaluate_guardfile(:guardfile_contents => valid_guardfile_string, :group => ['w']) }.should_not raise_error
|
::Guard.should_receive(:add_guard).with(:test, [], {})
|
||||||
|
|
||||||
|
subject.evaluate_guardfile(:guardfile_contents => valid_guardfile_string, :group => ['w'])
|
||||||
end
|
end
|
||||||
it "should evaluates only the specified symbol group" do
|
|
||||||
::Guard.should_receive(:add_guard).with('test', anything, {})
|
it "evaluates only the specified symbol group" do
|
||||||
lambda { subject.evaluate_guardfile(:guardfile_contents => valid_guardfile_string, :group => ['x']) }.should_not raise_error
|
::Guard.should_receive(:add_guard).with(:pow, [], {})
|
||||||
|
::Guard.should_receive(:add_guard).with(:test, [], {})
|
||||||
|
|
||||||
|
subject.evaluate_guardfile(:guardfile_contents => valid_guardfile_string, :group => [:w])
|
||||||
end
|
end
|
||||||
it "should evaluates only the specified groups" do
|
|
||||||
::Guard.should_receive(:add_guard).with('test', anything, {})
|
it "evaluates only the specified groups" do
|
||||||
::Guard.should_receive(:add_guard).with('another', anything, {})
|
::Guard.should_receive(:add_guard).with(:pow, [], {})
|
||||||
lambda { subject.evaluate_guardfile(:guardfile_contents => valid_guardfile_string, :group => ['x','y']) }.should_not raise_error
|
::Guard.should_receive(:add_guard).with(:rspec, [], {})
|
||||||
|
::Guard.should_receive(:add_guard).with(:ronn, [], {})
|
||||||
|
::Guard.should_receive(:add_guard).with(:less, [], {})
|
||||||
|
|
||||||
|
subject.evaluate_guardfile(:guardfile_contents => valid_guardfile_string, :group => [:x, :y])
|
||||||
end
|
end
|
||||||
it "should evaluate all groups when no group option is specified" do
|
|
||||||
::Guard.should_receive(:add_guard).with('test', anything, {}).twice
|
it "evaluates always guard outside any group (even when a group is given)" do
|
||||||
::Guard.should_receive(:add_guard).with('another', anything, {}).twice
|
::Guard.should_receive(:add_guard).with(:pow, [], {})
|
||||||
lambda { subject.evaluate_guardfile(:guardfile_contents => valid_guardfile_string) }.should_not raise_error
|
::Guard.should_receive(:add_guard).with(:test, [], {})
|
||||||
|
|
||||||
|
subject.evaluate_guardfile(:guardfile_contents => valid_guardfile_string, :group => [:w])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "evaluates all groups when no group option is specified" do
|
||||||
|
::Guard.should_receive(:add_guard).with(:pow, [], {})
|
||||||
|
::Guard.should_receive(:add_guard).with(:test, [], {})
|
||||||
|
::Guard.should_receive(:add_guard).with(:rspec, [], {})
|
||||||
|
::Guard.should_receive(:add_guard).with(:ronn, [], {})
|
||||||
|
::Guard.should_receive(:add_guard).with(:less, [], {})
|
||||||
|
|
||||||
|
subject.evaluate_guardfile(:guardfile_contents => valid_guardfile_string)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: not sure if each seperate quoting/call type needs its own test
|
|
||||||
describe "#guard" do
|
describe "#guard" do
|
||||||
it "should load a guard specified as a quoted string from the DSL" do
|
it "loads a guard specified as a quoted string from the DSL" do
|
||||||
::Guard.should_receive(:add_guard).with('test', [], {})
|
::Guard.should_receive(:add_guard).with(:test, [], {})
|
||||||
|
|
||||||
subject.evaluate_guardfile(:guardfile_contents => "guard 'test'")
|
subject.evaluate_guardfile(:guardfile_contents => "guard 'test'")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should load a guard specified as a symbol from the DSL" do
|
it "loads a guard specified as a double quoted string from the DSL" do
|
||||||
|
::Guard.should_receive(:add_guard).with(:test, [], {})
|
||||||
|
|
||||||
|
subject.evaluate_guardfile(:guardfile_contents => 'guard "test"')
|
||||||
|
end
|
||||||
|
|
||||||
|
it "loads a guard specified as a symbol from the DSL" do
|
||||||
::Guard.should_receive(:add_guard).with(:test, [], {})
|
::Guard.should_receive(:add_guard).with(:test, [], {})
|
||||||
|
|
||||||
subject.evaluate_guardfile(:guardfile_contents => "guard :test")
|
subject.evaluate_guardfile(:guardfile_contents => "guard :test")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should load a guard specified as a symbol and called with parens from the DSL" do
|
it "loads a guard specified as a symbol and called with parens from the DSL" do
|
||||||
::Guard.should_receive(:add_guard).with(:test, [], {})
|
::Guard.should_receive(:add_guard).with(:test, [], {})
|
||||||
|
|
||||||
subject.evaluate_guardfile(:guardfile_contents => "guard(:test)")
|
subject.evaluate_guardfile(:guardfile_contents => "guard(:test)")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should receive options when specified" do
|
it "receives options when specified, from normal arg" do
|
||||||
::Guard.should_receive(:add_guard).with('test', anything, { :opt_a => 1, :opt_b => 'fancy' })
|
::Guard.should_receive(:add_guard).with(:test, [], { :opt_a => 1, :opt_b => 'fancy' })
|
||||||
|
|
||||||
subject.evaluate_guardfile(:guardfile_contents => "guard 'test', :opt_a => 1, :opt_b => 'fancy'")
|
subject.evaluate_guardfile(:guardfile_contents => "guard 'test', :opt_a => 1, :opt_b => 'fancy'")
|
||||||
end
|
end
|
||||||
@ -254,7 +280,7 @@ describe Guard::Dsl do
|
|||||||
watch('c')
|
watch('c')
|
||||||
end"
|
end"
|
||||||
|
|
||||||
::Guard.should_receive(:add_guard).with('test', anything, {}) do |name, watchers, options|
|
::Guard.should_receive(:add_guard).with(:test, anything, {}) do |name, watchers, options|
|
||||||
watchers.size.should == 2
|
watchers.size.should == 2
|
||||||
watchers[0].pattern.should == 'a'
|
watchers[0].pattern.should == 'a'
|
||||||
watchers[0].action.call.should == proc { 'b' }.call
|
watchers[0].action.call.should == proc { 'b' }.call
|
||||||
@ -273,29 +299,22 @@ private
|
|||||||
end
|
end
|
||||||
|
|
||||||
def valid_guardfile_string
|
def valid_guardfile_string
|
||||||
"group 'w' do
|
"
|
||||||
guard 'test' do
|
guard :pow
|
||||||
watch('c')
|
|
||||||
end
|
group 'w' do
|
||||||
|
guard 'test'
|
||||||
end
|
end
|
||||||
|
|
||||||
group :x do
|
group :x do
|
||||||
guard 'test' do
|
guard 'rspec'
|
||||||
watch('c')
|
guard :ronn
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
group 'y' do
|
group 'y' do
|
||||||
guard 'another' do
|
guard 'less'
|
||||||
watch('c')
|
|
||||||
end
|
end
|
||||||
end
|
"
|
||||||
|
|
||||||
group 'z' do
|
|
||||||
guard 'another' do
|
|
||||||
watch('c')
|
|
||||||
end
|
|
||||||
end"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def mock_guardfile_content(content)
|
def mock_guardfile_content(content)
|
||||||
|
Loading…
Reference in New Issue
Block a user