Added DSL specs and improved error message.
DSL now have basics specs that confirm it works I splitted file not found and invalid Guardfile error message because it was confusing to know in which case you are when it occurs :)
This commit is contained in:
parent
4da879e849
commit
dd1100b4ae
@ -3,11 +3,18 @@ module Guard
|
|||||||
|
|
||||||
def self.evaluate_guardfile
|
def self.evaluate_guardfile
|
||||||
guardfile = "#{Dir.pwd}/Guardfile"
|
guardfile = "#{Dir.pwd}/Guardfile"
|
||||||
dsl = new
|
if File.exists? guardfile
|
||||||
dsl.instance_eval(File.read(guardfile.to_s), guardfile.to_s, 1)
|
begin
|
||||||
rescue
|
dsl = new
|
||||||
UI.error "Guardfile not found or invalid"
|
dsl.instance_eval(File.read(guardfile.to_s), guardfile.to_s, 1)
|
||||||
exit 1
|
rescue
|
||||||
|
UI.error "Invalid Guardfile, original error is:\n#{$!}"
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
else
|
||||||
|
UI.error "No Guardfile in current folder, please create one."
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.guardfile_included?(guard_name)
|
def self.guardfile_included?(guard_name)
|
||||||
|
1
spec/fixtures/dsl/invalid_guardfile/Guardfile
vendored
Normal file
1
spec/fixtures/dsl/invalid_guardfile/Guardfile
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
Balasfllsd fsdadsg hsla kjsdh jakh kajlsh klsajhgs dklhj
|
1
spec/fixtures/dsl/options/Guardfile
vendored
Normal file
1
spec/fixtures/dsl/options/Guardfile
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
guard 'test', :opt_a => 1, :opt_b => 'test'
|
1
spec/fixtures/dsl/simple/Guardfile
vendored
Normal file
1
spec/fixtures/dsl/simple/Guardfile
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
guard 'test'
|
4
spec/fixtures/dsl/watchers/Guardfile
vendored
Normal file
4
spec/fixtures/dsl/watchers/Guardfile
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
guard 'test' do
|
||||||
|
watch('a') { 'b' }
|
||||||
|
watch('c')
|
||||||
|
end
|
55
spec/guard/dsl_spec.rb
Normal file
55
spec/guard/dsl_spec.rb
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
require 'guard/dsl'
|
||||||
|
|
||||||
|
describe Guard::Dsl do
|
||||||
|
subject {Guard::Dsl}
|
||||||
|
|
||||||
|
it "load a guard from the DSL" do
|
||||||
|
fixture :simple
|
||||||
|
|
||||||
|
::Guard.stub!(:add_guard)
|
||||||
|
::Guard.should_receive(:add_guard).with('test', [], {})
|
||||||
|
subject.evaluate_guardfile
|
||||||
|
end
|
||||||
|
|
||||||
|
it "write an error message when no Guardfile is found" do
|
||||||
|
fixture :no_guardfile
|
||||||
|
|
||||||
|
Guard::UI.stub!(:error)
|
||||||
|
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
|
||||||
|
fixture :invalid_guardfile
|
||||||
|
|
||||||
|
Guard::UI.stub!(:error)
|
||||||
|
Guard::UI.should_receive(:error).with(/Invalid Guardfile, original error is:\n/)
|
||||||
|
lambda { subject.evaluate_guardfile }.should raise_error
|
||||||
|
end
|
||||||
|
|
||||||
|
it "receive watchers when specified" do
|
||||||
|
fixture :watchers
|
||||||
|
|
||||||
|
::Guard.stub!(:add_guard)
|
||||||
|
::Guard.should_receive(:add_guard).with('test', anything(), {}) do |name, watchers, options|
|
||||||
|
watchers.size.should eql 2
|
||||||
|
end
|
||||||
|
subject.evaluate_guardfile
|
||||||
|
end
|
||||||
|
|
||||||
|
it "receive options when specified" do
|
||||||
|
fixture :options
|
||||||
|
|
||||||
|
::Guard.stub!(:add_guard)
|
||||||
|
::Guard.should_receive(:add_guard).with('test', anything(), hash_including(:opt_a, :opt_b))
|
||||||
|
subject.evaluate_guardfile
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def fixture name
|
||||||
|
## Hack to make guard look into the correct fixture folder
|
||||||
|
Dir.stub!(:pwd).and_return("#{@fixture_path}/dsl/#{name}")
|
||||||
|
Dir.pwd.should == "#{@fixture_path}/dsl/#{name}"
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user