diff --git a/spec/fixtures/dsl/invalid_guardfile/Guardfile b/spec/fixtures/dsl/invalid_guardfile/Guardfile deleted file mode 100644 index 954a2fe..0000000 --- a/spec/fixtures/dsl/invalid_guardfile/Guardfile +++ /dev/null @@ -1 +0,0 @@ -Balasfllsd fsdadsg hsla kjsdh jakh kajlsh klsajhgs dklhj \ No newline at end of file diff --git a/spec/fixtures/dsl/options/Guardfile b/spec/fixtures/dsl/options/Guardfile deleted file mode 100644 index d87a0f6..0000000 --- a/spec/fixtures/dsl/options/Guardfile +++ /dev/null @@ -1 +0,0 @@ -guard 'test', :opt_a => 1, :opt_b => 'test' \ No newline at end of file diff --git a/spec/fixtures/dsl/simple/Guardfile b/spec/fixtures/dsl/simple/Guardfile deleted file mode 100644 index ed2fd58..0000000 --- a/spec/fixtures/dsl/simple/Guardfile +++ /dev/null @@ -1 +0,0 @@ -guard 'test' \ No newline at end of file diff --git a/spec/fixtures/dsl/watchers/Guardfile b/spec/fixtures/dsl/watchers/Guardfile deleted file mode 100644 index 6127008..0000000 --- a/spec/fixtures/dsl/watchers/Guardfile +++ /dev/null @@ -1,4 +0,0 @@ -guard 'test' do - watch('a') { 'b' } - watch('c') -end \ No newline at end of file diff --git a/spec/guard/dsl_spec.rb b/spec/guard/dsl_spec.rb index 3564f0f..d8e16e1 100644 --- a/spec/guard/dsl_spec.rb +++ b/spec/guard/dsl_spec.rb @@ -2,54 +2,61 @@ require 'spec_helper' require 'guard/dsl' describe Guard::Dsl do - subject {Guard::Dsl} + subject { Guard::Dsl } - it "load a guard from the DSL" do - fixture :simple - + before(:each) do ::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 + Dir.stub!(:pwd).and_return("no_guardfile_here") - 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) + mock_guardfile_content("This Guardfile is invalid!") + 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 + it "load a guard from the DSL" do + mock_guardfile_content("guard 'test'") - ::Guard.stub!(:add_guard) - ::Guard.should_receive(:add_guard).with('test', anything(), {}) do |name, watchers, options| - watchers.size.should eql 2 + ::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 end subject.evaluate_guardfile end it "receive options when specified" do - fixture :options + mock_guardfile_content("guard 'test', :opt_a => 1, :opt_b => 'fancy'") - ::Guard.stub!(:add_guard) - ::Guard.should_receive(:add_guard).with('test', anything(), hash_including(:opt_a, :opt_b)) + ::Guard.should_receive(:add_guard).with('test', anything, { :opt_a => 1, :opt_b => 'fancy' }) 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}" + + def mock_guardfile_content(content) + File.stub!(:read).with(File.expand_path('../../../Guardfile', __FILE__)) { content } end + end