├── .gitignore ├── Gemfile ├── Gemfile.lock ├── MIT-LICENSE ├── README.rdoc ├── Rakefile ├── bin └── enginex ├── enginex.gemspec ├── lib ├── enginex.rb └── templates │ ├── gitignore │ ├── rails │ ├── application.rb │ └── boot.rb │ ├── root │ ├── %underscored%.gemspec.tt │ ├── Gemfile.tt │ ├── MIT-LICENSE.tt │ ├── README.rdoc.tt │ ├── Rakefile.tt │ └── lib │ │ └── %underscored%.rb.tt │ ├── spec │ ├── %underscored%_spec.rb.tt │ ├── integration │ │ └── navigation_spec.rb.tt │ ├── spec_helper.rb │ └── support │ │ └── .empty_directory │ └── test │ ├── %underscored%_test.rb.tt │ ├── integration │ └── navigation_test.rb.tt │ ├── support │ └── integration_case.rb │ └── test_helper.rb └── test ├── enginex_test.rb └── test_helper.rb /.gitignore: -------------------------------------------------------------------------------- 1 | .bundle 2 | pkg/ 3 | test/enginex/ 4 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gemspec 4 | 5 | gem "sqlite3" 6 | gem "rspec", "~> 2.0" 7 | gem "rspec-rails", "~> 2.0" 8 | gem "capybara", "~> 0.4" 9 | gem "rdoc", "> 2.4.2" 10 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | enginex (0.8.1) 5 | rails (~> 3.0.3) 6 | rake (~> 0.8) 7 | thor (~> 0.14) 8 | 9 | GEM 10 | remote: http://rubygems.org/ 11 | specs: 12 | abstract (1.0.0) 13 | actionmailer (3.0.4) 14 | actionpack (= 3.0.4) 15 | mail (~> 2.2.15) 16 | actionpack (3.0.4) 17 | activemodel (= 3.0.4) 18 | activesupport (= 3.0.4) 19 | builder (~> 2.1.2) 20 | erubis (~> 2.6.6) 21 | i18n (~> 0.4) 22 | rack (~> 1.2.1) 23 | rack-mount (~> 0.6.13) 24 | rack-test (~> 0.5.7) 25 | tzinfo (~> 0.3.23) 26 | activemodel (3.0.4) 27 | activesupport (= 3.0.4) 28 | builder (~> 2.1.2) 29 | i18n (~> 0.4) 30 | activerecord (3.0.4) 31 | activemodel (= 3.0.4) 32 | activesupport (= 3.0.4) 33 | arel (~> 2.0.2) 34 | tzinfo (~> 0.3.23) 35 | activeresource (3.0.4) 36 | activemodel (= 3.0.4) 37 | activesupport (= 3.0.4) 38 | activesupport (3.0.4) 39 | arel (2.0.10) 40 | builder (2.1.2) 41 | capybara (0.4.1.2) 42 | celerity (>= 0.7.9) 43 | culerity (>= 0.2.4) 44 | mime-types (>= 1.16) 45 | nokogiri (>= 1.3.3) 46 | rack (>= 1.0.0) 47 | rack-test (>= 0.5.4) 48 | selenium-webdriver (>= 0.0.27) 49 | xpath (~> 0.1.3) 50 | celerity (0.8.8) 51 | childprocess (0.1.7) 52 | ffi (~> 0.6.3) 53 | culerity (0.2.15) 54 | diff-lcs (1.1.2) 55 | erubis (2.6.6) 56 | abstract (>= 1.0.0) 57 | ffi (0.6.3) 58 | rake (>= 0.8.7) 59 | i18n (0.5.0) 60 | json (1.6.3) 61 | json_pure (1.5.1) 62 | mail (2.2.19) 63 | activesupport (>= 2.3.6) 64 | i18n (>= 0.4.0) 65 | mime-types (~> 1.16) 66 | treetop (~> 1.4.8) 67 | mime-types (1.16) 68 | nokogiri (1.4.4) 69 | polyglot (0.3.2) 70 | rack (1.2.1) 71 | rack-mount (0.6.13) 72 | rack (>= 1.0.0) 73 | rack-test (0.5.7) 74 | rack (>= 1.0) 75 | rails (3.0.4) 76 | actionmailer (= 3.0.4) 77 | actionpack (= 3.0.4) 78 | activerecord (= 3.0.4) 79 | activeresource (= 3.0.4) 80 | activesupport (= 3.0.4) 81 | bundler (~> 1.0) 82 | railties (= 3.0.4) 83 | railties (3.0.4) 84 | actionpack (= 3.0.4) 85 | activesupport (= 3.0.4) 86 | rake (>= 0.8.7) 87 | thor (~> 0.14.4) 88 | rake (0.8.7) 89 | rdoc (3.11) 90 | json (~> 1.4) 91 | rspec (2.5.0) 92 | rspec-core (~> 2.5.0) 93 | rspec-expectations (~> 2.5.0) 94 | rspec-mocks (~> 2.5.0) 95 | rspec-core (2.5.1) 96 | rspec-expectations (2.5.0) 97 | diff-lcs (~> 1.1.2) 98 | rspec-mocks (2.5.0) 99 | rspec-rails (2.5.0) 100 | actionpack (~> 3.0) 101 | activesupport (~> 3.0) 102 | railties (~> 3.0) 103 | rspec (~> 2.5.0) 104 | rubyzip (0.9.4) 105 | selenium-webdriver (0.1.3) 106 | childprocess (~> 0.1.5) 107 | ffi (~> 0.6.3) 108 | json_pure 109 | rubyzip 110 | sqlite3 (1.3.3) 111 | thor (0.14.6) 112 | treetop (1.4.10) 113 | polyglot 114 | polyglot (>= 0.3.1) 115 | tzinfo (0.3.24) 116 | xpath (0.1.3) 117 | nokogiri (~> 1.3) 118 | 119 | PLATFORMS 120 | ruby 121 | 122 | DEPENDENCIES 123 | capybara (~> 0.4) 124 | enginex! 125 | rdoc (> 2.4.2) 126 | rspec (~> 2.0) 127 | rspec-rails (~> 2.0) 128 | sqlite3 129 | -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2010 José Valim http://blog.plataformatec.com.br 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.rdoc: -------------------------------------------------------------------------------- 1 | == Enginex 2 | 3 | Enginex is a command line tool which creates a Rails 3 Engine with Rakefile, Gemfile and a ready to run test suite on top of a vendored Rails application. 4 | 5 | Enginex was created for the purpose of and used in José Valim's book: Crafting Rails Applications available at http://plataformatec.com.br/crafting-rails-applications . 6 | 7 | == Use with 3.0 Only 8 | 9 | Enginex is only available for Rails 3.0. *For Rails 3.1 onwards, Enginex was ported to Rails as `rails plugin new` by Piotr Sarnacki.* 10 | 11 | == Usage 12 | 13 | $ enginex ENGINE_NAME 14 | 15 | Give --help to see supported options. 16 | 17 | == Bugs and Feedback 18 | 19 | If you discover any bugs, feel free to send me a message or create an issue on GitHub tracker: 20 | 21 | http://github.com/josevalim 22 | http://github.com/josevalim/enginex/issues 23 | 24 | MIT License. Copyright 2010 José Valim. http://blog.plataformatec.com.br 25 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | require 'rake' 3 | require 'rake/testtask' 4 | require 'rdoc/task' 5 | 6 | Rake::TestTask.new(:test) do |t| 7 | t.libs << 'lib' 8 | t.libs << 'test' 9 | t.pattern = 'test/*_test.rb' 10 | t.verbose = true 11 | end 12 | 13 | RDoc::Task.new(:rdoc) do |rdoc| 14 | rdoc.rdoc_dir = 'rdoc' 15 | rdoc.title = 'Enginex' 16 | rdoc.options << '--line-numbers' << '--inline-source' 17 | rdoc.rdoc_files.include('README.rdoc') 18 | rdoc.rdoc_files.include('lib/**/*.rb') 19 | end 20 | 21 | begin 22 | require 'jeweler' 23 | Jeweler::Tasks.new do |s| 24 | s.name = "enginex" 25 | s.version = "0.8.1" 26 | s.summary = "Creates a Rails 3 engine with Rakefile, Gemfile and running tests" 27 | s.email = "jose.valim@plataformatec.com.br" 28 | s.homepage = "http://github.com/josevalim/enginex" 29 | s.description = "Creates a Rails 3 engine with Rakefile, Gemfile and running tests" 30 | s.authors = ['José Valim'] 31 | s.files = FileList["[A-Z]*", "lib/**/*"] 32 | s.bindir = "bin" 33 | s.executables = %w(enginex) 34 | s.add_dependency("thor", "~> 0.14") 35 | s.add_dependency("rails", "~> 3.0.3") 36 | s.add_dependency("rake", "~> 0.8") 37 | end 38 | 39 | Jeweler::GemcutterTasks.new 40 | rescue LoadError 41 | puts "Jeweler, or one of its dependencies, is not available. Install it with: gem install jeweler" 42 | end 43 | -------------------------------------------------------------------------------- /bin/enginex: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # -*- mode: ruby -*- 3 | 4 | require 'enginex' 5 | 6 | ARGV << "--help" if ARGV.empty? 7 | 8 | Enginex.start 9 | -------------------------------------------------------------------------------- /enginex.gemspec: -------------------------------------------------------------------------------- 1 | # Generated by jeweler 2 | # DO NOT EDIT THIS FILE DIRECTLY 3 | # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' 4 | # -*- encoding: utf-8 -*- 5 | 6 | Gem::Specification.new do |s| 7 | s.name = %q{enginex} 8 | s.version = "0.8.1" 9 | 10 | s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= 11 | s.authors = ["Jos\303\251 Valim"] 12 | s.date = %q{2011-03-01} 13 | s.default_executable = %q{enginex} 14 | s.description = %q{Creates a Rails 3 engine with Rakefile, Gemfile and running tests} 15 | s.email = %q{jose.valim@plataformatec.com.br} 16 | s.executables = ["enginex"] 17 | s.extra_rdoc_files = [ 18 | "README.rdoc" 19 | ] 20 | s.files = [ 21 | "Gemfile", 22 | "Gemfile.lock", 23 | "MIT-LICENSE", 24 | "README.rdoc", 25 | "Rakefile", 26 | "lib/enginex.rb", 27 | "lib/templates/gitignore", 28 | "lib/templates/rails/application.rb", 29 | "lib/templates/rails/boot.rb", 30 | "lib/templates/root/%underscored%.gemspec.tt", 31 | "lib/templates/root/Gemfile.tt", 32 | "lib/templates/root/MIT-LICENSE.tt", 33 | "lib/templates/root/README.rdoc.tt", 34 | "lib/templates/root/Rakefile.tt", 35 | "lib/templates/root/lib/%underscored%.rb.tt", 36 | "lib/templates/spec/%underscored%_spec.rb.tt", 37 | "lib/templates/spec/integration/navigation_spec.rb.tt", 38 | "lib/templates/spec/spec_helper.rb", 39 | "lib/templates/test/%underscored%_test.rb.tt", 40 | "lib/templates/test/integration/navigation_test.rb.tt", 41 | "lib/templates/test/support/integration_case.rb", 42 | "lib/templates/test/test_helper.rb" 43 | ] 44 | s.homepage = %q{http://github.com/josevalim/enginex} 45 | s.require_paths = ["lib"] 46 | s.rubygems_version = %q{1.3.7} 47 | s.summary = %q{Creates a Rails 3 engine with Rakefile, Gemfile and running tests} 48 | s.test_files = [ 49 | "test/enginex_test.rb", 50 | "test/test_helper.rb" 51 | ] 52 | 53 | if s.respond_to? :specification_version then 54 | s.specification_version = 3 55 | 56 | if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then 57 | s.add_runtime_dependency(%q, ["~> 0.14"]) 58 | s.add_runtime_dependency(%q, ["~> 3.0.3"]) 59 | s.add_runtime_dependency(%q, ["~> 0.8"]) 60 | else 61 | s.add_dependency(%q, ["~> 0.14"]) 62 | s.add_dependency(%q, ["~> 3.0.3"]) 63 | s.add_dependency(%q, ["~> 0.8"]) 64 | end 65 | else 66 | s.add_dependency(%q, ["~> 0.14"]) 67 | s.add_dependency(%q, ["~> 3.0.3"]) 68 | s.add_dependency(%q, ["~> 0.8"]) 69 | end 70 | end 71 | 72 | -------------------------------------------------------------------------------- /lib/enginex.rb: -------------------------------------------------------------------------------- 1 | require "thor/group" 2 | require "active_support" 3 | require "active_support/version" 4 | require "active_support/core_ext/string" 5 | 6 | require "rails/generators" 7 | require "rails/generators/rails/app/app_generator" 8 | 9 | class Enginex < Thor::Group 10 | include Thor::Actions 11 | check_unknown_options! 12 | 13 | def self.source_root 14 | @_source_root ||= File.expand_path('../templates', __FILE__) 15 | end 16 | 17 | def self.say_step(message) 18 | @step = (@step || 0) + 1 19 | class_eval <<-METHOD, __FILE__, __LINE__ + 1 20 | def step_#{@step} 21 | #{"puts" if @step > 1} 22 | say_status "STEP #{@step}", #{message.inspect} 23 | end 24 | METHOD 25 | end 26 | 27 | argument :path, :type => :string, 28 | :desc => "Path to the engine to be created" 29 | 30 | class_option :test_framework, :default => "test_unit", :aliases => "-t", 31 | :desc => "Test framework to use. test_unit or rspec." 32 | 33 | desc "Creates a Rails 3 engine with Rakefile, Gemfile and running tests." 34 | 35 | say_step "Creating gem skeleton" 36 | 37 | def create_root 38 | self.destination_root = File.expand_path(path, destination_root) 39 | set_accessors! 40 | 41 | directory "root", "." 42 | FileUtils.cd(destination_root) 43 | end 44 | 45 | def create_tests_or_specs 46 | directory test_path 47 | end 48 | 49 | def change_gitignore 50 | template "gitignore", ".gitignore" 51 | end 52 | 53 | say_step "Vendoring Rails application at test/dummy" 54 | 55 | def invoke_rails_app_generator 56 | invoke Rails::Generators::AppGenerator, 57 | [ File.expand_path(dummy_path, destination_root) ] 58 | end 59 | 60 | say_step "Configuring Rails application" 61 | 62 | def change_config_files 63 | store_application_definition! 64 | template "rails/boot.rb", "#{dummy_path}/config/boot.rb", :force => true 65 | template "rails/application.rb", "#{dummy_path}/config/application.rb", :force => true 66 | end 67 | 68 | say_step "Removing unneeded files" 69 | 70 | def remove_uneeded_rails_files 71 | inside dummy_path do 72 | remove_file ".gitignore" 73 | remove_file "db/seeds.rb" 74 | remove_file "doc" 75 | remove_file "Gemfile" 76 | remove_file "lib/tasks" 77 | remove_file "public/images/rails.png" 78 | remove_file "public/index.html" 79 | remove_file "public/robots.txt" 80 | remove_file "README" 81 | remove_file "test" 82 | remove_file "vendor" 83 | end 84 | end 85 | 86 | protected 87 | 88 | def rspec? 89 | options[:test_framework] == "rspec" 90 | end 91 | 92 | def test_unit? 93 | options[:test_framework] == "test_unit" 94 | end 95 | 96 | def test_path 97 | rspec? ? "spec" : "test" 98 | end 99 | 100 | def dummy_path 101 | "#{test_path}/dummy" 102 | end 103 | 104 | def self.banner 105 | self_task.formatted_usage(self, false) 106 | end 107 | 108 | def application_definition 109 | @application_definition ||= begin 110 | contents = File.read(File.expand_path("#{dummy_path}/config/application.rb", destination_root)) 111 | contents[(contents.index("module Dummy"))..-1] 112 | end 113 | end 114 | alias :store_application_definition! :application_definition 115 | 116 | # Cache accessors since we are changing the directory 117 | def set_accessors! 118 | self.name 119 | self.class.source_root 120 | end 121 | 122 | def name 123 | @name ||= File.basename(destination_root) 124 | end 125 | 126 | def camelized 127 | @camelized ||= name.underscore.camelize 128 | end 129 | 130 | def underscored 131 | @underscored ||= name.underscore 132 | end 133 | end 134 | -------------------------------------------------------------------------------- /lib/templates/gitignore: -------------------------------------------------------------------------------- 1 | .bundle/ 2 | log/*.log 3 | pkg/ 4 | <%= test_path %>/dummy/db/*.sqlite3 5 | <%= test_path %>/dummy/log/*.log 6 | <%= test_path %>/dummy/tmp/ 7 | -------------------------------------------------------------------------------- /lib/templates/rails/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | require "active_model/railtie" 4 | require "active_record/railtie" 5 | require "action_controller/railtie" 6 | require "action_view/railtie" 7 | require "action_mailer/railtie" 8 | 9 | Bundler.require 10 | require "<%= underscored %>" 11 | 12 | <%= application_definition %> -------------------------------------------------------------------------------- /lib/templates/rails/boot.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | gemfile = File.expand_path('../../../../Gemfile', __FILE__) 3 | 4 | if File.exist?(gemfile) 5 | ENV['BUNDLE_GEMFILE'] = gemfile 6 | require 'bundler' 7 | Bundler.setup 8 | end 9 | 10 | $:.unshift File.expand_path('../../../../lib', __FILE__) -------------------------------------------------------------------------------- /lib/templates/root/%underscored%.gemspec.tt: -------------------------------------------------------------------------------- 1 | # Provide a simple gemspec so you can easily use your enginex 2 | # project in your rails apps through git. 3 | Gem::Specification.new do |s| 4 | s.name = "<%= underscored %>" 5 | s.summary = "Insert <%= camelized %> summary." 6 | s.description = "Insert <%= camelized %> description." 7 | s.files = Dir["{app,lib,config}/**/*"] + ["MIT-LICENSE", "Rakefile", "Gemfile", "README.rdoc"] 8 | s.version = "0.0.1" 9 | s.authors = "Author name here." 10 | end 11 | -------------------------------------------------------------------------------- /lib/templates/root/Gemfile.tt: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gem "rails", "<%= ActiveSupport::VERSION::STRING %>" 4 | gem "capybara", ">= 0.4.0" 5 | gem "sqlite3" 6 | <%- if rspec? %> 7 | gem "rspec-rails", ">= 2.0.0.beta" 8 | <% end -%> 9 | gem "rdoc", "> 2.4.2" 10 | 11 | # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+) 12 | # gem 'ruby-debug' 13 | # gem 'ruby-debug19' 14 | -------------------------------------------------------------------------------- /lib/templates/root/MIT-LICENSE.tt: -------------------------------------------------------------------------------- 1 | Copyright <%= Date.today.year %> YOURNAME 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /lib/templates/root/README.rdoc.tt: -------------------------------------------------------------------------------- 1 | = <%= camelized %> 2 | 3 | This project rocks and uses MIT-LICENSE. -------------------------------------------------------------------------------- /lib/templates/root/Rakefile.tt: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | require 'rubygems' 3 | begin 4 | require 'bundler/setup' 5 | rescue LoadError 6 | puts 'You must `gem install bundler` and `bundle install` to run rake tasks' 7 | end 8 | 9 | require 'rake' 10 | require 'rdoc/task' 11 | 12 | <% if rspec? -%> 13 | require 'rspec/core' 14 | require 'rspec/core/rake_task' 15 | 16 | RSpec::Core::RakeTask.new(:spec) 17 | <% else -%> 18 | require 'rake/testtask' 19 | 20 | Rake::TestTask.new(:test) do |t| 21 | t.libs << 'lib' 22 | t.libs << 'test' 23 | t.pattern = 'test/**/*_test.rb' 24 | t.verbose = false 25 | end 26 | <% end -%> 27 | 28 | task :default => :<%= test_path %> 29 | 30 | RDoc::Task.new(:rdoc) do |rdoc| 31 | rdoc.rdoc_dir = 'rdoc' 32 | rdoc.title = '<%= camelized %>' 33 | rdoc.options << '--line-numbers' << '--inline-source' 34 | rdoc.rdoc_files.include('README.rdoc') 35 | rdoc.rdoc_files.include('lib/**/*.rb') 36 | end 37 | -------------------------------------------------------------------------------- /lib/templates/root/lib/%underscored%.rb.tt: -------------------------------------------------------------------------------- 1 | module <%= camelized %> 2 | end -------------------------------------------------------------------------------- /lib/templates/spec/%underscored%_spec.rb.tt: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe <%= camelized %> do 4 | it "should be valid" do 5 | <%= camelized %>.should be_a(Module) 6 | end 7 | end -------------------------------------------------------------------------------- /lib/templates/spec/integration/navigation_spec.rb.tt: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe "Navigation" do 4 | include Capybara 5 | 6 | it "should be a valid app" do 7 | ::Rails.application.should be_a(Dummy::Application) 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/templates/spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # Configure Rails Environment 2 | ENV["RAILS_ENV"] = "test" 3 | 4 | require File.expand_path("../dummy/config/environment.rb", __FILE__) 5 | require "rails/test_help" 6 | require "rspec/rails" 7 | 8 | ActionMailer::Base.delivery_method = :test 9 | ActionMailer::Base.perform_deliveries = true 10 | ActionMailer::Base.default_url_options[:host] = "test.com" 11 | 12 | Rails.backtrace_cleaner.remove_silencers! 13 | 14 | # Configure capybara for integration testing 15 | require "capybara/rails" 16 | Capybara.default_driver = :rack_test 17 | Capybara.default_selector = :css 18 | 19 | # Run any available migration 20 | ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__) 21 | 22 | # Load support files 23 | Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } 24 | 25 | RSpec.configure do |config| 26 | # Remove this line if you don't want RSpec's should and should_not 27 | # methods or matchers 28 | require 'rspec/expectations' 29 | config.include RSpec::Matchers 30 | 31 | # == Mock Framework 32 | config.mock_with :rspec 33 | end 34 | -------------------------------------------------------------------------------- /lib/templates/spec/support/.empty_directory: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josevalim/enginex/84f770fbaa55560ca104e958852eab5e5e33ae74/lib/templates/spec/support/.empty_directory -------------------------------------------------------------------------------- /lib/templates/test/%underscored%_test.rb.tt: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class <%= camelized %>Test < ActiveSupport::TestCase 4 | test "truth" do 5 | assert_kind_of Module, <%= camelized %> 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/templates/test/integration/navigation_test.rb.tt: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class NavigationTest < ActiveSupport::IntegrationCase 4 | test "truth" do 5 | assert_kind_of Dummy::Application, Rails.application 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/templates/test/support/integration_case.rb: -------------------------------------------------------------------------------- 1 | # Define a bare test case to use with Capybara 2 | class ActiveSupport::IntegrationCase < ActiveSupport::TestCase 3 | include Capybara::DSL 4 | include Rails.application.routes.url_helpers 5 | end -------------------------------------------------------------------------------- /lib/templates/test/test_helper.rb: -------------------------------------------------------------------------------- 1 | # Configure Rails Environment 2 | ENV["RAILS_ENV"] = "test" 3 | 4 | require File.expand_path("../dummy/config/environment.rb", __FILE__) 5 | require "rails/test_help" 6 | 7 | ActionMailer::Base.delivery_method = :test 8 | ActionMailer::Base.perform_deliveries = true 9 | ActionMailer::Base.default_url_options[:host] = "test.com" 10 | 11 | Rails.backtrace_cleaner.remove_silencers! 12 | 13 | # Configure capybara for integration testing 14 | require "capybara/rails" 15 | Capybara.default_driver = :rack_test 16 | Capybara.default_selector = :css 17 | 18 | # Run any available migration 19 | ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__) 20 | 21 | # Load support files 22 | Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } -------------------------------------------------------------------------------- /test/enginex_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class EnginexTest < Enginex::TestCase 4 | test "enginex skeleton" do 5 | run_enginex do 6 | # Root 7 | assert_file "Rakefile" 8 | assert_file "Gemfile", /gem "rails"/, /gem "capybara"/, /gem "rdoc"/ 9 | assert_file ".gitignore", /\.bundle/ 10 | assert_file "Rakefile", /require 'rdoc\/task'/ 11 | 12 | # Lib 13 | assert_file "lib/demo_engine.rb", /module DemoEngine\nend/ 14 | 15 | # Vendored Rails 16 | assert_file "test/dummy/config/boot.rb" 17 | assert_file "test/dummy/config/application.rb" 18 | end 19 | end 20 | 21 | test "enginex skeleton with dashes in name" do 22 | @project_name = "demo-engine" 23 | run_enginex do 24 | assert_file "lib/demo_engine.rb", /module DemoEngine\nend/ 25 | end 26 | end 27 | 28 | 29 | test "enginex skeleton with test_unit" do 30 | run_enginex do 31 | assert_file "test/test_helper.rb" 32 | assert_directory "test/support/" 33 | assert_directory "test/integration/" 34 | 35 | assert_file "test/demo_engine_test.rb", /assert_kind_of Module, DemoEngine/ 36 | assert_file "test/integration/navigation_test.rb", /assert_kind_of Dummy::Application, Rails.application/ 37 | assert_file "test/support/integration_case.rb", /class ActiveSupport::IntegrationCase/ 38 | 39 | assert_file ".gitignore", /test\/dummy\/db\/\*\.sqlite3/ 40 | end 41 | end 42 | 43 | test "enginex skeleton with rspec" do 44 | run_enginex(:rspec) do 45 | assert_file "spec/spec_helper.rb" 46 | assert_directory "spec/support/" 47 | assert_directory "spec/integration/" 48 | 49 | assert_file "spec/demo_engine_spec.rb", /DemoEngine.should be_a\(Module\)/ 50 | assert_file "spec/integration/navigation_spec.rb", /Rails.application.should be_a\(Dummy::Application\)/ 51 | 52 | assert_file ".gitignore", /spec\/dummy\/db\/\*\.sqlite3/ 53 | end 54 | end 55 | 56 | test "enginex rakefile can create a gem" do 57 | run_enginex do 58 | execute("gem build demo_engine.gemspec") 59 | assert_file "demo_engine-0.0.1.gem" 60 | end 61 | end 62 | 63 | test "enginex can run tests" do 64 | run_enginex do 65 | assert_match /2 tests, 2 assertions, 0 failures, 0 errors/, execute("rake test") 66 | end 67 | end 68 | 69 | test "enginex can run specs" do 70 | run_enginex(:rspec) do 71 | assert_match /2 examples, 0 failures/, execute("rake spec") 72 | end 73 | end 74 | end 75 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | 3 | require 'bundler' 4 | Bundler.setup 5 | 6 | ENV["RAILS_ENV"] ||= "test" 7 | require 'fileutils' 8 | require 'test/unit' 9 | require 'active_support' 10 | require 'active_support/test_case' 11 | 12 | $enginex_counter = 0 13 | LIB_PATH = File.expand_path('../../lib', __FILE__) 14 | BIN_PATH = File.expand_path('../../bin/enginex', __FILE__) 15 | 16 | DESTINATION_ROOT = File.expand_path('../enginex', __FILE__) 17 | FileUtils.rm_rf(DESTINATION_ROOT) 18 | 19 | $:.unshift LIB_PATH 20 | require 'enginex' 21 | 22 | class Enginex::TestCase < ActiveSupport::TestCase 23 | def run_enginex(suite = :test_unit) 24 | if suite == :rspec 25 | option = '--test-framework=rspec' 26 | else 27 | option = '--test-framework=test_unit' 28 | end 29 | 30 | $enginex_counter += 1 31 | `ruby -I#{LIB_PATH} -rrubygems #{BIN_PATH} #{destination_root} #{option}` 32 | yield 33 | rescue Exception => e 34 | puts "Error happened. #{destination_root.inspect} left for inspecting." 35 | raise e 36 | ensure 37 | FileUtils.rm_rf(File.dirname(destination_root)) 38 | end 39 | 40 | def project_name 41 | @project_name ||= "demo_engine" 42 | end 43 | 44 | def destination_root 45 | File.join(DESTINATION_ROOT, $enginex_counter.to_s, project_name) 46 | end 47 | 48 | def capture(stream) 49 | begin 50 | stream = stream.to_s 51 | eval "$#{stream} = StringIO.new" 52 | yield 53 | eval("$#{stream}").string 54 | ensure 55 | eval("$#{stream} = #{stream.upcase}") 56 | end 57 | end 58 | alias :silence :capture 59 | 60 | def assert_file(relative, *contents) 61 | absolute = File.expand_path(relative, destination_root) 62 | assert File.exists?(absolute), "Expected file #{relative.inspect} to exist, but does not" 63 | 64 | read = File.read(absolute) if block_given? || !contents.empty? 65 | yield read if block_given? 66 | 67 | contents.each do |content| 68 | assert_match content, read 69 | end 70 | end 71 | alias :assert_directory :assert_file 72 | 73 | def assert_no_file(relative) 74 | absolute = File.expand_path(relative, destination_root) 75 | assert !File.exists?(absolute), "Expected file #{relative.inspect} to not exist, but does" 76 | end 77 | alias :assert_no_directory :assert_no_file 78 | 79 | def execute(command) 80 | current_path = Dir.pwd 81 | FileUtils.cd destination_root 82 | `#{command}` 83 | ensure 84 | FileUtils.cd current_path 85 | end 86 | end --------------------------------------------------------------------------------