Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Rspec builder #9

Open
wants to merge 1 commit into from

1 participant

@marsz
  • Asking respec setup.
  • Auto insert rspec related rubygems into Gemfile and bundle install
  • Add devise rspec hepler to spec/spec_helper.rb
  • Disable generate helper, helper_spec, assets files when generating Controller.
  • Generate FactoryGirl fixtures in spec/factories when generating Model.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 1, 2013
  1. @marsz

    setup rspec

    marsz authored
This page is out of date. Refresh to see the latest.
View
1  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__))
View
2  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
View
5 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
View
48 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
View
12 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
View
8 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
Something went wrong with that request. Please try again.