Sha256: 1eedf27e897e3b0dc4ec5475f00cd4d3d106cd853271e7f692580ec27dc56106

Contents?: true

Size: 1.73 KB

Versions: 2

Compression:

Stored size: 1.73 KB

Contents

require 'tempfile'
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe Scaffoldhub::TemplateFile do

  before do
    @status_proc = mock
    @status_proc.stubs(:call)
  end

  describe 'local template file' do

    subject { Scaffoldhub::TemplateFile.new('templates/index.html', 'public', true, File.expand_path(File.dirname(__FILE__)), @status_proc) }

    its(:src)  { should == File.expand_path(File.join(File.dirname(__FILE__), 'templates', 'index.html')) }
    its(:url)  { should == File.expand_path(File.join(File.dirname(__FILE__), 'templates', 'index.html')) }
    its(:dest) { should == File.join('public', 'index.html') }
  end

  describe 'remote template file' do

    FAKE_TEMPLATE_FILE_URL = 'http://github.com/patshaughnessy/scaffolds/default'

    subject { Scaffoldhub::TemplateFile.new('templates/index.html', 'public', false, FAKE_TEMPLATE_FILE_URL, @status_proc) }

    its(:url)  { should == FAKE_TEMPLATE_FILE_URL + '/templates/index.html' }
    its(:dest) { should == File.join('public', 'index.html') }

    describe '#download!' do

      before do
        @local_path = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'local_template_file.txt'))
        File.delete(@local_path) if File.exists?(@local_path)
        subject.stubs(:remote_file_contents!).returns('TEMPLATE')
        tempfile = mock
        Tempfile.stubs(:new).returns(tempfile)
        tempfile.stubs(:path).returns(@local_path)
        subject.download!
      end

      it 'should set the src to the local path after a download' do
        subject.src.should == @local_path
      end

      it 'should write the template file contents into a local file' do
        File.new(@local_path).read.should == 'TEMPLATE'
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
scaffoldhub-0.0.7 spec/template_file_spec.rb
scaffoldhub-0.0.6 spec/template_file_spec.rb