Sha256: e629567ef837cdd12d25b7674f65df7ff9b4f43a8d8cd14067e061b45e3770ef

Contents?: true

Size: 1.34 KB

Versions: 2

Compression:

Stored size: 1.34 KB

Contents

namespace :engine_cart do

  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

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

    unless File.exists? File.expand_path('Rakefile', TEST_APP)
      system "rails new #{TEST_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 => '../../'

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

      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
  File.basename(Dir.glob("*.gemspec").first, '.gemspec')
end

def within_test_app
  FileUtils.cd(TEST_APP)
  Bundler.with_clean_env do
    yield
  end
  FileUtils.cd(APP_ROOT)
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
engine_cart-0.0.2 lib/engine_cart/tasks/engine_cart.rake
engine_cart-0.0.1 lib/engine_cart/tasks/engine_cart.rake