rip out erb processing and unnecessary specs
This commit is contained in:
parent
dacc9d9334
commit
50e8222254
18
Rakefile
18
Rakefile
@ -1,22 +1,6 @@
|
||||
require 'bundler'
|
||||
Bundler::GemHelper.install_tasks
|
||||
|
||||
begin
|
||||
require 'rspec/core/rake_task'
|
||||
|
||||
RSpec::Core::RakeTask.new(:spec)
|
||||
rescue LoadError
|
||||
"#$! - no rspec"
|
||||
end
|
||||
|
||||
begin
|
||||
require 'rspec/core/rake_task'
|
||||
|
||||
RSpec::Core::RakeTask.new(:spec)
|
||||
rescue LoadError
|
||||
"#$! - no rspec"
|
||||
end
|
||||
|
||||
begin
|
||||
require 'cucumber'
|
||||
require 'cucumber/rake/task'
|
||||
@ -28,5 +12,5 @@ rescue LoadError
|
||||
"#$! - no cucumber"
|
||||
end
|
||||
|
||||
task :default => [ :spec, :cucumber ]
|
||||
task :default => [ :cucumber ]
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
Feature: CLI
|
||||
Scenario: Switch back to the original pre-deployment environment
|
||||
Given I have the file "tmp/Gemfile.erb" with the content:
|
||||
Given I have the file "tmp/Gemfile.penchant" with the content:
|
||||
"""
|
||||
gem 'rake'
|
||||
"""
|
||||
@ -12,7 +12,7 @@ Feature: CLI
|
||||
Then the file "tmp/Gemfile" should have the following content:
|
||||
"""
|
||||
# generated by penchant, environment: local
|
||||
gem 'rake'
|
||||
gem "rake"
|
||||
"""
|
||||
And the output should include "fallback: other"
|
||||
|
||||
|
@ -1,123 +0,0 @@
|
||||
@fakefs
|
||||
Feature: Gemfiles
|
||||
Scenario: When rebuilding for deployment, save the original state
|
||||
Given I have the file "Gemfile.erb" with the content:
|
||||
"""
|
||||
this is content
|
||||
"""
|
||||
And I have the file "Gemfile" with the content:
|
||||
"""
|
||||
# generated by penchant, environment: local
|
||||
"""
|
||||
When I rebuild the Gemfile for "production" mode with deployment
|
||||
Then the file "Gemfile" should have the following content:
|
||||
"""
|
||||
# generated by penchant, environment: production, deployment mode (was local)
|
||||
this is content
|
||||
"""
|
||||
|
||||
Scenario: When unbundling from deployment with an original state, switch to that state
|
||||
Given I have the file "Gemfile.erb" with the content:
|
||||
"""
|
||||
this is content
|
||||
"""
|
||||
And I have the file "Gemfile" with the content:
|
||||
"""
|
||||
# generated by penchant, environment: production, deployment mode (was local)
|
||||
"""
|
||||
When I rebuild the Gemfile asking to switch back to the previous state
|
||||
Then the file "Gemfile" should have the following content:
|
||||
"""
|
||||
# generated by penchant, environment: local
|
||||
this is content
|
||||
"""
|
||||
|
||||
Scenario: Simple env
|
||||
Given I have the file "Gemfile.erb" with the content:
|
||||
"""
|
||||
gem 'test'
|
||||
<% env :local do %>
|
||||
gem 'test'
|
||||
<% end %>
|
||||
"""
|
||||
When I rebuild the Gemfile for "local" mode
|
||||
Then the file "Gemfile" should have the following stripped content:
|
||||
"""
|
||||
# generated by penchant, environment: local
|
||||
gem 'test'
|
||||
gem 'test'
|
||||
"""
|
||||
|
||||
Scenario: Use placeholder expansion
|
||||
Given I have the file "Gemfile.erb" with the content:
|
||||
"""
|
||||
<% env :local, :path => '../%s' do %>
|
||||
gem 'test'
|
||||
<% end %>
|
||||
"""
|
||||
When I rebuild the Gemfile for "local" mode
|
||||
|
||||
Then the file "Gemfile" should have the following stripped content:
|
||||
"""
|
||||
# generated by penchant, environment: local
|
||||
gem 'test', {:path=>"../test"}
|
||||
"""
|
||||
|
||||
Scenario: Use a gem list for an operation
|
||||
Given I have the file "Gemfile.erb" with the content:
|
||||
"""
|
||||
<% gems 'test' do %>
|
||||
<% env :local, :path => '../%s' do %>
|
||||
<%= gem %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
"""
|
||||
When I rebuild the Gemfile for "local" mode
|
||||
Then the file "Gemfile" should have the following stripped content:
|
||||
"""
|
||||
# generated by penchant, environment: local
|
||||
gem 'test', {:path=>"../test"}
|
||||
"""
|
||||
|
||||
Scenario: Let gem get additional info
|
||||
Given I have the file "Gemfile.erb" with the content:
|
||||
"""
|
||||
<% gems 'test' do %>
|
||||
<%= gem :path => '../%s' %>
|
||||
<% end %>
|
||||
"""
|
||||
When I rebuild the Gemfile for "local" mode
|
||||
Then the file "Gemfile" should have the following content:
|
||||
"""
|
||||
# generated by penchant, environment: local
|
||||
|
||||
gem 'test', {:path=>"../test"}
|
||||
|
||||
"""
|
||||
|
||||
Scenario: Use a gem list without a block
|
||||
Given I have the file "Gemfile.erb" with the content:
|
||||
"""
|
||||
<% gems 'test', :path => '../%s' %>
|
||||
"""
|
||||
When I rebuild the Gemfile for "local" mode
|
||||
Then the file "Gemfile" should have the following content:
|
||||
"""
|
||||
# generated by penchant, environment: local
|
||||
gem 'test', {:path=>"../test"}
|
||||
|
||||
"""
|
||||
|
||||
Scenario: Use a gem list with an array
|
||||
Given I have the file "Gemfile.erb" with the content:
|
||||
"""
|
||||
<% gems [ 'test' ], :path => '../%s' %>
|
||||
"""
|
||||
When I rebuild the Gemfile for "local" mode
|
||||
Then the file "Gemfile" should have the following content:
|
||||
"""
|
||||
# generated by penchant, environment: local
|
||||
gem 'test', {:path=>"../test"}
|
||||
|
||||
"""
|
||||
|
@ -292,60 +292,6 @@ module Penchant
|
||||
end
|
||||
end
|
||||
|
||||
class ERBFile < FileProcessor
|
||||
def handle_result(data)
|
||||
$stderr.puts "ERB files are deprecated. Please convert them to the Ruby format."
|
||||
|
||||
@output << ERB.new(data, nil, nil, '@_erbout').result(binding)
|
||||
end
|
||||
|
||||
def env(check, template = {}, &block)
|
||||
if check.to_s == @environment.to_s
|
||||
original_erbout = @_erbout.dup
|
||||
@_erbout = ''
|
||||
|
||||
output = instance_eval(&block).lines.to_a
|
||||
|
||||
output.each do |line|
|
||||
if gem_name = line[%r{gem ['"]([^'"]+)['"]}, 1]
|
||||
new_line = line.rstrip
|
||||
|
||||
if !(options = process_options(gem_name, template)).empty?
|
||||
new_line += ", #{options.inspect}"
|
||||
end
|
||||
|
||||
line.replace(new_line + "\n")
|
||||
end
|
||||
end
|
||||
|
||||
@_erbout = original_erbout + output.join
|
||||
end
|
||||
end
|
||||
|
||||
def gems(*gems)
|
||||
template = {}
|
||||
template = gems.pop if gems.last.instance_of?(Hash)
|
||||
|
||||
gems.flatten.each do |gem|
|
||||
@_current_gem = gem
|
||||
if block_given?
|
||||
yield
|
||||
else
|
||||
@_erbout += gem(template) + "\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def gem(template = {})
|
||||
output = "gem '#{@_current_gem}'"
|
||||
options = process_options(@_current_gem, template)
|
||||
if !options.empty?
|
||||
output += ", #{options.inspect}"
|
||||
end
|
||||
output
|
||||
end
|
||||
end
|
||||
|
||||
class PenchantFile < FileProcessor
|
||||
def handle_result(data)
|
||||
instance_eval(data)
|
||||
@ -456,16 +402,7 @@ module Penchant
|
||||
end
|
||||
|
||||
def builder
|
||||
return @builder if @builder
|
||||
|
||||
klass = case File.extname(processable_gemfile_path)
|
||||
when '.penchant'
|
||||
PenchantFile
|
||||
when '.erb'
|
||||
ERBFile
|
||||
end
|
||||
|
||||
@builder = klass.new(template)
|
||||
@builder ||= PenchantFile.new(template)
|
||||
end
|
||||
|
||||
def template
|
||||
|
@ -1,45 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Penchant::DotPenchant do
|
||||
include FakeFS::SpecHelpers
|
||||
|
||||
describe '.run' do
|
||||
before do
|
||||
File.open('.penchant', 'wb') { |fh|
|
||||
fh.puts "@did_run = env"
|
||||
}
|
||||
end
|
||||
|
||||
it 'should run the file in the environment' do
|
||||
dot_file = Penchant::DotPenchant.run(:this)
|
||||
|
||||
dot_file.instance_variable_get(:@did_run).should == :this
|
||||
end
|
||||
end
|
||||
|
||||
let(:dot_file) { described_class.new }
|
||||
|
||||
describe '#rake' do
|
||||
context 'without Gemfile' do
|
||||
before do
|
||||
Kernel.expects(:system).with('rake task1 task2')
|
||||
end
|
||||
|
||||
it 'should run the rake task via system' do
|
||||
dot_file.rake("task1", "task2")
|
||||
end
|
||||
end
|
||||
|
||||
context 'with Gemfile' do
|
||||
before do
|
||||
File.open('Gemfile', 'wb')
|
||||
Kernel.expects(:system).with('bundle exec rake task1 task2')
|
||||
end
|
||||
|
||||
it 'should run the rake task via system' do
|
||||
dot_file.rake("task1", "task2")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,296 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Penchant::Gemfile do
|
||||
include FakeFS::SpecHelpers
|
||||
|
||||
let(:dir) { File.expand_path(Dir.pwd) }
|
||||
let(:gemfile) { described_class.new(dir) }
|
||||
|
||||
let(:gemfile_path) { File.join(dir, 'Gemfile') }
|
||||
let(:gemfile_erb_path) { File.join(dir, 'Gemfile.erb') }
|
||||
|
||||
def write_file(path, content = nil)
|
||||
FileUtils.mkdir_p(File.dirname(path))
|
||||
|
||||
File.open(path, 'wb') do |fh|
|
||||
content = yield if block_given?
|
||||
fh.print content
|
||||
end
|
||||
end
|
||||
|
||||
subject { gemfile }
|
||||
|
||||
context 'with no gemfile' do
|
||||
it { should_not have_gemfile }
|
||||
it { should_not have_gemfile_erb }
|
||||
end
|
||||
|
||||
context 'with gemfile' do
|
||||
let(:data) { "whatever" }
|
||||
|
||||
before do
|
||||
write_file(gemfile_path) { data }
|
||||
end
|
||||
|
||||
describe 'existence' do
|
||||
it { should have_gemfile }
|
||||
it { should_not have_gemfile_erb }
|
||||
end
|
||||
|
||||
describe '#environment' do
|
||||
context 'not defined' do
|
||||
its(:environment) { should be_nil }
|
||||
end
|
||||
|
||||
context 'defined' do
|
||||
let(:environment) { 'test' }
|
||||
let(:data) { <<-GEMFILE }
|
||||
# generated by penchant, environment: #{environment}
|
||||
GEMFILE
|
||||
|
||||
its(:environment) { should == environment }
|
||||
it { should_not be_deployment }
|
||||
end
|
||||
|
||||
context 'deployment' do
|
||||
let(:environment) { 'test' }
|
||||
let(:data) { <<-GEMFILE }
|
||||
# generated by penchant, environment: #{environment}, deployment mode
|
||||
GEMFILE
|
||||
|
||||
its(:environment) { should == environment }
|
||||
it { should be_deployment }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#switch_to!' do
|
||||
it 'should raise an exception' do
|
||||
expect { subject.switch_to!(:whatever) }.to raise_error(Errno::ENOENT)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with gemfile.erb' do
|
||||
let(:erb_data) { 'whatever' }
|
||||
|
||||
before do
|
||||
write_file(gemfile_erb_path) { erb_data }
|
||||
end
|
||||
|
||||
it { should_not have_gemfile }
|
||||
it { should have_gemfile_erb }
|
||||
|
||||
describe '#switch_to!' do
|
||||
let(:erb_data) { <<-ERB }
|
||||
<% env :test do %>
|
||||
test
|
||||
<% end %>
|
||||
|
||||
<% env :not do %>
|
||||
not
|
||||
<% end %>
|
||||
|
||||
<% no_deployment do %>
|
||||
diddeploy
|
||||
<% end %>
|
||||
|
||||
all
|
||||
ERB
|
||||
|
||||
it 'should render test data' do
|
||||
subject.switch_to!(:test)
|
||||
|
||||
File.read('Gemfile').should include('test')
|
||||
File.read('Gemfile').should include('diddeploy')
|
||||
File.read('Gemfile').should_not include('not')
|
||||
File.read('Gemfile').should include('all')
|
||||
end
|
||||
|
||||
it 'should not render test data' do
|
||||
subject.switch_to!(:not)
|
||||
|
||||
File.read('Gemfile').should_not include('test')
|
||||
File.read('Gemfile').should include('diddeploy')
|
||||
File.read('Gemfile').should include('not')
|
||||
File.read('Gemfile').should include('all')
|
||||
end
|
||||
|
||||
it 'should not render either' do
|
||||
subject.switch_to!
|
||||
|
||||
File.read('Gemfile').should_not include('test')
|
||||
File.read('Gemfile').should_not include('not')
|
||||
File.read('Gemfile').should include('diddeploy')
|
||||
File.read('Gemfile').should include('all')
|
||||
end
|
||||
|
||||
it 'should skip no_deployment sections' do
|
||||
subject.switch_to!(nil, true)
|
||||
|
||||
File.read('Gemfile').should_not include('test')
|
||||
File.read('Gemfile').should_not include('not')
|
||||
File.read('Gemfile').should_not include('diddeploy')
|
||||
File.read('Gemfile').should include('all')
|
||||
end
|
||||
|
||||
it { should_not have_dot_penchant }
|
||||
|
||||
context 'with .penchant' do
|
||||
before do
|
||||
File.open('.penchant', 'wb')
|
||||
end
|
||||
|
||||
it { should have_dot_penchant }
|
||||
|
||||
it 'should process the file' do
|
||||
subject.switch_to!(:not)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#switch_to!' do
|
||||
let(:template) { 'source' }
|
||||
let(:gemfile_path) { 'gemfile path' }
|
||||
let(:header) { 'header' }
|
||||
|
||||
let(:gemfile_out) { File.read(gemfile_path) }
|
||||
|
||||
before do
|
||||
gemfile.stubs(:template).returns(template)
|
||||
gemfile.stubs(:gemfile_path).returns(gemfile_path)
|
||||
|
||||
gemfile.expects(:header).returns(header)
|
||||
end
|
||||
|
||||
it 'should write out the new gemfile' do
|
||||
gemfile.switch_to!
|
||||
|
||||
gemfile_out.should include(template)
|
||||
gemfile_out.should include(header)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#header' do
|
||||
subject { gemfile.header }
|
||||
|
||||
let(:env) { 'env' }
|
||||
let(:prior_environment) { 'prior' }
|
||||
|
||||
before do
|
||||
gemfile.stubs(:current_env).returns(env)
|
||||
gemfile.stubs(:environment).returns(prior_environment)
|
||||
end
|
||||
|
||||
context 'not deployment' do
|
||||
before do
|
||||
gemfile.stubs(:is_deployment).returns(false)
|
||||
end
|
||||
|
||||
it { should == "# generated by penchant, environment: #{env}" }
|
||||
end
|
||||
|
||||
context 'deployment' do
|
||||
before do
|
||||
gemfile.stubs(:is_deployment).returns(true)
|
||||
end
|
||||
|
||||
it { should == "# generated by penchant, environment: #{env}, deployment mode (was #{prior_environment})" }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#prior_environment' do
|
||||
subject { gemfile.prior_environment }
|
||||
|
||||
let(:prior) { 'prior' }
|
||||
|
||||
before do
|
||||
gemfile.stubs(:gemfile_header).returns("# header (was #{prior})")
|
||||
end
|
||||
|
||||
it { should == prior }
|
||||
end
|
||||
|
||||
describe '.switch_back!' do
|
||||
let(:gemfile) { stub }
|
||||
let(:fallback_env) { 'env' }
|
||||
|
||||
context 'pre_switch fails' do
|
||||
before do
|
||||
described_class.stubs(:pre_switch).returns(false)
|
||||
|
||||
gemfile.expects(:switch_back!).never
|
||||
end
|
||||
|
||||
it 'should not switch back' do
|
||||
described_class.switch_back!(fallback_env).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
context 'pre_switch succeeds' do
|
||||
before do
|
||||
described_class.stubs(:pre_switch).returns(gemfile)
|
||||
|
||||
gemfile.expects(:switch_back!).with(fallback_env)
|
||||
end
|
||||
|
||||
it 'should switch back' do
|
||||
described_class.switch_back!(fallback_env)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.pre_switch' do
|
||||
subject { described_class.pre_switch(env, deployment) }
|
||||
|
||||
let(:env) { 'env' }
|
||||
let(:deployment) { 'deployment' }
|
||||
|
||||
context 'no Gemfile.erb' do
|
||||
before do
|
||||
described_class.any_instance.expects(:has_gemfile_erb?).returns(false)
|
||||
end
|
||||
|
||||
it { should be_false }
|
||||
end
|
||||
|
||||
context 'Gemfile.erb' do
|
||||
before do
|
||||
described_class.any_instance.expects(:has_gemfile_erb?).returns(true)
|
||||
described_class.any_instance.expects(:run_dot_penchant!).with(env, deployment)
|
||||
end
|
||||
|
||||
it { should be_a_kind_of(described_class) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#switch_back!' do
|
||||
let(:fallback_env) { 'fallback' }
|
||||
let(:prior) { 'prior' }
|
||||
|
||||
context 'no prior' do
|
||||
before do
|
||||
gemfile.stubs(:prior_environment).returns(nil)
|
||||
|
||||
gemfile.expects(:switch_to!).with(fallback_env)
|
||||
end
|
||||
|
||||
it 'should proxy through to switch_to!' do
|
||||
gemfile.switch_back!(fallback_env)
|
||||
end
|
||||
end
|
||||
|
||||
context 'prior' do
|
||||
before do
|
||||
gemfile.stubs(:prior_environment).returns(prior)
|
||||
|
||||
gemfile.expects(:switch_to!).with(prior)
|
||||
end
|
||||
|
||||
it 'should proxy through to switch_to!' do
|
||||
gemfile.switch_back!(fallback_env)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +0,0 @@
|
||||
require 'fakefs/spec_helpers'
|
||||
require 'penchant'
|
||||
|
||||
RSpec.configure do |c|
|
||||
c.mock_with :mocha
|
||||
end
|
Loading…
Reference in New Issue
Block a user