Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rspec builder #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/bootstrappers
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
Expand Down
2 changes: 1 addition & 1 deletion lib/bootstrappers/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class AppBuilder < Rails::AppBuilder

include Bootstrappers::Actions
include Bootstrappers::LayoutActions
include Bootstrappers::RspecActions


def raise_delivery_errors
Expand Down Expand Up @@ -87,6 +88,5 @@ def use_mysql_config_template

end


end
end
5 changes: 5 additions & 0 deletions lib/bootstrappers/generators/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -142,6 +143,10 @@ def init_git
build :init_git
end

def setup_rspec
build :setup_rspec
end

protected

def get_builder_class
Expand Down
48 changes: 48 additions & 0 deletions lib/bootstrappers/rspec_actions.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions templates/rspec_config_application
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions templates/rspec_gemfile
Original file line number Diff line number Diff line change
@@ -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