Sha256: 7d8848ce0233ef6764dc10172453db479f5f7230abcc07a664a27ed4455a9af2

Contents?: true

Size: 1.71 KB

Versions: 3

Compression:

Stored size: 1.71 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_GITHUB_URL = 'http://github.com/patshaughnessy/scaffolds/default'

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

    its(:url)  { should == FAKE_GITHUB_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

3 entries across 3 versions & 1 rubygems

Version Path
scaffoldhub-0.0.4 spec/template_file_spec.rb
scaffoldhub-0.0.3 spec/template_file_spec.rb
scaffoldhub-0.0.2 spec/template_file_spec.rb