Avoid using actual fixture files, instead mock Guardfile content (this way we can directly see tested Guardfile content in the specs.

This commit is contained in:
Rémy Coutable 2010-10-30 22:42:17 +02:00
parent dd1100b4ae
commit 39ea8441c0
5 changed files with 30 additions and 30 deletions

View File

@ -1 +0,0 @@
Balasfllsd fsdadsg hsla kjsdh jakh kajlsh klsajhgs dklhj

View File

@ -1 +0,0 @@
guard 'test', :opt_a => 1, :opt_b => 'test'

View File

@ -1 +0,0 @@
guard 'test'

View File

@ -1,4 +0,0 @@
guard 'test' do
watch('a') { 'b' }
watch('c')
end

View File

@ -2,54 +2,61 @@ require 'spec_helper'
require 'guard/dsl' require 'guard/dsl'
describe Guard::Dsl do describe Guard::Dsl do
subject {Guard::Dsl} subject { Guard::Dsl }
it "load a guard from the DSL" do before(:each) do
fixture :simple
::Guard.stub!(:add_guard) ::Guard.stub!(:add_guard)
::Guard.should_receive(:add_guard).with('test', [], {})
subject.evaluate_guardfile
end end
it "write an error message when no Guardfile is found" do 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.") Guard::UI.should_receive(:error).with("No Guardfile in current folder, please create one.")
lambda { subject.evaluate_guardfile }.should raise_error lambda { subject.evaluate_guardfile }.should raise_error
end end
it "write an error message when Guardfile is not valid" do it "write an error message when Guardfile is not valid" do
fixture :invalid_guardfile mock_guardfile_content("This Guardfile is invalid!")
Guard::UI.stub!(:error)
Guard::UI.should_receive(:error).with(/Invalid Guardfile, original error is:\n/) Guard::UI.should_receive(:error).with(/Invalid Guardfile, original error is:\n/)
lambda { subject.evaluate_guardfile }.should raise_error lambda { subject.evaluate_guardfile }.should raise_error
end end
it "receive watchers when specified" do it "load a guard from the DSL" do
fixture :watchers mock_guardfile_content("guard 'test'")
::Guard.stub!(:add_guard) ::Guard.should_receive(:add_guard).with('test', [], {})
::Guard.should_receive(:add_guard).with('test', anything(), {}) do |name, watchers, options| subject.evaluate_guardfile
watchers.size.should eql 2 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 end
subject.evaluate_guardfile subject.evaluate_guardfile
end end
it "receive options when specified" do 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, { :opt_a => 1, :opt_b => 'fancy' })
::Guard.should_receive(:add_guard).with('test', anything(), hash_including(:opt_a, :opt_b))
subject.evaluate_guardfile subject.evaluate_guardfile
end end
private private
def fixture name
## Hack to make guard look into the correct fixture folder def mock_guardfile_content(content)
Dir.stub!(:pwd).and_return("#{@fixture_path}/dsl/#{name}") File.stub!(:read).with(File.expand_path('../../../Guardfile', __FILE__)) { content }
Dir.pwd.should == "#{@fixture_path}/dsl/#{name}"
end end
end end