2010-10-30 16:26:09 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'guard/dsl'
|
|
|
|
|
|
|
|
describe Guard::Dsl do
|
2010-10-30 20:42:17 +00:00
|
|
|
subject { Guard::Dsl }
|
2010-10-30 16:26:09 +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
|
|
|
|
|
|
|
|
it "write 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")
|
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
|
|
|
|
|
|
|
|
it "write an error message when Guardfile is not valid" do
|
2010-10-30 20:42:17 +00:00
|
|
|
mock_guardfile_content("This Guardfile is invalid!")
|
|
|
|
|
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
|
|
|
|
|
2010-10-30 20:42:17 +00:00
|
|
|
it "load a guard from the DSL" do
|
|
|
|
mock_guardfile_content("guard 'test'")
|
2010-10-30 16:26:09 +00:00
|
|
|
|
2010-10-30 20:42:17 +00:00
|
|
|
::Guard.should_receive(:add_guard).with('test', [], {})
|
|
|
|
subject.evaluate_guardfile
|
|
|
|
end
|
|
|
|
|
|
|
|
it "receive watchers when specified" do
|
|
|
|
mock_guardfile_content("
|
|
|
|
guard 'test' do
|
|
|
|
watch('a') { 'b' }
|
|
|
|
watch('c')
|
|
|
|
end")
|
|
|
|
|
|
|
|
::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
|
2010-10-30 16:26:09 +00:00
|
|
|
end
|
|
|
|
subject.evaluate_guardfile
|
|
|
|
end
|
|
|
|
|
|
|
|
it "receive options when specified" do
|
2010-10-30 20:42:17 +00:00
|
|
|
mock_guardfile_content("guard 'test', :opt_a => 1, :opt_b => 'fancy'")
|
2010-10-30 16:26:09 +00:00
|
|
|
|
2010-10-30 20:42:17 +00:00
|
|
|
::Guard.should_receive(:add_guard).with('test', anything, { :opt_a => 1, :opt_b => 'fancy' })
|
2010-10-30 16:26:09 +00:00
|
|
|
subject.evaluate_guardfile
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
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
|
2010-10-30 20:42:17 +00:00
|
|
|
|
2010-10-30 16:26:09 +00:00
|
|
|
end
|