Sha256: d88a0bc427687bdb1ba4f8deaab73330ca19aeaddcff26a947e3c0e4c7499082

Contents?: true

Size: 1.8 KB

Versions: 26

Compression:

Stored size: 1.8 KB

Contents

require File.join(File.dirname(File.expand_path(__FILE__)), "/../spec_helper.rb")

describe AutomateIt::TemplateManager::ERB do
  before(:all) do
    @a = AutomateIt.new(:verbosity => Logger::WARN)
    @m = @a.template_manager
    @d = @m[:erb]
    @d.setup(:default_check => :mtime)
    @d.available?.should be_true
  end

  before(:each) do
    @a.preview = false
  end

  it "should set file's mode when rendering" do
    @a.mktempdircd do
      source = "source"
      target = "target"
      mode1 = 0646 if INTERPRETER.shell_manager.provides_mode?
      mode2 = 0100646
      File.open(source, "w+"){|h| h.write("<%=variable%>")}

      opts = {:file => source, :to => target, :locals => {:variable => 42}}
      opts[:mode] = mode1 if mode1
      @a.render(opts).should be_true
      File.read(target).should == "42"
      if INTERPRETER.shell_manager.provides_mode?
        File.stat(target).mode.should == mode2
      else
        puts "NOTE: Can't check permission modes on this platform, #{__FILE__}"
      end
    end
  end

  it "should fail to render non-existent file" do
    @a.mktempdircd do
      lambda { @a.render(:file => "source", :to => "target") }.should raise_error(Errno::ENOENT)
    end
  end

  it "should not raise error with non-existent file in preview mode" do
    @a.mktempdircd do
      @a.preview = true
      @a.render(:file => "source", :to => "target").should be_true
    end
  end

  it "should not backup non-existing files" do
    @a.mktempdircd do
      @a.render(:text => "source", :to => "target").should be_true

      Dir.entries(".").grep(/\w/).size.should == 1
    end
  end

  it "should backup existing files" do
    @a.mktempdircd do
      @a.touch "target"
      @a.render(:text => "source", :to => "target").should be_true

      Dir.entries(".").grep(/\w/).size.should == 2
    end
  end
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
automate-it-0.9.2 spec/integration/template_manager_erb_spec.rb
automate-it-0.9.1 spec/integration/template_manager_erb_spec.rb
automate-it-0.9.0 spec/integration/template_manager_erb_spec.rb
automateit-0.71031.2 spec/integration/template_manager_erb_spec.rb
automateit-0.71017 spec/integration/template_manager_erb_spec.rb
automateit-0.71021 spec/integration/template_manager_erb_spec.rb
automateit-0.71031.1 spec/integration/template_manager_erb_spec.rb
automateit-0.71012 spec/integration/template_manager_erb_spec.rb
automateit-0.71030 spec/integration/template_manager_erb_spec.rb
automateit-0.71031 spec/integration/template_manager_erb_spec.rb
automateit-0.71101 spec/integration/template_manager_erb_spec.rb
automateit-0.71101.2 spec/integration/template_manager_erb_spec.rb
automateit-0.71103 spec/integration/template_manager_erb_spec.rb
automateit-0.71102 spec/integration/template_manager_erb_spec.rb
automateit-0.71101.1 spec/integration/template_manager_erb_spec.rb
automateit-0.71104 spec/integration/template_manager_erb_spec.rb
automateit-0.71112 spec/integration/template_manager_erb_spec.rb
automateit-0.71219 spec/integration/template_manager_erb_spec.rb
automateit-0.71220 spec/integration/template_manager_erb_spec.rb
automateit-0.71221 spec/integration/template_manager_erb_spec.rb