Skip to content
Browse files

make the test suite run in 15 seconds instead of 60, using spork.

to run spork, use 'bundle exec spork' in one terminal, to start the daemon. in another, use 'bundle exec rspec spec' to run the suite.

overview of changes:
  * add spork to Gemfile
  * sort out spec_helper into 'prefork' and 'each run' blocks for spork
  * modify .rspec with --drb, so it connects to the spork process instead of loading rails. <-- this is the important bit
  * update the readme to inform the user about the new sweetness! <-- the other important bit

for more info, check out the lovely tutorial on http://www.rubyinside.com/how-to-rails-3-and-rspec-2-4336.html
  • Loading branch information...
1 parent 3cdeda4 commit 50e41d0a35d74fe0635de216e887ed57a58a2426 @YenTheFirst YenTheFirst committed
Showing with 60 additions and 66 deletions.
  1. +1 −1 .rspec
  2. +1 −0 Gemfile
  3. +3 −1 Gemfile.lock
  4. +4 −30 README.md
  5. +51 −34 spec/spec_helper.rb
View
2 .rspec
@@ -1 +1 @@
---colour
+--colour --drb
View
1 Gemfile
@@ -15,5 +15,6 @@ group :test, :development do
gem 'factory_girl_rails'
gem 'rspec-rails', '~> 2.4'
gem 'simplecov'
+ gem 'spork', '~> 0.9.0.rc'
end
View
4 Gemfile.lock
@@ -13,7 +13,7 @@ GIT
rails_admin (0.0.1)
builder (~> 2.1.0)
fastercsv
- haml (>= 3.0.0, < 3.2.0)
+ haml (< 3.2.0, >= 3.0.0)
rails (~> 3.0.7)
GEM
@@ -131,6 +131,7 @@ GEM
sinatra (1.2.6)
rack (~> 1.1)
tilt (< 2.0, >= 1.2.2)
+ spork (0.9.0.rc9)
sqlite3 (1.3.3)
thor (0.14.6)
tilt (1.3.2)
@@ -158,4 +159,5 @@ DEPENDENCIES
resque
rspec-rails (~> 2.4)
simplecov
+ spork (~> 0.9.0.rc)
sqlite3
View
34 README.md
@@ -1,31 +1,5 @@
-This is a Rails app that does things
-
-Users can't register, they can only be provisioned by admins.
-To provision, go to rails console, and issue User.create(:email=>"their_email@place.ya"). They'll be sent a confirmation email (or in dev mode, it'll be printed in logs)
-
-Deploying:
-
-the following environment variables must be set:
-FLOCKY_TOKEN,FLOCKY_USERNAME,FLOCKY_PASSWORD,FLOCKY_APPNUM
-These are the API token, username, password, and appnumber for your tropo app
-
-you can get your appnumber by visiting https://api.tropo.com/v1/applications
-
-App domain classtalk.org redirects from heroku URL using heroku config variable. To set the key APP_DOMAIN use: heroku config:add APP_DOMAIN=your.domain.com --app <heroku-appname>
-
-
-on heroku, the following plugins are used:
-sendgrid, cloudmailin, cron
-
-Setting up incoming email
-1) install the cloudmailin plugin on heroku
-2) look at 'heroku config' for your app, to get the username and password
-3) on cloudmailin.com, add the desired incoming domain as a custom domain
-4) on your DNS server, add 'clients.cloudmailin.net' as a CNAME for your desired subdomain/domain.
-resources: http://docs.cloudmailin.com/custom_domains, http://devcenter.heroku.com/articles/cloudmailin
-
-[![Code for America Tracker](http://stats.codeforamerica.org/codeforamerica/homework_notifier.png)](http://stats.codeforamerica.org/projects/homework_notifier)
-
-
Testing:
-the APP_DOMAIN environment variable must be set, to "test.host"
+you can type 'bundle exec rake', and it will run the tests - slowly.
+fortunately, we have spork, to speed things up!
+in one terminal, start spork with 'bundle exec spork'
+now, in another terminal, you can run your tests with 'bundle exec rspec spec'. this will run the full suite, with no overhead of loading rails!
View
85 spec/spec_helper.rb
@@ -1,36 +1,53 @@
-# This file is copied to spec/ when you run 'rails generate rspec:install'
-ENV["RAILS_ENV"] ||= 'test'
-require 'simplecov'
-SimpleCov.start
-require File.expand_path("../../config/environment", __FILE__)
-require 'rspec/rails'
-
-# Requires supporting ruby files with custom matchers and macros, etc,
-# in spec/support/ and its subdirectories.
-Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
-
-RSpec.configure do |config|
- # == Mock Framework
- #
- # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
- #
- # config.mock_with :mocha
- # config.mock_with :flexmock
- # config.mock_with :rr
- config.mock_with :rspec
-
- # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
-
- # If you're not using ActiveRecord, or you'd prefer not to run each of your
- # examples within a transaction, remove the following line or assign false
- # instead of true.
- config.use_transactional_fixtures = true
-
- config.include Devise::TestHelpers, :type => :controller
- def login(user=Factory.create(:user))
- @request.env["devise.mapping"] = Devise.mappings[:admin]
- user.confirm!
- sign_in user
+require 'spork'
+
+Spork.prefork do
+ # Loading more in this block will cause your tests to run faster. However,
+ # if you change any configuration or code from libraries loaded here, you'll
+ # need to restart spork for it take effect.
+
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
+ ENV["RAILS_ENV"] ||= 'test'
+ require 'simplecov'
+ SimpleCov.start
+ require File.expand_path("../../config/environment", __FILE__)
+ require 'rspec/rails'
+
+ # Requires supporting ruby files with custom matchers and macros, etc,
+ # in spec/support/ and its subdirectories.
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
+
+
+ RSpec.configure do |config|
+ # == Mock Framework
+ #
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+ config.mock_with :rspec
+
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, remove the following line or assign false
+ # instead of true.
+ config.use_transactional_fixtures = true
+
+ config.include Devise::TestHelpers, :type => :controller
+ def login(user=Factory.create(:user))
+ @request.env["devise.mapping"] = Devise.mappings[:admin]
+ user.confirm!
+ sign_in user
+ end
end
+
+
end
+
+Spork.each_run do
+ # This code will be run each time you run your specs.
+
+end
+

0 comments on commit 50e41d0

Please sign in to comment.
Something went wrong with that request. Please try again.