diff --git a/bin/bootstrappers b/bin/bootstrappers index 0c453af..09d2919 100755 --- a/bin/bootstrappers +++ b/bin/bootstrappers @@ -3,6 +3,7 @@ require File.expand_path(File.join('..', 'lib', 'bootstrappers', 'generators', 'app_generator'), File.dirname(__FILE__)) require File.expand_path(File.join('..', 'lib', 'bootstrappers', 'actions'), File.dirname(__FILE__)) require File.expand_path(File.join('..', 'lib', 'bootstrappers', 'layout_actions'), File.dirname(__FILE__)) +require File.expand_path(File.join('..', 'lib', 'bootstrappers', 'rspec_actions'), File.dirname(__FILE__)) require File.expand_path(File.join('..', 'lib', 'bootstrappers', 'app_builder'), File.dirname(__FILE__)) templates_root = File.expand_path(File.join("..", "templates"), File.dirname(__FILE__)) diff --git a/lib/bootstrappers/app_builder.rb b/lib/bootstrappers/app_builder.rb index 6e60dc2..4461d82 100644 --- a/lib/bootstrappers/app_builder.rb +++ b/lib/bootstrappers/app_builder.rb @@ -3,6 +3,7 @@ class AppBuilder < Rails::AppBuilder include Bootstrappers::Actions include Bootstrappers::LayoutActions + include Bootstrappers::RspecActions def raise_delivery_errors @@ -87,6 +88,5 @@ def use_mysql_config_template end - end end diff --git a/lib/bootstrappers/generators/app_generator.rb b/lib/bootstrappers/generators/app_generator.rb index d7566ac..bca0638 100644 --- a/lib/bootstrappers/generators/app_generator.rb +++ b/lib/bootstrappers/generators/app_generator.rb @@ -31,6 +31,7 @@ def bootstrappers_customization invoke :add_common_method_to_application_controller invoke :setup_root_route invoke :setup_git + invoke :setup_rspec end def remove_files_we_dont_need @@ -142,6 +143,10 @@ def init_git build :init_git end + def setup_rspec + build :setup_rspec + end + protected def get_builder_class diff --git a/lib/bootstrappers/rspec_actions.rb b/lib/bootstrappers/rspec_actions.rb new file mode 100644 index 0000000..15b8686 --- /dev/null +++ b/lib/bootstrappers/rspec_actions.rb @@ -0,0 +1,48 @@ +module Bootstrappers + module RspecActions + + def setup_rspec + use_rspec = ask("Setup Rspec for testing? [Y/n]") + if use_rspec.downcase != "n" + remove_dir "test" + rspec_insert_into_gemfile + bundle_command 'install' + generate 'rspec:install' + rspec_insert_into_config_application + rspec_modify_spec_helper + end + end + + private + + def rspec_insert_into_gemfile + inject_into_file( + "Gemfile", + File.open(find_in_source_paths('rspec_gemfile')).read, + :after => "\nend\n" + ) + end + + def rspec_insert_into_config_application + inject_into_file( + "config/application.rb", + File.open(find_in_source_paths('rspec_config_application')).read, + :before => " end\n" + ) + end + + def rspec_modify_spec_helper + inject_into_file( + "spec/spec_helper.rb", + " config.mock_with :rspec\n", + :after => "config.mock_with :rr\n" + ) + + inject_into_file( + "spec/spec_helper.rb", + "\n config.include Devise::TestHelpers, :type => :controller\n", + :before => "\nend\n" + ) + end + end +end \ No newline at end of file diff --git a/templates/rspec_config_application b/templates/rspec_config_application new file mode 100644 index 0000000..72990ab --- /dev/null +++ b/templates/rspec_config_application @@ -0,0 +1,12 @@ + + # disable some file generators + config.generators.stylesheets = false + config.generators.javascripts = false + config.generators.helper = false + config.generators.helper_specs = false + + # factory gilr + config.generators do |g| + g.test_framework :rspec, :fixture => true, :views => false, :fixture_replacement => :factory_girl + g.fixture_replacement :factory_girl, :dir => "spec/factories" + end diff --git a/templates/rspec_gemfile b/templates/rspec_gemfile new file mode 100644 index 0000000..9c47ada --- /dev/null +++ b/templates/rspec_gemfile @@ -0,0 +1,8 @@ + +group :development, :test do + gem "rspec" + gem "rspec-rails" + gem "shoulda-matchers" + gem "factory_girl_rails" + gem 'turn', '~> 0.8.3', :require => false +end