Add missing specs for Guard implementation base class
This commit is contained in:
parent
1c6ce380ea
commit
1845efb11e
@ -55,12 +55,14 @@ module Guard
|
||||
else
|
||||
content = File.read('Guardfile')
|
||||
guard = File.read("#{ ::Guard.locate_guard(name) }/lib/guard/#{ name }/templates/Guardfile")
|
||||
|
||||
File.open('Guardfile', 'wb') do |f|
|
||||
f.puts(content)
|
||||
f.puts("")
|
||||
f.puts(guard)
|
||||
end
|
||||
::Guard::UI.info "#{name} guard added to Guardfile, feel free to edit it"
|
||||
|
||||
::Guard::UI.info "#{ name } guard added to Guardfile, feel free to edit it"
|
||||
end
|
||||
end
|
||||
|
||||
|
60
spec/guard/guard_spec.rb
Normal file
60
spec/guard/guard_spec.rb
Normal file
@ -0,0 +1,60 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Guard::Guard do
|
||||
|
||||
describe '#initialize' do
|
||||
|
||||
it 'assigns the defined watchers' do
|
||||
watchers = [ Guard::Watcher.new('*') ]
|
||||
guard = Guard::Guard.new(watchers)
|
||||
guard.watchers.should eql watchers
|
||||
end
|
||||
|
||||
it 'assigns the defined options' do
|
||||
options = { :a => 1, :b => 2 }
|
||||
guard = Guard::Guard.new([], options)
|
||||
guard.options.should eql options
|
||||
end
|
||||
|
||||
context 'with a group in the options' do
|
||||
it 'assigns the given group' do
|
||||
options = { :group => :test }
|
||||
guard = Guard::Guard.new([], options)
|
||||
guard.group.should eql :test
|
||||
end
|
||||
end
|
||||
|
||||
context 'without a group in the options' do
|
||||
it 'assigns a default group' do
|
||||
options = { }
|
||||
guard = Guard::Guard.new([], options)
|
||||
guard.group.should eql :default
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#init' do
|
||||
context 'when the Guard is already in the Guardfile' do
|
||||
before { ::Guard::Dsl.stub(:guardfile_include?).and_return true }
|
||||
|
||||
it 'shows an info message' do
|
||||
::Guard::UI.should_receive(:info).with 'Guardfile already includes myguard guard'
|
||||
Guard::Guard.init('myguard')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the Guard is not in the Guardfile' do
|
||||
before { ::Guard::Dsl.stub(:guardfile_include?).and_return false }
|
||||
|
||||
it 'appends the template to the Guardfile' do
|
||||
File.should_receive(:read).with('Guardfile').and_return 'Guardfile content'
|
||||
::Guard.should_receive(:locate_guard).with('myguard').and_return '/Users/me/projects/guard-myguard'
|
||||
File.should_receive(:read).with('/Users/me/projects/guard-myguard/lib/guard/myguard/templates/Guardfile').and_return('Template content')
|
||||
io = StringIO.new
|
||||
File.should_receive(:open).with('Guardfile', 'wb').and_yield io
|
||||
Guard::Guard.init('myguard')
|
||||
io.string.should eql "Guardfile content\n\nTemplate content\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user