Sha256: 6fd7229c23c1a5a9eb3096d788ccb93c09d2c5c1716cc368d81ec82c5d009919

Contents?: true

Size: 1.98 KB

Versions: 1

Compression:

Stored size: 1.98 KB

Contents

namespace :engine_cart do

  desc "Prepare a gem for using engine_cart"
  task :prepare do
    require 'generators/engine_cart/engine_cart_generator'
    generator = EngineCartGenerator.new
    generator.create_test_app_templates
    generator.ignore_test_app
  end

  task :setup do
    TEST_APP_TEMPLATES = 'spec/test_app_templates' unless defined? TEST_APP_TEMPLATES
    TEST_APP = 'spec/internal' unless defined? TEST_APP
  end

  desc "Clean out the test rails app"
  task :clean => [:setup] do
    puts "Removing sample rails app"
    `rm -rf #{TEST_APP}`
  end

  task :create_test_rails_app => [:setup] do
    system "rails new #{TEST_APP}"
  end

  task :inject_gemfile_extras => [:setup] do
    # Add our gem and extras to the generated Rails app
    open(File.expand_path('Gemfile', TEST_APP), 'a') do |f|
      gemfile_extras_path = File.expand_path("Gemfile.extra", TEST_APP_TEMPLATES)

      f.write <<-EOF
        gem '#{current_engine_name}', :path => '#{File.expand_path('.')}'

        if File.exists?("#{gemfile_extras_path}")
          eval File.read("#{gemfile_extras_path}"), nil, "#{gemfile_extras_path}"
        end
EOF
    end
  end

  desc "Create the test rails app"
  task :generate => [:setup] do

    unless File.exists? File.expand_path('Rakefile', TEST_APP)
      # Create a new test rails app
      Rake::Task['engine_cart:create_test_rails_app'].invoke
      Rake::Task['engine_cart:inject_gemfile_extras'].invoke

      # Copy our test app generators into the app and prepare it
      system "cp -r #{TEST_APP_TEMPLATES}/lib/generators #{TEST_APP}/lib"
      within_test_app do
        system "bundle install"
        system "rails generate test_app"
        system "rake db:migrate db:test:prepare"
      end
      puts "Done generating test app"
    end
  end
end

def current_engine_name
  ENV["CURRENT_ENGINE_NAME"] || File.basename(Dir.glob("*.gemspec").first, '.gemspec')
end

def within_test_app
  Dir.chdir(TEST_APP) do
    Bundler.with_clean_env do
      yield
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
engine_cart-0.1.1 lib/engine_cart/tasks/engine_cart.rake