Sha256: 35b1ce60f32d2ec6179e146a2a63e13e5f7b5af332ee10ac419e569386226bf8

Contents?: true

Size: 1.69 KB

Versions: 13

Compression:

Stored size: 1.69 KB

Contents

require 'spec_helper'

describe ArchitectureJS::Generator do

  before :each do
    FileUtils.mkdir TMP_DIR
    FileUtils.mkdir "#{TMP_DIR}/templates"
    FileUtils.cp "#{FIXTURES}/templates/test_template_one.js", "#{TMP_DIR}/test_template_one.js"
    FileUtils.cp "#{FIXTURES}/templates/test_template_two.js", "#{TMP_DIR}/test_template_two.js"
    project = ArchitectureJS::Project.new({ name: 'myapp' }, TMP_DIR)
    project.template_directories = ["#{FIXTURES}/templates"]
    @gen = ArchitectureJS::Generator.new(project)
  end

  after :each do
    FileUtils.rm_rf TMP_DIR if File.exists? TMP_DIR
  end

  it 'should have a project' do
    @gen.project.class.should == ArchitectureJS::Project
  end

  it 'should have template_paths' do
    @gen.template_paths.should == ["#{FIXTURES}/templates"]
  end

  it 'should find all the templates' do
    @gen.templates['test_template_one'].should_not be_nil
    @gen.templates['test_template_two'].should_not be_nil
  end

  it 'should render a template' do
    @gen.render_template('test_template_one').should == File.open("#{FIXTURES}/templates/test_template_one.js").read
    @gen.render_template('test_template_two').should == File.open("#{FIXTURES}/test_template_two.js").read
  end

  it 'should render a template with options' do
    @gen.render_template('test_template_two', optional_variable: 'true').should == File.open("#{FIXTURES}/test_template_options.js").read
  end

  it 'should generate a file from a template' do
    @gen.generate_file("test.js", @gen.render_template("test_template_two"), TMP_DIR)
    File.exists?("#{TMP_DIR}/test.js").should be_true
    File.open("#{TMP_DIR}/test.js").read.should == File.open("#{FIXTURES}/test_template_two.js").read
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
architecture-js-0.1.16 spec/generator_spec.rb
architecture-js-0.1.15 spec/generator_spec.rb
architecture-js-0.1.14 spec/generator_spec.rb
architecture-js-0.1.13 spec/generator_spec.rb
architecture-js-0.1.12 spec/generator_spec.rb
architecture-js-0.1.11 spec/generator_spec.rb
architecture-js-0.1.10 spec/generator_spec.rb
architecture-js-0.1.9 spec/generator_spec.rb
architecture-js-0.1.8 spec/generator_spec.rb
architecture-js-0.1.7 spec/generator_spec.rb
architecture-js-0.1.6 spec/generator_spec.rb
architecture-js-0.1.5 spec/generator_spec.rb
architecture-js-0.1.4 spec/generator_spec.rb