├── .gitignore ├── .rspec ├── CHANGELOG ├── Gemfile ├── LICENSE ├── README.textile ├── Rakefile ├── TODO.md ├── bin └── templater ├── lib ├── rails_templater.rb ├── rails_templater │ ├── cli.rb │ ├── fixture_replacement.rb │ ├── javascript_framework.rb │ ├── orm.rb │ ├── template_engine.rb │ ├── templater.rb │ ├── testing_framework.rb │ └── version.rb └── template_framework │ ├── core_ext.rb │ ├── recipes │ ├── active_record.rb │ ├── code_coverage.rb │ ├── compass.rb │ ├── cover_me.rb │ ├── cucumber.rb │ ├── default.rb │ ├── erb.rb │ ├── fabrication.rb │ ├── factory_girl.rb │ ├── fixture_replacement.rb │ ├── git.rb │ ├── haml.rb │ ├── javascript_framework.rb │ ├── mongoid.rb │ ├── orm.rb │ ├── pry.rb │ ├── rcov.rb │ ├── rspec.rb │ ├── shoulda_matchers.rb │ ├── slim.rb │ ├── template_engine.rb │ ├── test_unit.rb │ └── testing_framework.rb │ ├── snippets │ ├── cucumber │ │ └── factory_girl │ ├── fabrication │ │ ├── generator_rspec │ │ └── generator_test_unit │ ├── factory_girl │ │ ├── generator_rspec │ │ └── generator_test_unit │ └── rspec │ │ └── mongoid │ ├── template_runner.rb │ └── templates │ ├── active_record │ └── config │ │ └── database.yml │ ├── erb │ └── app │ │ └── views │ │ └── layouts │ │ └── application.html.erb │ ├── git │ └── gitignore │ ├── haml │ └── app │ │ └── views │ │ └── layouts │ │ └── application.html.haml │ ├── jquery │ └── app │ │ └── assets │ │ └── javascripts │ │ └── application.js │ ├── mongoid │ ├── features │ │ └── step_definitions │ │ │ └── mongoid_steps.rb │ └── lib │ │ └── tasks │ │ └── assets.rake │ ├── prototype │ └── app │ │ └── assets │ │ └── javascripts │ │ └── application.js │ └── slim │ └── app │ └── views │ └── layouts │ └── application.html.slim ├── rails_templater.gemspec └── spec ├── fixtures ├── sample_snippet └── sample_template.rb ├── rails_templater ├── fixture_replacement_spec.rb ├── javascript_framework_spec.rb ├── orm_spec.rb ├── template_engine_spec.rb ├── templater_spec.rb └── testing_framework_spec.rb ├── rails_templater_spec.rb ├── spec_helper.rb └── support ├── fixtures.rb └── paths.rb /.gitignore: -------------------------------------------------------------------------------- 1 | .bundle 2 | Gemfile.lock 3 | pkg/* -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --colour 2 | --format documentation 3 | --fail-fast -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | In Development 2 | 3 | 0.3.0 (March 14, 2012) 4 | * Updated to work with Rails Asset Pipeline 5 | * Removed Sass recipe as it is now the default in Rails 6 | * Added Pry recipe for IRB Replacement 7 | * Added Fabrication as recommended option for Fixture Replacement 8 | * Removed Remarkable, replaced with mongo 9 | * When Erb is selected as the template framework, layout.html.erb matches Haml & Slim recipes 10 | * Removed custom FactoryGirl generators, using factory_girl_rails 11 | * Adding mongoid-rspec for matchers option when Mongoid & RSpec are selected 12 | * Adding should-matchers for ActiveRecord matchers for RSpec & TestUnit 13 | 14 | 0.2.1 (February 9, 2011) 15 | * Fixed path-generation not being pluralized in Rails 3.0.4 [tariksin] 16 | 17 | 0.2.0 (February 6, 2011) 18 | * Added 960 Grid System option to Compass (via guilleiguaran) 19 | * Added shoulda-context option for TestUnit (via guilleiguaran) 20 | * Added CoverMe code coverage recipe for Ruby 1.9 (via guilleiguaran) 21 | * Added RCov code coverage recipe for Ruby 1.8 (via guilleiguaran) 22 | * Mongoid recipe is now using 2.0.0.rc.7 23 | 24 | 0.1.2 (February 1, 2011) 25 | 26 | * Added the Slim template engine (via fredwu) 27 | * Fixed the layout template for Haml 28 | 29 | 0.1.1 (January 30, 2011) 30 | 31 | * rails-templater choices are now agnostic 32 | * Add ActiveRecord as an ORM option 33 | * Add TestUnit as a Testing Framework option 34 | * Add Prototype as a JavaScript Framework option 35 | * Remarkable RSpec matchers are optional and are dependent on the RSpec recipe 36 | * Haml is an optional choice for your View Templates 37 | * Sass is an optional choice for composing Stylesheets 38 | * Compass is now dependent on the Sass recipe 39 | * Compass has three options: core, blueprint semantic, and blueprint basic 40 | * Cucumber is an optional choice for Integration Testing 41 | 42 | 0.0.2 (January 23, 2011) 43 | 44 | * Add a custom generator for FactoryGirl which uses the new 2.0.0 syntax 45 | 46 | 0.0.1 (January 13, 2011) 47 | 48 | * First version -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source :gemcutter 2 | 3 | gemspec 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Kevin Faustino 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. -------------------------------------------------------------------------------- /README.textile: -------------------------------------------------------------------------------- 1 | h1. Rails Templater 2 | 3 | Rails Templater is a gem which generates new Ruby on Rails 3 applications the way you want them. Based on your choices, Rails Templater will create an application configured correctly. For example, if you select Mongoid for an ODM and RSpec for your testing framework, Rails Templater will generate all necessary hooks to handle dropping your collections from MongoDB. The project was inspired by ffmike's "BigOldRailsTemplate":http://github.com/ffmike/BigOldRailsTemplate Rails 2 template project. 4 | 5 | h2. Install 6 | 7 | @gem install rails_templater@ 8 | 9 | h2. Usage 10 | 11 | At the command prompt, create a new Rails application using the @templater@ command: 12 | 13 | @templater myapp_name@ 14 | 15 | h2. Generated Application 16 | 17 | Rails Templater provides you with the following choices during application generation: 18 | 19 | h3. Database 20 | 21 | * "Mongoid":http://mongoid.org/ as your Object Document Mapper for MongoDB 22 | * ActiveRecord as your Object Relational Mapper for Relational Databases 23 | 24 | h3. Testing 25 | 26 | * "RSpec":http://github.com/rspec/rspec 27 | * TestUnit 28 | 29 | h4. Matchers (optional) 30 | 31 | * "mongoid-rspec":https://github.com/evansagge/mongoid-rspec for Mongoid RSpec matchers 32 | * "shoulda-matchers":https://github.com/thoughtbot/shoulda-matchers for ActiveRecord matchers in RSpec/TestUnit 33 | * "shoulda-context":http://github.com/thoughtbot/shoulda-context for contexts in TestUnit 34 | 35 | h4. Fixture Replacement 36 | 37 | * "Fabrication":http://fabricationgem.org/ 38 | * "FactoryGirl":http://github.com/thoughtbot/factory_girl 39 | 40 | h4. Integration Testing (optional) 41 | 42 | * "Cucumber":http://github.com/aslakhellesoy/cucumber-rails 43 | 44 | h4. Code Coverage 45 | 46 | * "RCov":http://github.com/relevance/rcov (optional, only for Ruby 1.8) 47 | * "CoverMe":https://github.com/markbates/cover_me (optional, only for Ruby 1.9) 48 | 49 | h3. JavaScript 50 | 51 | * "jQuery":http://jquery.com/ 52 | * "Prototype":http://www.prototypejs.org/ 53 | 54 | h3. Template Engine 55 | 56 | * "Haml":http://haml-lang.com 57 | * "Slim":http://github.com/stonean/slim 58 | * ERB 59 | 60 | h3. Sass Extensions (optional) 61 | 62 | * "Compass":http://compass-style.org as your stylesheet authoring framework 63 | 64 | h2. Note on Patches/Pull Requests 65 | 66 | * Fork the project. 67 | * Make your feature addition or bug fix in a branch. 68 | * Send me a pull request. 69 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler' 2 | Bundler::GemHelper.install_tasks 3 | 4 | require "rspec/core/rake_task" 5 | RSpec::Core::RakeTask.new(:spec) do |spec| 6 | spec.pattern = 'spec/**/*_spec.rb' 7 | end 8 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | # TODO 2 | 3 | * Add Bourbon to Sass Extensions 4 | * Devise recipe 5 | * SimpleForm recipe -------------------------------------------------------------------------------- /bin/templater: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | $:.unshift File.expand_path("../../lib", __FILE__) 3 | 4 | require 'rails_templater' 5 | 6 | RailsTemplater::Cli.start(ARGV) -------------------------------------------------------------------------------- /lib/rails_templater.rb: -------------------------------------------------------------------------------- 1 | require 'active_support/core_ext/string' 2 | 3 | module RailsTemplater 4 | extend self 5 | 6 | class NotSupportedError < Exception; end 7 | 8 | autoload :Cli, 'rails_templater/cli' 9 | autoload :FixtureReplacement, 'rails_templater/fixture_replacement' 10 | autoload :JavaScriptFramework, 'rails_templater/javascript_framework' 11 | autoload :Orm, 'rails_templater/orm' 12 | autoload :Templater, 'rails_templater/templater' 13 | autoload :TemplateEngine, 'rails_templater/template_engine' 14 | autoload :TestingFramework, 'rails_templater/testing_framework' 15 | 16 | def template_runner 17 | File.join(File.dirname(__FILE__), 'template_framework', 'template_runner.rb') 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/rails_templater/cli.rb: -------------------------------------------------------------------------------- 1 | require 'thor/group' 2 | 3 | module RailsTemplater 4 | class Cli < Thor::Group 5 | argument :application_name, :type => :string, :desc => "The name of the rails application" 6 | desc "Generates a new Rails application with templater'" 7 | 8 | def run_templater 9 | system("rails new #{application_name} -JO --skip-bundle -m #{RailsTemplater::template_runner}") 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/rails_templater/fixture_replacement.rb: -------------------------------------------------------------------------------- 1 | module RailsTemplater 2 | class FixtureReplacement 3 | 4 | DEFAULT = :factory_girl 5 | SUPPORTED_TYPES = [:factory_girl, :fabrication] 6 | 7 | def type 8 | @type || DEFAULT 9 | end 10 | 11 | def type=(value) 12 | raise NotSupportedError unless SUPPORTED_TYPES.include?(value) 13 | @type = value 14 | end 15 | 16 | SUPPORTED_TYPES.each do |type| 17 | define_method "#{type}?" do 18 | self.type == type 19 | end 20 | end 21 | end 22 | end -------------------------------------------------------------------------------- /lib/rails_templater/javascript_framework.rb: -------------------------------------------------------------------------------- 1 | module RailsTemplater 2 | class JavaScriptFramework 3 | 4 | DEFAULT = :jquery 5 | SUPPORTED_TYPES = [:jquery, :prototype] 6 | 7 | def type 8 | @type || DEFAULT 9 | end 10 | 11 | def type=(value) 12 | raise NotSupportedError unless SUPPORTED_TYPES.include?(value) 13 | @type = value 14 | end 15 | 16 | SUPPORTED_TYPES.each do |type| 17 | define_method "#{type}?" do 18 | self.type == type 19 | end 20 | end 21 | end 22 | end -------------------------------------------------------------------------------- /lib/rails_templater/orm.rb: -------------------------------------------------------------------------------- 1 | module RailsTemplater 2 | class Orm 3 | 4 | DEFAULT = :mongoid 5 | SUPPORTED_TYPES = [:active_record, :mongoid] 6 | 7 | def type 8 | @type || DEFAULT 9 | end 10 | 11 | def type=(value) 12 | raise NotSupportedError unless SUPPORTED_TYPES.include?(value) 13 | @type = value 14 | end 15 | 16 | SUPPORTED_TYPES.each do |type| 17 | define_method "#{type}?" do 18 | self.type == type 19 | end 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /lib/rails_templater/template_engine.rb: -------------------------------------------------------------------------------- 1 | module RailsTemplater 2 | class TemplateEngine 3 | 4 | DEFAULT = :haml 5 | SUPPORTED_TYPES = [:haml, :slim, :erb] 6 | 7 | def type 8 | @type || DEFAULT 9 | end 10 | 11 | def type=(value) 12 | raise NotSupportedError unless SUPPORTED_TYPES.include?(value) 13 | @type ||= value 14 | end 15 | 16 | SUPPORTED_TYPES.each do |type| 17 | define_method "#{type}?" do 18 | self.type == type 19 | end 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /lib/rails_templater/templater.rb: -------------------------------------------------------------------------------- 1 | module RailsTemplater 2 | class Templater 3 | 4 | attr_reader :post_bundler_strategies 5 | 6 | def initialize 7 | @post_bundler_strategies = [] 8 | @template_framework_path = File.join(File.dirname(__FILE__), '..', 'template_framework') 9 | end 10 | 11 | def fixture_replacement 12 | @fixture_replacement ||= FixtureReplacement.new 13 | end 14 | 15 | def orm 16 | @orm ||= Orm.new 17 | end 18 | 19 | def javascript_framework 20 | @javascript_framework ||= JavaScriptFramework.new 21 | end 22 | 23 | def template_engine 24 | @template_engine ||= TemplateEngine.new 25 | end 26 | 27 | def post_bundler(&block) 28 | @post_bundler_strategies << block 29 | end 30 | 31 | def recipe(name) 32 | File.expand_path("recipes/#{name}.rb", @template_framework_path) 33 | end 34 | 35 | ['snippet', 'template'].each do |type| 36 | 37 | define_method "#{type}_path" do |group| 38 | File.expand_path("#{type}s/#{group}", @template_framework_path) 39 | end 40 | 41 | define_method "load_#{type}" do |name, group| 42 | group_path = send("#{type}_path".to_sym, group) 43 | File.read File.expand_path(name, group_path) 44 | end 45 | 46 | end 47 | 48 | def testing_framework 49 | @testing_framework ||= TestingFramework.new 50 | end 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /lib/rails_templater/testing_framework.rb: -------------------------------------------------------------------------------- 1 | module RailsTemplater 2 | class TestingFramework 3 | DEFAULT = :rspec 4 | SUPPORTED_TYPES = [:rspec, :test_unit] 5 | 6 | def type 7 | @type || DEFAULT 8 | end 9 | 10 | def type=(value) 11 | raise NotSupportedError unless SUPPORTED_TYPES.include?(value) 12 | @type ||= value 13 | end 14 | 15 | SUPPORTED_TYPES.each do |type| 16 | define_method "#{type}?" do 17 | self.type == type 18 | end 19 | end 20 | end 21 | end -------------------------------------------------------------------------------- /lib/rails_templater/version.rb: -------------------------------------------------------------------------------- 1 | module RailsTemplater 2 | VERSION = "0.3.0" 3 | end 4 | -------------------------------------------------------------------------------- /lib/template_framework/core_ext.rb: -------------------------------------------------------------------------------- 1 | module Rails 2 | module Generators 3 | module Actions 4 | def templater 5 | @templater ||= RailsTemplater::Templater.new 6 | end 7 | 8 | def execute_post_bundler_strategies 9 | templater.post_bundler_strategies.each {|strategy| strategy.call } 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/template_framework/recipes/active_record.rb: -------------------------------------------------------------------------------- 1 | gem 'sqlite3-ruby', :require => 'sqlite3' 2 | 3 | gsub_file 'config/application.rb', '# require "active_record/railtie"', 'require "active_record/railtie"' 4 | create_file 'config/database.yml', templater.load_template('config/database.yml', 'active_record') 5 | run 'cp config/database.yml config/database.yml.example' -------------------------------------------------------------------------------- /lib/template_framework/recipes/code_coverage.rb: -------------------------------------------------------------------------------- 1 | # Code Coverage 2 | if RUBY_VERSION >= "1.9" 3 | apply(templater.recipe('cover_me')) if yes?("\n\nWould you like to add CoverMe for code coverage? [y|n]: ", Thor::Shell::Color::BLUE) 4 | else 5 | if templater.testing_framework.rspec? 6 | apply(templater.recipe('rcov')) if yes?("\n\nWould you like to add RCov for code coverage? [y|n]: ", Thor::Shell::Color::BLUE) 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/template_framework/recipes/compass.rb: -------------------------------------------------------------------------------- 1 | if yes?("\n[Stylesheets] Would you like to use Compass? [y|n]: ", Thor::Shell::Color::BLUE) 2 | design_options = { 3 | 'Option' => 'Design Framework', 4 | '1' => 'Compass', 5 | '2' => 'Compass with blueprint semantic', 6 | '3' => 'Compass with blueprint basic', 7 | '4' => 'Compass with 960.gs' 8 | } 9 | 10 | print_table design_options.to_a, :ident => 4 11 | design_selection = ask("\nOption: ", Thor::Shell::Color::BLUE) 12 | 13 | design_framework = case design_selection 14 | when "1" 15 | :compass 16 | when "2" 17 | :compass_blueprint_semantic 18 | when "3" 19 | :compass_blueprint 20 | when "4" 21 | :compass_960 22 | else 23 | :none 24 | end 25 | 26 | unless design_framework == :none 27 | remove_file 'app/assets/stylesheets/application.css' 28 | 29 | gem 'compass-rails', group: :assets 30 | 31 | framework_option = case design_framework 32 | when :compass_blueprint 33 | "--using blueprint/basic" 34 | when :compass_blueprint_semantic 35 | "--using blueprint/semantic" 36 | when :compass_960 37 | gem 'compass-960-plugin' 38 | "-r ninesixty --using 960" 39 | end 40 | 41 | templater.post_bundler do 42 | run "bundle exec compass init rails . #{framework_option}" 43 | end 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /lib/template_framework/recipes/cover_me.rb: -------------------------------------------------------------------------------- 1 | gem 'cover_me', '~> 1.2', :group => :test 2 | 3 | templater.post_bundler do 4 | generate "cover_me:install" 5 | 6 | testing_framework_helper = templater.testing_framework.rspec? ? 'spec/spec_helper.rb' : 'test/test_helper.rb' 7 | inject_into_file testing_framework_helper, "\nrequire 'cover_me'", :after => "ENV[\"RAILS_ENV\"] ||= 'test'" 8 | end 9 | -------------------------------------------------------------------------------- /lib/template_framework/recipes/cucumber.rb: -------------------------------------------------------------------------------- 1 | if yes?("\n[Integration Testing] Would you like to add integration testing with Cucumber? [y|n]: ", Thor::Shell::Color::BLUE) 2 | 3 | gem 'cucumber-rails', '~> 1.3', :group => :test 4 | gem 'database_cleaner', :group => :test 5 | 6 | cucumber_generate_command = "cucumber:install" 7 | cucumber_generate_command << ' --skip-database' if templater.orm.mongoid? 8 | 9 | templater.post_bundler do 10 | generate cucumber_generate_command 11 | 12 | if templater.fixture_replacement.factory_girl? 13 | inject_into_file "features/support/env.rb", templater.load_snippet("factory_girl", 'cucumber'), :after => 'ActionController::Base.allow_rescue = false' 14 | elsif templater.fixture_replacement.fabrication? 15 | generate 'fabrication:cucumber_steps' 16 | end 17 | 18 | # Mongoid truncation strategy 19 | if templater.orm.mongoid? 20 | gsub_file 'features/support/env.rb', 'DatabaseCleaner.strategy = :transaction', 'DatabaseCleaner.strategy = :truncation' 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /lib/template_framework/recipes/default.rb: -------------------------------------------------------------------------------- 1 | # Delete all unnecessary files 2 | remove_file "README" 3 | remove_file "public/index.html" 4 | remove_file "public/robots.txt" 5 | remove_file "public/images/rails.png" 6 | 7 | # Create project files 8 | create_file 'README' 9 | create_file 'log/.gitkeep' 10 | create_file 'tmp/.gitkeep' 11 | 12 | get "http://html5shiv.googlecode.com/svn/trunk/html5.js", "public/javascripts/html5.js" 13 | 14 | apply templater.recipe('git') -------------------------------------------------------------------------------- /lib/template_framework/recipes/erb.rb: -------------------------------------------------------------------------------- 1 | remove_file 'app/views/layouts/application.html.erb' 2 | create_file 'app/views/layouts/application.html.erb', templater.load_template('app/views/layouts/application.html.erb', 'erb') 3 | -------------------------------------------------------------------------------- /lib/template_framework/recipes/fabrication.rb: -------------------------------------------------------------------------------- 1 | say("\nReplacing Fixtures with Fabrication\n", Thor::Shell::Color::YELLOW) 2 | 3 | gem 'fabrication' 4 | 5 | templater.post_bundler do 6 | environment templater.load_snippet("generator_#{templater.testing_framework.type}", 'fabrication') 7 | end -------------------------------------------------------------------------------- /lib/template_framework/recipes/factory_girl.rb: -------------------------------------------------------------------------------- 1 | say("\nReplacing Fixtures with FactoryGirl\n", Thor::Shell::Color::YELLOW) 2 | gem 'factory_girl_rails', '~> 1.2', :group => [:development, :test] 3 | 4 | templater.post_bundler do 5 | environment templater.load_snippet("generator_#{templater.testing_framework.type}", 'factory_girl') 6 | end -------------------------------------------------------------------------------- /lib/template_framework/recipes/fixture_replacement.rb: -------------------------------------------------------------------------------- 1 | say "\nWhich Fixture Replacement library would you like to use?\n", Thor::Shell::Color::BLUE 2 | 3 | fixture_replacement_options = { 4 | 'Option' => 'Factory Library', 5 | '1' => 'Fabrication', 6 | '2' => 'FactoryGirl' 7 | } 8 | 9 | print_table fixture_replacement_options.to_a, :ident => 4 10 | 11 | fixture_replacement_selection = ask("\nOption: ", Thor::Shell::Color::BLUE) 12 | if fixture_replacement_options.keys[1..-1].include?(fixture_replacement_selection) 13 | templater.fixture_replacement.type = fixture_replacement_options[fixture_replacement_selection].downcase.underscore.to_sym 14 | end 15 | 16 | $stdout << "\n\n" 17 | 18 | apply templater.recipe(templater.fixture_replacement.type) -------------------------------------------------------------------------------- /lib/template_framework/recipes/git.rb: -------------------------------------------------------------------------------- 1 | git :init 2 | 3 | append_file '.gitignore', templater.load_template('gitignore','git') -------------------------------------------------------------------------------- /lib/template_framework/recipes/haml.rb: -------------------------------------------------------------------------------- 1 | say "\nReplacing ERb with Haml as your Template Engine\n", Thor::Shell::Color::YELLOW 2 | 3 | gem "haml-rails" 4 | 5 | remove_file 'app/views/layouts/application.html.erb' 6 | create_file 'app/views/layouts/application.html.haml', templater.load_template('app/views/layouts/application.html.haml', 'haml') 7 | -------------------------------------------------------------------------------- /lib/template_framework/recipes/javascript_framework.rb: -------------------------------------------------------------------------------- 1 | say "\nWhich JavaScript Framework would you like to use?\n", Thor::Shell::Color::BLUE 2 | 3 | javascript_framework_options = { 4 | 'Option' => 'JavaScript Framework', 5 | '1' => 'jquery', 6 | '2' => 'prototype' 7 | } 8 | 9 | print_table javascript_framework_options.to_a, :ident => 4 10 | 11 | javascript_framework_selection = ask("\nOption: ", Thor::Shell::Color::BLUE) 12 | if javascript_framework_options.keys[1..-1].include?(javascript_framework_selection) 13 | templater.javascript_framework.type = javascript_framework_options[javascript_framework_selection].downcase.to_sym 14 | end 15 | 16 | $stdout << "\n\n" 17 | 18 | if templater.javascript_framework.jquery? 19 | gem 'jquery-rails' 20 | else 21 | gem 'prototype-rails' 22 | end 23 | 24 | remove_file 'app/assets/javascripts/application.js' 25 | create_file 'app/assets/javascripts/application.js', templater.load_template('app/assets/javascripts/application.js', templater.javascript_framework.type) 26 | -------------------------------------------------------------------------------- /lib/template_framework/recipes/mongoid.rb: -------------------------------------------------------------------------------- 1 | say("\nReplacing ActiveRecord with Mongoid\n", Thor::Shell::Color::YELLOW ) 2 | 3 | gem 'mongoid', '~> 2.4' 4 | gem 'bson_ext', '~> 1.6' 5 | 6 | gsub_file 'config/application.rb', 'require "active_record/railtie"', '# require "active_record/railtie"' 7 | 8 | templater.post_bundler do 9 | generate 'mongoid:config' 10 | run 'cp config/mongoid.yml config/mongoid.yml.example' 11 | create_file 'lib/tasks/assets.rake', templater.load_template('lib/tasks/assets.rake', 'mongoid') 12 | end 13 | -------------------------------------------------------------------------------- /lib/template_framework/recipes/orm.rb: -------------------------------------------------------------------------------- 1 | say "\nWhich ORM/ODM would you like to use?\n", Thor::Shell::Color::BLUE 2 | 3 | orm_options = { 4 | 'Option' => 'ORM/ODM', 5 | '1' => 'Mongoid', 6 | '2' => 'ActiveRecord' 7 | } 8 | 9 | print_table orm_options.to_a, :ident => 4 10 | 11 | orm_selection = ask("\nOption: ", Thor::Shell::Color::BLUE) 12 | if orm_options.keys[1..-1].include?(orm_selection) 13 | templater.orm.type = orm_options[orm_selection].underscore.to_sym 14 | end 15 | 16 | $stdout << "\n\n" 17 | 18 | apply templater.recipe('mongoid') if templater.orm.mongoid? 19 | apply templater.recipe('active_record') if templater.orm.active_record? 20 | -------------------------------------------------------------------------------- /lib/template_framework/recipes/pry.rb: -------------------------------------------------------------------------------- 1 | if yes?("\n[Console] Pry over IRB for your Rails console? [y|n]: ", Thor::Shell::Color::BLUE) 2 | gem 'pry-rails', group: :development 3 | gem 'pry-nav', group: :development 4 | end -------------------------------------------------------------------------------- /lib/template_framework/recipes/rcov.rb: -------------------------------------------------------------------------------- 1 | gem "rcov", :group => [:development] 2 | -------------------------------------------------------------------------------- /lib/template_framework/recipes/rspec.rb: -------------------------------------------------------------------------------- 1 | say("\nReplacing TestUnit with RSpec as your Testing Framework\n", Thor::Shell::Color::YELLOW ) 2 | 3 | gem 'rspec-rails', '~> 2.8', :group => [:development] 4 | 5 | remove_dir 'test' 6 | gsub_file 'config/application.rb', 'require "rails/test_unit/railtie"', '# require "rails/test_unit/railtie"' 7 | 8 | templater.post_bundler do 9 | generate 'rspec:install' 10 | 11 | spec_helper_path = 'spec/spec_helper.rb' 12 | 13 | gsub_file spec_helper_path, 'config.fixture_path = "#{::Rails.root}/spec/fixtures"', '' 14 | 15 | if templater.orm.mongoid? 16 | gsub_file spec_helper_path, /(config.use_transactional_fixtures = true)/, '# \1' 17 | inject_into_file spec_helper_path, templater.load_snippet('mongoid', 'rspec'), :after => "# config.use_transactional_fixtures = true\n" 18 | end 19 | end 20 | 21 | if templater.orm.mongoid? 22 | gem('mongoid-rspec', '~> 1.4', :group => :test) if yes?("\n\nWould you like to add Mongoid RSpec matchers? [y|n]: ", Thor::Shell::Color::BLUE) 23 | else 24 | apply templater.recipe('shoulda_matchers') 25 | end -------------------------------------------------------------------------------- /lib/template_framework/recipes/shoulda_matchers.rb: -------------------------------------------------------------------------------- 1 | gem('shoulda-matchers', '~> 1.0', :group => :test) if yes?("\n\nWould you like to add shoulda matchers? [y|n]: ", Thor::Shell::Color::BLUE) -------------------------------------------------------------------------------- /lib/template_framework/recipes/slim.rb: -------------------------------------------------------------------------------- 1 | say "\nReplacing ERb with Slim as your Template Engine\n", Thor::Shell::Color::YELLOW 2 | 3 | gem 'slim-rails' 4 | 5 | remove_file 'app/views/layouts/application.html.erb' 6 | create_file 'app/views/layouts/application.html.slim', templater.load_template('app/views/layouts/application.html.slim', 'slim') 7 | -------------------------------------------------------------------------------- /lib/template_framework/recipes/template_engine.rb: -------------------------------------------------------------------------------- 1 | say "\nWhich Template Engine would you like to use?\n", Thor::Shell::Color::BLUE 2 | 3 | template_engine_options = { 4 | 'Option' => 'Template Engine', 5 | '1' => 'Haml', 6 | '2' => 'Slim', 7 | '3' => 'ERB', 8 | } 9 | 10 | print_table template_engine_options.to_a, :ident => 4 11 | 12 | template_engine_selection = ask("\nOption: ", Thor::Shell::Color::BLUE) 13 | if template_engine_options.keys[1..-1].include?(template_engine_selection) 14 | templater.template_engine.type = template_engine_options[template_engine_selection].downcase.to_sym 15 | end 16 | 17 | $stdout << "\n\n" 18 | 19 | apply templater.recipe(templater.template_engine.type) -------------------------------------------------------------------------------- /lib/template_framework/recipes/test_unit.rb: -------------------------------------------------------------------------------- 1 | gsub_file 'config/application.rb', '# require "rails/test_unit/railtie"', 'require "rails/test_unit/railtie"' 2 | 3 | if yes?("\nWould you like to use Shoulda contexts? [y|n]: ", Thor::Shell::Color::BLUE) 4 | gem 'shoulda-context', :group => :test 5 | end 6 | 7 | apply templater.recipe('shoulda_matchers') 8 | 9 | -------------------------------------------------------------------------------- /lib/template_framework/recipes/testing_framework.rb: -------------------------------------------------------------------------------- 1 | say "\nWhich Testing Framework would you like to use?\n", Thor::Shell::Color::BLUE 2 | 3 | testing_framework_options = { 4 | 'Option' => 'Testing Framework', 5 | '1' => 'rspec', 6 | '2' => 'TestUnit' 7 | } 8 | 9 | print_table testing_framework_options.to_a, :ident => 4 10 | 11 | testing_framework_selection = ask("\nOption: ", Thor::Shell::Color::BLUE) 12 | if testing_framework_options.keys[1..-1].include?(testing_framework_selection) 13 | templater.testing_framework.type = testing_framework_options[testing_framework_selection].underscore.to_sym 14 | end 15 | 16 | $stdout << "\n\n" 17 | 18 | apply templater.recipe('rspec') if templater.testing_framework.rspec? 19 | apply templater.recipe('test_unit') if templater.testing_framework.test_unit? 20 | -------------------------------------------------------------------------------- /lib/template_framework/snippets/cucumber/factory_girl: -------------------------------------------------------------------------------- 1 | 2 | 3 | require 'factory_girl' 4 | require 'factory_girl/step_definitions' 5 | FactoryGirl.find_definitions -------------------------------------------------------------------------------- /lib/template_framework/snippets/fabrication/generator_rspec: -------------------------------------------------------------------------------- 1 | 2 | config.generators do |g| 3 | g.fixture_replacement :fabrication 4 | end 5 | -------------------------------------------------------------------------------- /lib/template_framework/snippets/fabrication/generator_test_unit: -------------------------------------------------------------------------------- 1 | 2 | config.generators do |g| 3 | g.test_framework :test_unit, :fixture_replacement => :fabrication 4 | g.fixture_replacement :fabrication, :dir => "test/fabricators" 5 | end 6 | -------------------------------------------------------------------------------- /lib/template_framework/snippets/factory_girl/generator_rspec: -------------------------------------------------------------------------------- 1 | 2 | config.generators do |g| 3 | g.fixture_replacement :factory_girl, :dir => 'spec/factories' 4 | end 5 | -------------------------------------------------------------------------------- /lib/template_framework/snippets/factory_girl/generator_test_unit: -------------------------------------------------------------------------------- 1 | 2 | config.generators do |g| 3 | g.test_framework :test_unit, :fixture_replacement => :factory_girl 4 | g.fixture_replacement :factory_girl, :dir => "test/factories" 5 | end -------------------------------------------------------------------------------- /lib/template_framework/snippets/rspec/mongoid: -------------------------------------------------------------------------------- 1 | 2 | config.before :each do 3 | Mongoid.master.collections.select {|c| c.name !~ /system/ }.each(&:drop) 4 | end 5 | 6 | -------------------------------------------------------------------------------- /lib/template_framework/template_runner.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift(File.expand_path('./../../', __FILE__)) 2 | 3 | require 'rails_templater' 4 | require File.join(File.dirname(__FILE__), 'core_ext.rb') 5 | 6 | %w(default orm testing_framework fixture_replacement code_coverage javascript_framework template_engine compass cucumber pry).each do |recipe| 7 | apply templater.recipe(recipe) 8 | end 9 | 10 | say("\nInitial generation complete\n", Thor::Shell::Color::YELLOW) 11 | 12 | say("\nBeginning bundle install\n", Thor::Shell::Color::YELLOW) 13 | run 'bundle install' 14 | say("\nbundle install complete\n", Thor::Shell::Color::YELLOW) 15 | 16 | execute_post_bundler_strategies 17 | 18 | git :add => "." 19 | git :commit => "-m 'Initial commit'" -------------------------------------------------------------------------------- /lib/template_framework/templates/active_record/config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite version 3.x 2 | # gem install sqlite3-ruby (not necessary on OS X Leopard) 3 | development: 4 | adapter: sqlite3 5 | database: db/development.sqlite3 6 | pool: 5 7 | timeout: 5000 8 | 9 | # Warning: The database defined as "test" will be erased and 10 | # re-generated from your development database when you run "rake". 11 | # Do not set this db to the same as development or production. 12 | test: 13 | adapter: sqlite3 14 | database: db/test.sqlite3 15 | pool: 5 16 | timeout: 5000 17 | 18 | production: 19 | adapter: sqlite3 20 | database: db/production.sqlite3 21 | pool: 5 22 | timeout: 5000 -------------------------------------------------------------------------------- /lib/template_framework/templates/erb/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <%= csrf_meta_tags %> 5 | <%= stylesheet_link_tag "application", :media => "all" %> 6 | 9 | 10 | 11 | <%= yield %> 12 | 13 | <%= javascript_include_tag "application" %> 14 | 15 | -------------------------------------------------------------------------------- /lib/template_framework/templates/git/gitignore: -------------------------------------------------------------------------------- 1 | config/database.yml 2 | config/mongoid.yml 3 | public/cache/ 4 | public/system/* 5 | tmp/restart.txt 6 | coverage/ 7 | coverage.data 8 | -------------------------------------------------------------------------------- /lib/template_framework/templates/haml/app/views/layouts/application.html.haml: -------------------------------------------------------------------------------- 1 | !!! 5 2 | %html 3 | %head 4 | = csrf_meta_tag 5 | /[if lt IE 9] 6 | = javascript_include_tag 'html5' 7 | %body 8 | = yield 9 | = javascript_include_tag 'application' -------------------------------------------------------------------------------- /lib/template_framework/templates/jquery/app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // the compiled file. 9 | // 10 | // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD 11 | // GO AFTER THE REQUIRES BELOW. 12 | // 13 | //= require jquery 14 | //= require_tree . -------------------------------------------------------------------------------- /lib/template_framework/templates/mongoid/features/step_definitions/mongoid_steps.rb: -------------------------------------------------------------------------------- 1 | Given /^an? (.+) exists with an? (.+) of "([^"]*)"$/ do |model, field, value| 2 | factory_name = model.gsub(' ', '_') 3 | Factory factory_name, field => value 4 | end -------------------------------------------------------------------------------- /lib/template_framework/templates/mongoid/lib/tasks/assets.rake: -------------------------------------------------------------------------------- 1 | asset_task = Rake::Task['assets:environment'] 2 | Rake.application.send(:eval, "@tasks.delete('assets:environment')") 3 | 4 | namespace :assets do 5 | task :environment do 6 | module ::Mongoid 7 | def load!(config_file) 8 | puts "Skipping connection to Mongo DB" 9 | end 10 | end 11 | 12 | asset_task.execute 13 | end 14 | end -------------------------------------------------------------------------------- /lib/template_framework/templates/prototype/app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // the compiled file. 9 | // 10 | // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD 11 | // GO AFTER THE REQUIRES BELOW. 12 | // 13 | //= require prototype 14 | //= require prototype_ujs 15 | //= require_tree . 16 | -------------------------------------------------------------------------------- /lib/template_framework/templates/slim/app/views/layouts/application.html.slim: -------------------------------------------------------------------------------- 1 | ! doctype 5 2 | html 3 | head 4 | = csrf_meta_tag 5 | /![if lt IE 9] 6 | = javascript_include_tag 'html5' 7 | /![endif] 8 | body 9 | = yield 10 | = javascript_include_tag 'application' -------------------------------------------------------------------------------- /rails_templater.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | require File.expand_path("../lib/rails_templater/version", __FILE__) 3 | 4 | Gem::Specification.new do |s| 5 | s.name = "rails_templater" 6 | s.version = RailsTemplater::VERSION 7 | s.platform = Gem::Platform::RUBY 8 | s.authors = ["Kevin Faustino"] 9 | s.email = ["kevin.faustino@gmail.com"] 10 | s.homepage = "http://rubygems.org/gems/rails_templater" 11 | s.summary = "Template generator for Ruby on Rails 3 applications" 12 | s.description = "Template generator for Ruby on Rails 3 applications" 13 | 14 | s.required_rubygems_version = ">= 1.3.6" 15 | s.rubyforge_project = "rails_templater" 16 | 17 | s.add_dependency "rails", "~> 3.1" 18 | s.add_development_dependency "bundler", "~> 1.0" 19 | s.add_development_dependency("rspec", ["~> 2.8"]) 20 | 21 | s.files = `git ls-files`.split("\n") 22 | s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact 23 | s.require_path = 'lib' 24 | end 25 | -------------------------------------------------------------------------------- /spec/fixtures/sample_snippet: -------------------------------------------------------------------------------- 1 | Foo Bar -------------------------------------------------------------------------------- /spec/fixtures/sample_template.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kfaustino/rails-templater/341010ec4f3143a905a1a62e5384088913e6ad51/spec/fixtures/sample_template.rb -------------------------------------------------------------------------------- /spec/rails_templater/fixture_replacement_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe RailsTemplater::FixtureReplacement do 4 | 5 | context "Fixture Replacement type has not been set" do 6 | its(:type) { should == :factory_girl } 7 | end 8 | 9 | context "Fxiture Replacement type has been set to FactoryGirl" do 10 | 11 | before(:each) do 12 | subject.type = :factory_girl 13 | end 14 | 15 | it { should be_factory_girl } 16 | 17 | end 18 | 19 | describe "#type" do 20 | 21 | it "allows setting of only supported Fixture Replacements" do 22 | expect { 23 | subject.type = :fixture 24 | }.to raise_error(RailsTemplater::NotSupportedError) 25 | end 26 | 27 | end 28 | 29 | end -------------------------------------------------------------------------------- /spec/rails_templater/javascript_framework_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe RailsTemplater::JavaScriptFramework do 4 | 5 | context "JavaScript Framework type has not been set" do 6 | its(:type) { should == :jquery } 7 | end 8 | 9 | context "JavaScript Framework type has been set to jQuery" do 10 | 11 | before(:each) do 12 | subject.type = :jquery 13 | end 14 | 15 | it { should be_jquery } 16 | 17 | end 18 | 19 | context "JavaScript Framework type has been set to Prototype" do 20 | 21 | before(:each) do 22 | subject.type = :prototype 23 | end 24 | 25 | it { should be_prototype } 26 | 27 | end 28 | 29 | it "only sets type to supported JavaScript Frameworks" do 30 | expect{ 31 | subject.type = :random 32 | }.to raise_error(RailsTemplater::NotSupportedError) 33 | end 34 | 35 | 36 | end -------------------------------------------------------------------------------- /spec/rails_templater/orm_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe RailsTemplater::Orm do 4 | 5 | it "defaults to Mongoid" do 6 | subject.type.should == :mongoid 7 | end 8 | 9 | context "ORM type is ActiveRecord" do 10 | 11 | before(:each) do 12 | subject.type = :active_record 13 | end 14 | 15 | it { should be_active_record } 16 | 17 | end 18 | 19 | context "ORM type is Mongoid" do 20 | 21 | before(:each) do 22 | subject.type = :mongoid 23 | end 24 | 25 | it { should be_mongoid } 26 | 27 | end 28 | 29 | it "only sets type to supported ORMs" do 30 | expect{ 31 | subject.type = :mongo_mapper 32 | }.to raise_error(RailsTemplater::NotSupportedError) 33 | end 34 | 35 | 36 | end -------------------------------------------------------------------------------- /spec/rails_templater/template_engine_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe RailsTemplater::TemplateEngine do 4 | 5 | context "Template Engine type has not been set" do 6 | its(:type) { should == :haml } 7 | end 8 | 9 | context "Template Engine type has been set to Haml" do 10 | 11 | before(:each) do 12 | subject.type = :haml 13 | end 14 | 15 | it { should be_haml } 16 | 17 | end 18 | 19 | context "Template Engine type has been set to Slim" do 20 | 21 | before(:each) do 22 | subject.type = :slim 23 | end 24 | 25 | it { should be_slim } 26 | 27 | end 28 | 29 | context "Template Engine type has been set to ERb" do 30 | 31 | before(:each) do 32 | subject.type = :erb 33 | end 34 | 35 | it { should be_erb } 36 | 37 | end 38 | 39 | it "only sets type to supported Template Engines" do 40 | expect{ 41 | subject.type = :random 42 | }.to raise_error(RailsTemplater::NotSupportedError) 43 | end 44 | 45 | 46 | end -------------------------------------------------------------------------------- /spec/rails_templater/templater_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe RailsTemplater::Templater do 4 | 5 | let(:group) { 'sample' } 6 | 7 | its(:fixture_replacement) { should be_kind_of(RailsTemplater::FixtureReplacement) } 8 | its(:javascript_framework) { should be_kind_of(RailsTemplater::JavaScriptFramework) } 9 | its(:orm) { should be_kind_of(RailsTemplater::Orm) } 10 | its(:testing_framework) { should be_kind_of(RailsTemplater::TestingFramework) } 11 | 12 | it "generates a recipe path based on a name" do 13 | subject.recipe("mongoid").should == File.expand_path('recipes/mongoid.rb', TEMPLATE_FRAMEWORK_PATH) 14 | end 15 | 16 | it "generates a snippet path" do 17 | subject.snippet_path("cucumber").should == File.expand_path('snippets/cucumber', TEMPLATE_FRAMEWORK_PATH) 18 | end 19 | 20 | it "generates a template path" do 21 | subject.template_path("haml").should == File.expand_path('templates/haml', TEMPLATE_FRAMEWORK_PATH) 22 | end 23 | 24 | describe "#load_snippet" do 25 | 26 | let(:snippet_name) { 'sample_snippet' } 27 | 28 | before(:each) do 29 | subject.stub(:snippet_path) { FIXTURE_PATH } 30 | end 31 | 32 | it "loads a snippet" do 33 | subject.load_snippet(snippet_name, group).should == load_fixture(snippet_name) 34 | end 35 | 36 | end 37 | 38 | describe "#load_template" do 39 | 40 | let(:template_name) { 'sample_template.rb' } 41 | 42 | before(:each) do 43 | subject.stub(:template_path) { FIXTURE_PATH } 44 | end 45 | 46 | it "loads a template" do 47 | subject.load_template(template_name, group).should == load_fixture(template_name) 48 | end 49 | 50 | end 51 | 52 | describe "#post_bundler" do 53 | 54 | it "adds blocks to post_bundler_strategies" do 55 | subject.post_bundler do 56 | "Hi" 57 | end 58 | subject.post_bundler_strategies.should have(1).item 59 | result = subject.post_bundler_strategies.first.call 60 | result.should == 'Hi' 61 | end 62 | 63 | end 64 | 65 | end 66 | -------------------------------------------------------------------------------- /spec/rails_templater/testing_framework_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe RailsTemplater::TestingFramework do 4 | 5 | it "defaults to RSpec" do 6 | subject.type.should == :rspec 7 | end 8 | 9 | context "Testing Framework type is set to RSpec" do 10 | 11 | before(:each) do 12 | subject.type = :rspec 13 | end 14 | 15 | it { should be_rspec } 16 | 17 | end 18 | 19 | context "Testing Framework type is set to TestUnit" do 20 | 21 | before(:each) do 22 | subject.type = :test_unit 23 | end 24 | 25 | it { should be_test_unit } 26 | 27 | end 28 | 29 | it "only sets type to supported Test Frameworks" do 30 | expect{ 31 | subject.type = :random 32 | }.to raise_error(RailsTemplater::NotSupportedError) 33 | end 34 | 35 | end -------------------------------------------------------------------------------- /spec/rails_templater_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe RailsTemplater do 4 | 5 | subject { RailsTemplater } 6 | 7 | its(:template_runner) { should == File.expand_path('template_runner.rb', TEMPLATE_FRAMEWORK_PATH)} 8 | 9 | end -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | begin 2 | require 'bundler' 3 | Bundler.setup(:default, :development) 4 | rescue LoadError => e 5 | # Fall back on doing an unlocked resolve at runtime. 6 | STDERR.puts e.message 7 | STDERR.puts "Try running `bundle install`." 8 | exit! 9 | end 10 | 11 | require 'rails_templater' 12 | require 'rspec' 13 | 14 | # # Requires supporting files with custom matchers and macros, etc, 15 | # in ./support/ and its subdirectories. 16 | Dir[File.join(File.dirname(__FILE__),'/support/**/*.rb')].each {|f| require f} 17 | 18 | RSpec.configure do |config| 19 | config.mock_with :rspec 20 | end -------------------------------------------------------------------------------- /spec/support/fixtures.rb: -------------------------------------------------------------------------------- 1 | FIXTURE_PATH = File.join(File.dirname(__FILE__), '..', 'fixtures') 2 | 3 | def load_fixture(name) 4 | File.read File.expand_path(name, FIXTURE_PATH) 5 | end -------------------------------------------------------------------------------- /spec/support/paths.rb: -------------------------------------------------------------------------------- 1 | TEMPLATE_FRAMEWORK_PATH = File.join(File.dirname(__FILE__), '..', '..','lib', 'template_framework') --------------------------------------------------------------------------------