Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Dsl spec #13

Merged
1 commit merged into from

1 participant

@oliamb

No description provided.

@oliamb oliamb 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 :)
dd1100b
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 30, 2010
  1. @oliamb

    Added DSL specs and improved error message.

    oliamb authored
    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 page is out of date. Refresh to see the latest.
View
17 lib/guard/dsl.rb
@@ -3,11 +3,18 @@ class Dsl
def self.evaluate_guardfile
guardfile = "#{Dir.pwd}/Guardfile"
- dsl = new
- dsl.instance_eval(File.read(guardfile.to_s), guardfile.to_s, 1)
- rescue
- UI.error "Guardfile not found or invalid"
- exit 1
+ if File.exists? guardfile
+ begin
+ dsl = new
+ dsl.instance_eval(File.read(guardfile.to_s), guardfile.to_s, 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
def self.guardfile_included?(guard_name)
View
1  spec/fixtures/dsl/invalid_guardfile/Guardfile
@@ -0,0 +1 @@
+Balasfllsd fsdadsg hsla kjsdh jakh kajlsh klsajhgs dklhj
View
1  spec/fixtures/dsl/options/Guardfile
@@ -0,0 +1 @@
+guard 'test', :opt_a => 1, :opt_b => 'test'
View
1  spec/fixtures/dsl/simple/Guardfile
@@ -0,0 +1 @@
+guard 'test'
View
4 spec/fixtures/dsl/watchers/Guardfile
@@ -0,0 +1,4 @@
+guard 'test' do
+ watch('a') { 'b' }
+ watch('c')
+end
View
55 spec/guard/dsl_spec.rb
@@ -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
Something went wrong with that request. Please try again.