Browse Source

Merge pull request #1293 from dsander/optional-spring

Allow to use spring by setting SPRING in .env
Dominik Sander 9 years ago
parent
commit
800e055b47
7 changed files with 49 additions and 12 deletions
  1. 16 11
      Gemfile
  2. 5 0
      Gemfile.lock
  3. 1 1
      Guardfile
  4. 4 0
      bin/rails
  5. 4 0
      bin/rake
  6. 4 0
      bin/rspec
  7. 15 0
      bin/spring

+ 16 - 11
Gemfile

@@ -12,6 +12,17 @@ GemfileHelper.load_dotenv do |dotenv_dir|
   end
 end
 
+# Introduces a scope for gem loading based on a condition
+def if_true(condition)
+  if condition
+    yield
+  else
+    # When not including the gems, we still want our Gemfile.lock
+    # to include them, so we scope them to an unsupported platform.
+    platform :ruby_18, &proc
+  end
+end
+
 # Optional libraries.  To conserve RAM, comment out any that you don't need,
 # then run `bundle` and commit the updated Gemfile and Gemfile.lock.
 gem 'twilio-ruby', '~> 3.11.5'    # TwilioAgent
@@ -118,6 +129,11 @@ group :development do
   gem 'capistrano-rails', '~> 1.1'
   gem 'capistrano-bundler', '~> 1.1.4'
 
+  if_true(ENV['SPRING']) do
+    gem 'spring-commands-rspec', '~> 1.0.4'
+    gem 'spring', '~> 1.6.3'
+  end
+
   group :test do
     gem 'coveralls', require: false
     gem 'delorean'
@@ -147,17 +163,6 @@ gem 'tzinfo', '>= 1.2.0'	# required by rails; 1.2.0 has support for *BSD and Sol
 gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]
 
 
-# Introduces a scope for gem loading based on a condition
-def if_true(condition)
-  if condition
-    yield
-  else
-    # When not including the gems, we still want our Gemfile.lock
-    # to include them, so we scope them to an unsupported platform.
-    platform :ruby_18, &proc
-  end
-end
-
 on_heroku = ENV['ON_HEROKU'] ||
             ENV['HEROKU_POSTGRESQL_ROSE_URL'] ||
             ENV['HEROKU_POSTGRESQL_GOLD_URL'] ||

+ 5 - 0
Gemfile.lock

@@ -496,6 +496,9 @@ GEM
     slop (3.6.0)
     spectrum-rails (1.3.4)
       railties (>= 3.1)
+    spring (1.6.3)
+    spring-commands-rspec (1.0.4)
+      spring (>= 0.9.1)
     sprockets (3.5.2)
       concurrent-ruby (~> 1.0)
       rack (> 1, < 3)
@@ -653,6 +656,8 @@ DEPENDENCIES
   shoulda-matchers
   slack-notifier (~> 1.0.0)
   spectrum-rails
+  spring (~> 1.6.3)
+  spring-commands-rspec (~> 1.0.4)
   string-scrub
   therubyracer (~> 0.12.2)
   tumblr_client!

+ 1 - 1
Guardfile

@@ -8,7 +8,7 @@ guard 'livereload' do
   watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|js|html|png|jpg))).*}) { |m| "/assets/#{m[3]}" }
 end
 
-guard :rspec, cmd: 'bundle exec rspec' do
+guard :rspec, cmd: ENV['SPRING'] ? 'bundle exec spring rspec' : 'bundle exec rspec' do
   watch(%r{^spec/.+_spec\.rb$})
   watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
   watch('spec/spec_helper.rb')  { "spec" }

+ 4 - 0
bin/rails

@@ -1,4 +1,8 @@
 #!/usr/bin/env ruby
+begin
+  load File.expand_path("../spring", __FILE__)
+rescue LoadError
+end
 APP_PATH = File.expand_path('../../config/application',  __FILE__)
 require_relative '../config/boot'
 require 'rails/commands'

+ 4 - 0
bin/rake

@@ -1,4 +1,8 @@
 #!/usr/bin/env ruby
+begin
+  load File.expand_path("../spring", __FILE__)
+rescue LoadError
+end
 require_relative '../config/boot'
 require 'rake'
 Rake.application.run

+ 4 - 0
bin/rspec

@@ -1,3 +1,7 @@
 #!/usr/bin/env ruby
+begin
+  load File.expand_path("../spring", __FILE__)
+rescue LoadError
+end
 require 'bundler/setup'
 load Gem.bin_path('rspec-core', 'rspec')

+ 15 - 0
bin/spring

@@ -0,0 +1,15 @@
+#!/usr/bin/env ruby
+
+# This file loads spring without using Bundler, in order to be fast.
+# It gets overwritten when you run the `spring binstub` command.
+
+unless defined?(Spring)
+  require "rubygems"
+  require "bundler"
+
+  if match = Bundler.default_lockfile.read.match(/^GEM$.*?^    (?:  )*spring \((.*?)\)$.*?^$/m)
+    Gem.paths = { "GEM_PATH" => [Bundler.bundle_path.to_s, *Gem.path].uniq }
+    gem "spring", match[1]
+    require "spring/binstub"
+  end
+end