a new way to manage lists of gems with commoon things

This commit is contained in:
John Bintz 2012-06-04 15:39:22 -04:00
parent 9e0bfa722e
commit c858dcdd69
8 changed files with 110 additions and 7 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
.bundle
Gemfile.lock
pkg/*
.DS_Store

View File

@ -13,3 +13,4 @@ gem 'rspec', '~> 2.6.0'
gem 'rake'
gem 'cucumber'
gem 'cuke-pack', :path => '../cuke-pack'

View File

@ -9,10 +9,13 @@ group :rspec do
end
end
group :cucumber do
guard 'cucumber' do
watch(%r{^features/.+\.feature$})
# added by cuke-pack
group :wip do
guard 'cucumber', :env => :cucumber, :cli => '-p wip' do
watch(%r{^features/.+.feature$})
watch(%r{^(app|lib).*}) { 'features' }
watch(%r{^features/support/.+$}) { 'features' }
watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
watch(%r{^features/step_definitions/(.+).rb$}) { 'features' }
end
end

8
config/cucumber.yml Normal file
View File

@ -0,0 +1,8 @@
<%
std_opts = "-r features --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} -f Cucumber::StepWriter --out features/step_definitions --strict"
%>
default: <%= std_opts %> features
wip: <%= std_opts %> --tags @wip features
precommit: FAILFAST=true <%= std_opts %> --tags ~@wip:0 features
cleanup: <%= std_opts %> -f Cucumber::CleanupFormatter --out unused.txt features

View File

@ -31,3 +31,41 @@ Feature: Gemfiles
# generated by penchant, environment: local
this is content
"""
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 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:
"""
<% with_gem_list '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 content:
"""
# generated by penchant, environment: local
gem 'test', :path => %{../test}
"""

View File

@ -0,0 +1,4 @@
When /^I rebuild the Gemfile for "(.*?)" mode$/ do |env|
Penchant::Gemfile.do_full_env_switch!(env)
end

View File

@ -0,0 +1,20 @@
require 'cuke-pack/support/pause'
require 'cuke-pack/support/pending'
Before do
# if you want pending steps to pause before marking the step as pending,
# set @pause_ok to true
@pause_ok = false
end
require 'cuke-pack/support/step_writer'
require 'cuke-pack/support/wait_for'
require 'cuke-pack/support/failfast'
# set the level of flaying on the step definitions
# set it to false to skip flaying
flay_level = 32
require 'cuke-pack/support/flay'

View File

@ -61,7 +61,7 @@ module Penchant
def switch_to!(gemfile_env = nil, deployment = false)
@env, @is_deployment = gemfile_env, deployment
output = [ header, ERB.new(template).result(binding) ]
output = [ header, ERB.new(template, nil, nil, '@_erbout').result(binding) ]
File.open(gemfile_path, 'wb') { |fh| fh.print output.join("\n") }
end
@ -97,8 +97,36 @@ module Penchant
File.read(gemfile_erb_path)
end
def env(check, &block)
instance_eval(&block) if check.to_s == @env.to_s
def env(check, template = {}, &block)
if check.to_s == @env.to_s
original_erbout = @_erbout.dup
output = instance_eval(&block).lines.to_a
output.each do |line|
if gem_name = line[%r{gem ['"]([^'"]+)['"]}, 1]
new_line = line.rstrip
template.each do |key, value|
new_line += ", #{key.inspect} => %{#{value % gem_name}}"
end
new_line += "\n"
line.replace(new_line)
end
end
@_erbout = original_erbout + output.join
end
end
def with_gem_list(*gems)
gems.each do |gem|
@_current_gem = gem
yield
end
end
def gem
"gem '#{@_current_gem}'"
end
def no_deployment(&block)