Skip to content

Commit

Permalink
[#92] Add --webkit flag
Browse files Browse the repository at this point in the history
By default, Capybara Webkit will be installed. However, Some folks don't
want/need it, and having QT as a dependency of Suspenders drastically
raises the bar in terms of ease of installation. See:

#70
  • Loading branch information
Dan Croak committed Aug 3, 2012
1 parent da91a2b commit 826c856
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 48 deletions.
20 changes: 13 additions & 7 deletions README.md
Expand Up @@ -27,29 +27,27 @@ which will be appended to the default generated projectname/Gemfile.

It includes application gems like:

* [Paperclip](https://github.com/thoughtbot/paperclip) for file uploads
* [Formtastic](https://github.com/justinfrench/formtastic) for better forms
* [Airbrake](https://github.com/airbrake/airbrake) for exception notification
* [Flutie](https://github.com/thoughtbot/flutie) for default CSS styles
* [Bourbon](https://github.com/thoughtbot/bourbon) for classy sass mixins
* [Clearance](https://github.com/thoughtbot/clearance) for authentication
* [Flutie](https://github.com/thoughtbot/flutie) for default CSS styles
* [Formtastic](https://github.com/justinfrench/formtastic) for better forms
* [Paperclip](https://github.com/thoughtbot/paperclip) for file uploads

And testing gems like:

* [Bourne](https://github.com/thoughtbot/bourne) and Mocha for stubbing and spying
* [Cucumber, Capybara, and Capybara Webkit](http://robots.thoughtbot.com/post/4583605733/capybara-webkit) for integration testing, including Javascript behavior
* [RSpec](https://github.com/rspec/rspec) for awesome, readable isolation testing
* [Factory Girl](https://github.com/thoughtbot/factory_girl) for easier creation of test data
* [RSpec](https://github.com/rspec/rspec) for awesome, readable isolation testing
* [Shoulda Matchers](http://github.com/thoughtbot/shoulda-matchers) for frequently needed Rails and RSpec matchers
* [Timecop](https://github.com/jtrupiano/timecop) for dealing with time
* [Bourne](https://github.com/thoughtbot/bourne) and Mocha for stubbing and spying
* [email_spec](https://github.com/bmabey/email-spec) for testing emails.

Other goodies
-------------

Suspenders also comes with:

* [jQuery](https://github.com/jquery/jquery) for Javascript pleasantry
* Rails' flashes set up and in application layout.
* A few nice time formats.

Expand All @@ -72,6 +70,14 @@ You can optionally not include Clearance:

suspenders app --clearance false

Capybara Webkit
---------------

You can optionally not include Capybara Webkit (which depends on QT being
installed on your machine):

suspenders app --webkit false

Dependencies
------------

Expand Down
10 changes: 10 additions & 0 deletions features/clearance_false.feature
@@ -0,0 +1,10 @@
@disable-bundler
Feature: Skipping Clearance

Scenario: --clearance=false
When I suspend a project called "test_project" with:
| argument | value |
| --clearance | false |
And I cd to the "test_project" root
Then "clearance" should not be installed
And I can cleanly rake the project
@@ -1,7 +1,7 @@
@disable-bundler
Feature: Creating a Heroku app when suspending a project
Feature: Creating a Heroku app

Scenario: User uses the --heroku=true command line argument
Scenario: --heroku=true
When I suspend a project called "test_project" with:
| argument | value |
| --heroku | true |
Expand Down
13 changes: 0 additions & 13 deletions features/skipping_clearance.feature

This file was deleted.

5 changes: 0 additions & 5 deletions features/step_definitions/gem_steps.rb

This file was deleted.

3 changes: 0 additions & 3 deletions features/step_definitions/heroku_steps.rb

This file was deleted.

Expand Up @@ -53,3 +53,17 @@
Then I see a successful response in the shell
}
end

Then /^"(.*)" should not be installed$/ do |gem_name|
in_current_dir do
system("bundle show #{gem_name} 2>&1 > /dev/null").should be_false
end
end

Then /^"(.*)" should not be included in "(.*)"$/ do |content, file_path|
check_file_content file_path, content, false
end

Then /^the "([^"]*)" heroku app should exist$/ do |app_name|
FakeHeroku.should have_created_app(app_name)
end
11 changes: 11 additions & 0 deletions features/webkit_false.feature
@@ -0,0 +1,11 @@
@disable-bundler
Feature: Skipping Capybara Webkit

Scenario: --webkit=false
When I suspend a project called "test_project" with:
| argument | value |
| --webkit | false |
And I cd to the "test_project" root
Then "capybara-webkit" should not be installed
And "webkit" should not be included in "features/support/env.rb"
And I can cleanly rake the project
33 changes: 24 additions & 9 deletions lib/suspenders/app_builder.rb
Expand Up @@ -55,17 +55,29 @@ def add_jquery_ui
end

def use_postgres_config_template
template 'postgresql_database.yml.erb', 'config/database.yml', :force => true
template 'postgresql_database.yml.erb', 'config/database.yml',
:force => true
end

def create_database
bundle_command 'exec rake db:create'
end

def include_custom_gems
def add_custom_gems
additions_path = find_in_source_paths 'Gemfile_additions'
new_gems = File.open(additions_path).read
inject_into_file 'Gemfile', "\n#{new_gems}", :after => /gem 'jquery-rails'/
inject_into_file 'Gemfile', "\n#{new_gems}",
:after => /gem 'jquery-rails'/
end

def add_clearance_gem
inject_into_file 'Gemfile', "\ngem 'clearance'",
:after => /gem 'jquery-rails'/
end

def add_capybara_webkit_gem
inject_into_file 'Gemfile', "\n gem 'capybara-webkit', '~> 0.11.0'",
:after => /gem 'cucumber-rails', '1.3.0'/
end

def configure_rspec
Expand Down Expand Up @@ -95,11 +107,18 @@ def generate_rspec
'# config.mock_with :mocha', 'config.mock_with :mocha'
end

def generate_cucumber
def generate_cucumber(options = {})
generate 'cucumber:install', '--rspec', '--capybara'
copy_file 'features_support_env.rb', 'features/support/env.rb', :force => true
inject_into_file 'config/cucumber.yml',
' -drb -r features', :after => %{default: <%= std_opts %> features}
copy_file 'features_support_env.rb', 'features/support/env.rb',
:force => true

if options[:webkit]
inject_into_file 'features/support/env.rb',
"\n Capybara.javascript_driver = :webkit",
:after => /Capybara.default_selector = :css/
end
end

def setup_guard_spork
Expand Down Expand Up @@ -206,9 +225,5 @@ def setup_default_rake_task
'task(:default).clear\ntask :default => [:spec, :cucumber]'
end
end

def add_clearance_gem
inject_into_file 'Gemfile', "\ngem 'clearance'", :after => /gem 'jquery-rails'/
end
end
end
21 changes: 14 additions & 7 deletions lib/suspenders/generators/app_generator.rb
Expand Up @@ -3,17 +3,20 @@

module Suspenders
class AppGenerator < Rails::Generators::AppGenerator
class_option :clearance, :type => :boolean, :aliases => '-C', :default => true,
:desc => 'Add the Clearance Rails authentication library'

class_option :database, :type => :string, :aliases => '-d', :default => 'postgresql',
:desc => "Preconfigure for selected database (options: #{DATABASES.join('/')})"

class_option :skip_test_unit, :type => :boolean, :aliases => '-T', :default => true,
:desc => 'Skip Test::Unit files'

class_option :heroku, :type => :boolean, :aliases => '-H', :default => false,
:desc => 'Create staging and production heroku apps'

class_option :clearance, :type => :boolean, :aliases => '-C', :default => true,
:desc => 'Add the clearance Rails authentication library'
class_option :skip_test_unit, :type => :boolean, :aliases => '-T', :default => true,
:desc => 'Skip Test::Unit files'

class_option :webkit, :type => :boolean, :aliases => '-W', :default => true,
:desc => 'Add the Capybara Webkit Javascript integration testing library'

def finish_template
invoke :suspenders_customization
Expand Down Expand Up @@ -75,12 +78,16 @@ def add_jquery_ui
end

def customize_gemfile
build :include_custom_gems
build :add_custom_gems

if options[:clearance]
build :add_clearance_gem
end

if options[:webkit]
build :add_capybara_webkit_gem
end

bundle_command 'install'
end

Expand All @@ -99,7 +106,7 @@ def configure_app
build :configure_rspec
build :configure_action_mailer
build :generate_rspec
build :generate_cucumber
build :generate_cucumber, :webkit => options[:webkit]
build :setup_guard_spork
build :add_email_validator
build :setup_default_rake_task
Expand Down
1 change: 0 additions & 1 deletion templates/Gemfile_additions
Expand Up @@ -19,7 +19,6 @@ end

group :test do
gem 'cucumber-rails', '1.3.0'
gem 'capybara-webkit', '~> 0.11.0'
gem 'factory_girl_rails'
gem 'bourne'
gem 'database_cleaner'
Expand Down
1 change: 0 additions & 1 deletion templates/features_support_env.rb
Expand Up @@ -6,7 +6,6 @@
require 'cucumber/rails'

Capybara.default_selector = :css
Capybara.javascript_driver = :webkit
DatabaseCleaner.strategy = :truncation
end

Expand Down

0 comments on commit 826c856

Please sign in to comment.