Sha256: 6be8de8e70b95f806a8c9b5594ebd7ed393e796a3716a3140d7f104bdfc7ec7b

Contents?: true

Size: 1.63 KB

Versions: 18

Compression:

Stored size: 1.63 KB

Contents

require 'tmpdir'

include Rake
include Rake::Funnel::Support

describe Rake::Funnel::Tasks::QuickTemplate do
  before {
    Task.clear
  }

  describe 'defaults' do
    its(:name) { should == :template }
    its(:search_pattern) { should eq(%w(**/*.erb)) }
    its(:context) { should be_an_instance_of(Binding) }
  end

  describe 'execution' do
    let(:templates) { %w(1.template two/2.template) }

    let(:finder) { double(Finder).as_null_object }
    let(:engine) { TemplateEngine }

    before {
      allow(finder).to receive(:all_or_default).and_return(templates)
      allow(Finder).to receive(:new).and_return(finder)
      allow(engine).to receive(:render).and_return('file content')
      allow(Rake).to receive(:rake_output_message)
      allow(File).to receive(:read).and_return('template content')
      allow(File).to receive(:write)
    }

    subject! { described_class.new }

    before {
      Task[subject.name].invoke
    }

    it 'should report created files' do
      templates.each do |template|
        expect(Rake).to have_received(:rake_output_message).with("Creating file #{template.ext}")
      end
    end

    it 'should read all templates' do
      templates.each do |template|
        expect(File).to have_received(:read).with(template)
      end
    end

    it 'should render all templates' do
      templates.each do |template|
        expect(engine).to have_received(:render).with('template content', template, subject.context)
      end
    end

    it 'should write all files' do
      templates.each do |template|
        expect(File).to have_received(:write).with(template.ext, 'file content')
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
rake-funnel-0.18.0 spec/rake/funnel/tasks/quick_template_spec.rb
rake-funnel-0.17.0 spec/rake/funnel/tasks/quick_template_spec.rb
rake-funnel-0.16.1 spec/rake/funnel/tasks/quick_template_spec.rb
rake-funnel-0.16.0 spec/rake/funnel/tasks/quick_template_spec.rb
rake-funnel-0.15.0.pre spec/rake/funnel/tasks/quick_template_spec.rb
rake-funnel-0.14.0.pre spec/rake/funnel/tasks/quick_template_spec.rb
rake-funnel-0.13.0.pre spec/rake/funnel/tasks/quick_template_spec.rb
rake-funnel-0.12.0.pre spec/rake/funnel/tasks/quick_template_spec.rb
rake-funnel-0.11.0.pre spec/rake/funnel/tasks/quick_template_spec.rb
rake-funnel-0.10.0.pre spec/rake/funnel/tasks/quick_template_spec.rb
rake-funnel-0.9.1.pre spec/rake/funnel/tasks/quick_template_spec.rb
rake-funnel-0.9.0.pre spec/rake/funnel/tasks/quick_template_spec.rb
rake-funnel-0.8.0.pre spec/rake/funnel/tasks/quick_template_spec.rb
rake-funnel-0.7.0.pre spec/rake/funnel/tasks/quick_template_spec.rb
rake-funnel-0.6.1.pre spec/rake/funnel/tasks/quick_template_spec.rb
rake-funnel-0.6.0.pre spec/rake/funnel/tasks/quick_template_spec.rb
rake-funnel-0.5.0.pre spec/rake/funnel/tasks/quick_template_spec.rb
rake-funnel-0.4.0.pre spec/rake/funnel/tasks/quick_template_spec.rb