2010-10-30 16:26:09 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Guard::Dsl do
|
2010-10-30 20:42:17 +00:00
|
|
|
subject { Guard::Dsl }
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-10-30 20:42:17 +00:00
|
|
|
before(:each) do
|
2010-10-30 16:26:09 +00:00
|
|
|
::Guard.stub!(:add_guard)
|
|
|
|
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
|
2010-10-30 20:42:17 +00:00
|
|
|
Dir.stub!(:pwd).and_return("no_guardfile_here")
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-10-30 16:26:09 +00:00
|
|
|
Guard::UI.should_receive(:error).with("No Guardfile in current folder, please create one.")
|
|
|
|
lambda { subject.evaluate_guardfile }.should raise_error
|
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-04-16 21:13:29 +00:00
|
|
|
it "displays an error message when Guardfile is not valid" do
|
2010-10-30 20:42:17 +00:00
|
|
|
mock_guardfile_content("This Guardfile is invalid!")
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-10-30 16:26:09 +00:00
|
|
|
Guard::UI.should_receive(:error).with(/Invalid Guardfile, original error is:\n/)
|
|
|
|
lambda { subject.evaluate_guardfile }.should raise_error
|
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-12-17 17:37:24 +00:00
|
|
|
describe ".guardfile_include?" do
|
2011-04-16 21:13:29 +00:00
|
|
|
it "detects a guard specified by a string with simple quotes" do
|
2010-12-17 17:37:24 +00:00
|
|
|
mock_guardfile_content("guard 'test'")
|
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 specified by a string with double quotes" do
|
|
|
|
mock_guardfile_content('guard "test"')
|
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
|
2010-12-17 17:37:24 +00:00
|
|
|
mock_guardfile_content("guard :test")
|
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
|
|
|
|
mock_guardfile_content("guard(:test)")
|
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
|
|
|
|
2010-12-17 17:13:31 +00:00
|
|
|
describe "#group" do
|
|
|
|
before do
|
|
|
|
mock_guardfile_content("
|
|
|
|
group 'x' do
|
|
|
|
guard 'test' do
|
|
|
|
watch('c')
|
|
|
|
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
|
|
|
group 'y' do
|
|
|
|
guard 'another' do
|
|
|
|
watch('c')
|
|
|
|
end
|
|
|
|
end")
|
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-12-17 17:13:31 +00:00
|
|
|
it "should 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
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-12-17 17:13:31 +00:00
|
|
|
it "should 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'])
|
|
|
|
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
|
2010-12-17 17:37:24 +00:00
|
|
|
it "should load a guard specified as a string from the DSL" do
|
2010-12-17 17:13:31 +00:00
|
|
|
mock_guardfile_content("guard 'test'")
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-12-17 17:13:31 +00:00
|
|
|
::Guard.should_receive(:add_guard).with('test', [], {})
|
|
|
|
subject.evaluate_guardfile
|
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-12-17 17:37:24 +00:00
|
|
|
it "should load a guard specified as a symbol from the DSL" do
|
|
|
|
mock_guardfile_content("guard :test")
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-12-17 17:37:24 +00:00
|
|
|
::Guard.should_receive(:add_guard).with(:test, [], {})
|
|
|
|
subject.evaluate_guardfile
|
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-12-17 17:13:31 +00:00
|
|
|
it "should receive options when specified" do
|
|
|
|
mock_guardfile_content("guard 'test', :opt_a => 1, :opt_b => 'fancy'")
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-12-17 17:13:31 +00:00
|
|
|
::Guard.should_receive(:add_guard).with('test', anything, { :opt_a => 1, :opt_b => 'fancy' })
|
|
|
|
subject.evaluate_guardfile
|
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
|
|
|
|
it "should receive watchers when specified" do
|
|
|
|
mock_guardfile_content("
|
|
|
|
guard 'test' do
|
|
|
|
watch('a') { 'b' }
|
|
|
|
watch('c')
|
|
|
|
end")
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-12-17 17:13:31 +00:00
|
|
|
::Guard.should_receive(:add_guard).with('test', anything, {}) do |name, watchers, options|
|
|
|
|
watchers.size.should == 2
|
|
|
|
watchers[0].pattern.should == 'a'
|
|
|
|
watchers[0].action.call.should == proc { 'b' }.call
|
|
|
|
watchers[1].pattern.should == 'c'
|
|
|
|
watchers[1].action.should be_nil
|
|
|
|
end
|
|
|
|
subject.evaluate_guardfile
|
|
|
|
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
|
|
|
|
2010-10-30 20:42:17 +00:00
|
|
|
def mock_guardfile_content(content)
|
|
|
|
File.stub!(:read).with(File.expand_path('../../../Guardfile', __FILE__)) { content }
|
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
|
|
|
end
|