Skip to content

Instantly share code, notes, and snippets.

@jeremyf
Created July 26, 2013 13:54
Show Gist options
  • Save jeremyf/6089028 to your computer and use it in GitHub Desktop.
Save jeremyf/6089028 to your computer and use it in GitHub Desktop.
Rake file configuration for mountable Rails 3.x engine
namespace :dummy do
desc "Generate a Rails dummy for ActivityEngine tests"
task :generate => [:init, :new_app, :install, :migrate]
desc 'Remove dummy application'
task :remove => :init do
require 'fileutils'
$stdout.puts "Removing spec/dummy"
DummyFileUtils.rm_rf(DUMMY_ROOT)
end
desc "Replace the existing Rails dummy for ActivityEngine tests"
task :regenerate => [:remove, :generate]
task :new_app => [:init, :guard] do
# Cribbed from https://gist.github.com/stas/4131823
require 'rails'
require 'activity_engine'
require 'rails/generators'
require 'rails/generators/rails/plugin_new/plugin_new_generator'
class DummyGenerator < Rails::Generators::PluginNewGenerator
def self.default_source_root
Rails::Generators::PluginNewGenerator.default_source_root
end
def do_nothing
end
alias :create_root :do_nothing
alias :create_root_files :do_nothing
alias :create_app_files :do_nothing
alias :create_config_files :do_nothing
alias :create_lib_files :do_nothing
alias :create_public_stylesheets_files :do_nothing
alias :create_javascript_files :do_nothing
alias :create_script_files :do_nothing
alias :update_gemfile :do_nothing
alias :create_test_files :do_nothing
alias :finish_template :do_nothing
end
puts "Generating #{DUMMY_ROOT}"
DummyGenerator.start(
%W(. --force --skip-bundle --old-style-hash --dummy-path=#{DUMMY_ROOT})
)
end
task :install => [:init, :new_app] do
puts "Installing ActivityEngine"
require 'generators/activity_engine/install_generator'
ActivityEngine::Generators::InstallGenerator.start(
%W(. --force )
)
end
task :migrate => :init do
puts "Running activity_engine migrations"
rakefile = File.join(DUMMY_ROOT, 'Rakefile')
system("rake -f #{rakefile} db:create db:migrate db:test:prepare")
end
task :init do
DummyFileUtils = FileUtils #::DryRun
DUMMY_ROOT = File.expand_path("../../spec/dummy", __FILE__).freeze
end
task :guard => [:init] do
if File.exist?(File.join(DUMMY_ROOT, 'Rakefile'))
$stderr.puts "Dummy rakefile already exists"
exit!(-1)
end
end
end
#!/usr/bin/env rake
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
# I want these tasks local to the project, not in Rake's 'app' namespace
Dir.glob('tasks/*.rake').each { |r| import r }
Bundler::GemHelper.install_tasks
task default: :spec
task :spec => ['dummy:regenerate'] do
require 'rails'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:rspec) do |t|
t.pattern = '../**/*_spec.rb'
# Because we are running in the context of the dummy app, we need to
# make sure that spec_helper.rb is somewhere in the load path.
# Thus the "-I ../"
t.rspec_opts = "--colour -I ../"
end
Rake::Task['rspec'].invoke
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment