Created
November 22, 2012 15:51
-
-
Save stas/4131823 to your computer and use it in GitHub Desktop.
Rails Engine: rake task and generator to DRY `spec/dummy`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails/generators' | |
require 'rails/generators/rails/plugin_new/plugin_new_generator' | |
module MyEngine | |
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 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env rake | |
require 'rspec/core/rake_task' | |
RSpec::Core::RakeTask.new(:spec => :dummy_app) do |t| | |
t.pattern = File.expand_path('../spec/**/*_spec.rb', __FILE__) | |
end | |
task :default => :spec | |
desc 'Generates a dummy app for testing' | |
task :dummy_app => [:setup, :migrate] | |
task :setup do | |
require 'rails' | |
require 'my_engine' | |
require 'my_engine/generators/dummy_generator' | |
dummy = File.expand_path('../spec/dummy', __FILE__) | |
sh "rm -rf #{dummy}" | |
MyEngine::DummyGenerator.start( | |
%W(. --quiet --force --skip-bundle --old-style-hash --dummy-path=#{dummy}) | |
) | |
end | |
task :migrate do | |
rakefile = File.expand_path('../spec/dummy/Rakefile', __FILE__) | |
sh("rake -f #{rakefile} my_engine:install:migrations") | |
sh("rake -f #{rakefile} db:create db:migrate db:test:prepare") | |
end |
Cool gem, definitely plan on using it, Thx ;)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@etdsoft take a look at https://github.com/stas/rails-dummy