spec/rake/funnel/tasks/copy_spec.rb in rake-funnel-0.1.0.pre vs spec/rake/funnel/tasks/copy_spec.rb in rake-funnel-0.2.0.pre

- old
+ new

@@ -1,99 +1,44 @@ include Rake include Rake::Funnel::Support describe Rake::Funnel::Tasks::Copy do before { - CLEAN.clear Task.clear } describe 'defaults' do its(:name) { should == :copy } its(:source) { should eq([]) } its(:target) { should be_nil } - - it 'should not add the target file to the files to be cleaned' do - expect(CLEAN).to be_empty - end - - describe 'overriding defaults' do - subject { - described_class.new do |t| - t.target = 'something' - end - } - - it 'should add the target file to the files to be cleaned' do - expect(CLEAN).to include(subject.target) - end - end end describe 'execution' do - let(:source) { %w(bin/1 bin/2 bin/3/4 bin/directory/file bin/directory bin/directory-no-content) } - let(:target) { 'some path' } + let(:source) { %w(one two) } + let(:target) { 'target' } + let(:finder) { instance_double(Finder).as_null_object } - subject! { + before { + allow(finder).to receive(:all_or_default).and_return(source) + allow(Finder).to receive(:new).and_return(finder) + } + + before { + allow(Copier).to receive(:copy) + } + + subject { described_class.new do |t| t.source = source t.target = target end } - context 'failure' do - context 'target not defined' do - let(:target) { nil } + before { + Task[subject.name].invoke + } - it 'should fail' do - expect { Task[subject.name].invoke }.to raise_error(/Target not defined/) - end - end - end - - context 'success' do - let(:finder) { double(Finder).as_null_object } - - before { - allow(finder).to receive(:all_or_default).and_return(source) - allow(Finder).to receive(:new).and_return(finder) - - allow(File).to receive(:directory?).and_return(false) - source.last(2).each do |dir| - allow(File).to receive(:directory?).with(dir).and_return(true) - end - - allow(RakeFileUtils).to receive(:mkdir_p) - allow(RakeFileUtils).to receive(:cp) - } - - before { - Task[subject.name].invoke - } - - def no_prefix(file) - file.sub(%r|bin/|, '') - end - - it 'should create target directories' do - expect(RakeFileUtils).to have_received(:mkdir_p).with(subject.target + '/3') - expect(RakeFileUtils).to have_received(:mkdir_p).with(subject.target + '/directory') - end - - it 'should skip source directories' do - source - .select { |src| File.directory?(src) } - .each do |src| - expect(RakeFileUtils).not_to have_received(:cp).with(src, anything) - end - end - - it 'should copy files with common path removed' do - source - .select { |src| !File.directory?(src) } - .each do |src| - expect(RakeFileUtils).to have_received(:cp).with(src, File.join(subject.target, no_prefix(src)), { preserve: true }) - end - end + it 'should delegate to Copier' do + expect(Copier).to have_received(:copy).with(source, subject.target) end end end