milhouse-spork 0.7.5.1 → 0.7.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +19 -19
- data/README.rdoc +99 -99
- data/assets/bootstrap.rb +29 -29
- data/bin/spork +20 -20
- data/features/cucumber_rails_integration.feature +118 -118
- data/features/diagnostic_mode.feature +40 -40
- data/features/rails_delayed_loading_workarounds.feature +115 -115
- data/features/rspec_rails_integration.feature +93 -93
- data/features/spork_debugger.feature +108 -108
- data/features/steps/general_steps.rb +3 -3
- data/features/steps/rails_steps.rb +52 -52
- data/features/steps/sandbox_steps.rb +115 -115
- data/features/support/background_job.rb +63 -63
- data/features/support/env.rb +111 -111
- data/features/unknown_app_framework.feature +41 -41
- data/geminstaller.yml +9 -9
- data/lib/spork/app_framework/rails.rb +157 -157
- data/lib/spork/app_framework/rails_stub_files/application.rb +1 -1
- data/lib/spork/app_framework/rails_stub_files/application_controller.rb +22 -22
- data/lib/spork/app_framework/rails_stub_files/application_helper.rb +2 -2
- data/lib/spork/app_framework/unknown.rb +5 -5
- data/lib/spork/app_framework.rb +73 -73
- data/lib/spork/custom_io_streams.rb +24 -24
- data/lib/spork/diagnoser.rb +103 -103
- data/lib/spork/ext/ruby-debug.rb +150 -150
- data/lib/spork/forker.rb +70 -70
- data/lib/spork/run_strategy/forking.rb +29 -29
- data/lib/spork/run_strategy/magazine/magazine_slave.rb +0 -0
- data/lib/spork/run_strategy/magazine/magazine_slave_provider.rb +0 -0
- data/lib/spork/run_strategy/magazine/ring_server.rb +0 -0
- data/lib/spork/run_strategy/magazine.rb +2 -2
- data/lib/spork/run_strategy.rb +44 -44
- data/lib/spork/runner.rb +90 -90
- data/lib/spork/server.rb +74 -74
- data/lib/spork/test_framework/cucumber.rb +24 -24
- data/lib/spork/test_framework/rspec.rb +14 -14
- data/lib/spork/test_framework.rb +167 -167
- data/lib/spork.rb +126 -126
- data/spec/spec_helper.rb +108 -108
- data/spec/spork/app_framework/rails_spec.rb +22 -22
- data/spec/spork/app_framework/unknown_spec.rb +12 -12
- data/spec/spork/app_framework_spec.rb +16 -16
- data/spec/spork/diagnoser_spec.rb +105 -105
- data/spec/spork/forker_spec.rb +44 -44
- data/spec/spork/run_strategy/forking_spec.rb +38 -38
- data/spec/spork/runner_spec.rb +50 -50
- data/spec/spork/server_spec.rb +15 -15
- data/spec/spork/test_framework/cucumber_spec.rb +11 -11
- data/spec/spork/test_framework/rspec_spec.rb +10 -10
- data/spec/spork/test_framework_spec.rb +114 -114
- data/spec/spork_spec.rb +151 -151
- data/spec/support/fake_framework.rb +15 -15
- data/spec/support/fake_run_strategy.rb +21 -21
- metadata +7 -15
data/features/support/env.rb
CHANGED
@@ -1,111 +1,111 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'fileutils'
|
3
|
-
require 'forwardable'
|
4
|
-
require 'tempfile'
|
5
|
-
require 'spec/expectations'
|
6
|
-
require 'timeout'
|
7
|
-
require 'spork'
|
8
|
-
|
9
|
-
require(File.dirname(__FILE__) + '/background_job.rb')
|
10
|
-
|
11
|
-
class SporkWorld
|
12
|
-
BINARY = File.expand_path(File.dirname(__FILE__) + '/../../bin/spork')
|
13
|
-
RUBY_BINARY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
|
14
|
-
SANDBOX_DIR = File.expand_path(File.join(File.dirname(__FILE__), '../../tmp/sandbox'))
|
15
|
-
|
16
|
-
extend Forwardable
|
17
|
-
def_delegators SporkWorld, :sandbox_dir, :spork_lib_dir
|
18
|
-
|
19
|
-
def spork_lib_dir
|
20
|
-
@spork_lib_dir ||= File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
|
21
|
-
end
|
22
|
-
|
23
|
-
def initialize
|
24
|
-
@current_dir = SANDBOX_DIR
|
25
|
-
@background_jobs = []
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
attr_reader :last_exit_status, :last_stderr, :last_stdout, :background_jobs
|
30
|
-
def last_stderr
|
31
|
-
return @last_stderr if @last_stderr
|
32
|
-
if @background_job
|
33
|
-
@last_stderr = @background_job.stderr.read
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
def last_stdout
|
39
|
-
return @last_stdout if @last_stdout
|
40
|
-
if @background_job
|
41
|
-
@last_stdout = @background_job.stdout.read
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def create_file(file_name, file_content)
|
46
|
-
file_content.gsub!("SPORK_LIB", "'#{spork_lib_dir}'") # Some files, such as Rakefiles need to use the lib dir
|
47
|
-
in_current_dir do
|
48
|
-
FileUtils.mkdir_p(File.dirname(file_name))
|
49
|
-
File.open(file_name, 'w') { |f| f << file_content }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def in_current_dir(&block)
|
54
|
-
Dir.chdir(@current_dir, &block)
|
55
|
-
end
|
56
|
-
|
57
|
-
def localized_command(command, args)
|
58
|
-
case command
|
59
|
-
when 'spork'
|
60
|
-
command = SporkWorld::BINARY
|
61
|
-
when 'cucumber'
|
62
|
-
command = Cucumber::BINARY
|
63
|
-
else
|
64
|
-
command = %x{which #{command}}.chomp
|
65
|
-
end
|
66
|
-
"#{SporkWorld::RUBY_BINARY} -I #{Cucumber::LIBDIR} #{command} #{args}"
|
67
|
-
end
|
68
|
-
|
69
|
-
def run(command)
|
70
|
-
stderr_file = Tempfile.new('spork')
|
71
|
-
stderr_file.close
|
72
|
-
in_current_dir do
|
73
|
-
@last_stdout = `#{command} 2> #{stderr_file.path}`
|
74
|
-
@last_exit_status = $?.exitstatus
|
75
|
-
end
|
76
|
-
@last_stderr = IO.read(stderr_file.path)
|
77
|
-
end
|
78
|
-
|
79
|
-
def run_in_background(command)
|
80
|
-
in_current_dir do
|
81
|
-
@background_job = BackgroundJob.run(command)
|
82
|
-
end
|
83
|
-
@background_jobs << @background_job
|
84
|
-
@background_job
|
85
|
-
end
|
86
|
-
|
87
|
-
def terminate_background_jobs
|
88
|
-
if @background_jobs
|
89
|
-
@background_jobs.each do |background_job|
|
90
|
-
background_job.kill
|
91
|
-
end
|
92
|
-
end
|
93
|
-
@background_jobs.clear
|
94
|
-
@background_job = nil
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
World do
|
100
|
-
SporkWorld.new
|
101
|
-
end
|
102
|
-
|
103
|
-
Before do
|
104
|
-
FileUtils.rm_rf SporkWorld::SANDBOX_DIR
|
105
|
-
FileUtils.mkdir_p SporkWorld::SANDBOX_DIR
|
106
|
-
end
|
107
|
-
|
108
|
-
After do
|
109
|
-
# FileUtils.rm_rf SporkWorld::SANDBOX_DIR
|
110
|
-
terminate_background_jobs
|
111
|
-
end
|
1
|
+
require 'rubygems'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'forwardable'
|
4
|
+
require 'tempfile'
|
5
|
+
require 'spec/expectations'
|
6
|
+
require 'timeout'
|
7
|
+
require 'spork'
|
8
|
+
|
9
|
+
require(File.dirname(__FILE__) + '/background_job.rb')
|
10
|
+
|
11
|
+
class SporkWorld
|
12
|
+
BINARY = File.expand_path(File.dirname(__FILE__) + '/../../bin/spork')
|
13
|
+
RUBY_BINARY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
|
14
|
+
SANDBOX_DIR = File.expand_path(File.join(File.dirname(__FILE__), '../../tmp/sandbox'))
|
15
|
+
|
16
|
+
extend Forwardable
|
17
|
+
def_delegators SporkWorld, :sandbox_dir, :spork_lib_dir
|
18
|
+
|
19
|
+
def spork_lib_dir
|
20
|
+
@spork_lib_dir ||= File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
@current_dir = SANDBOX_DIR
|
25
|
+
@background_jobs = []
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
attr_reader :last_exit_status, :last_stderr, :last_stdout, :background_jobs
|
30
|
+
def last_stderr
|
31
|
+
return @last_stderr if @last_stderr
|
32
|
+
if @background_job
|
33
|
+
@last_stderr = @background_job.stderr.read
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def last_stdout
|
39
|
+
return @last_stdout if @last_stdout
|
40
|
+
if @background_job
|
41
|
+
@last_stdout = @background_job.stdout.read
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_file(file_name, file_content)
|
46
|
+
file_content.gsub!("SPORK_LIB", "'#{spork_lib_dir}'") # Some files, such as Rakefiles need to use the lib dir
|
47
|
+
in_current_dir do
|
48
|
+
FileUtils.mkdir_p(File.dirname(file_name))
|
49
|
+
File.open(file_name, 'w') { |f| f << file_content }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def in_current_dir(&block)
|
54
|
+
Dir.chdir(@current_dir, &block)
|
55
|
+
end
|
56
|
+
|
57
|
+
def localized_command(command, args)
|
58
|
+
case command
|
59
|
+
when 'spork'
|
60
|
+
command = SporkWorld::BINARY
|
61
|
+
when 'cucumber'
|
62
|
+
command = Cucumber::BINARY
|
63
|
+
else
|
64
|
+
command = %x{which #{command}}.chomp
|
65
|
+
end
|
66
|
+
"#{SporkWorld::RUBY_BINARY} -I #{Cucumber::LIBDIR} #{command} #{args}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def run(command)
|
70
|
+
stderr_file = Tempfile.new('spork')
|
71
|
+
stderr_file.close
|
72
|
+
in_current_dir do
|
73
|
+
@last_stdout = `#{command} 2> #{stderr_file.path}`
|
74
|
+
@last_exit_status = $?.exitstatus
|
75
|
+
end
|
76
|
+
@last_stderr = IO.read(stderr_file.path)
|
77
|
+
end
|
78
|
+
|
79
|
+
def run_in_background(command)
|
80
|
+
in_current_dir do
|
81
|
+
@background_job = BackgroundJob.run(command)
|
82
|
+
end
|
83
|
+
@background_jobs << @background_job
|
84
|
+
@background_job
|
85
|
+
end
|
86
|
+
|
87
|
+
def terminate_background_jobs
|
88
|
+
if @background_jobs
|
89
|
+
@background_jobs.each do |background_job|
|
90
|
+
background_job.kill
|
91
|
+
end
|
92
|
+
end
|
93
|
+
@background_jobs.clear
|
94
|
+
@background_job = nil
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
World do
|
100
|
+
SporkWorld.new
|
101
|
+
end
|
102
|
+
|
103
|
+
Before do
|
104
|
+
FileUtils.rm_rf SporkWorld::SANDBOX_DIR
|
105
|
+
FileUtils.mkdir_p SporkWorld::SANDBOX_DIR
|
106
|
+
end
|
107
|
+
|
108
|
+
After do
|
109
|
+
# FileUtils.rm_rf SporkWorld::SANDBOX_DIR
|
110
|
+
terminate_background_jobs
|
111
|
+
end
|
@@ -1,42 +1,42 @@
|
|
1
|
-
Feature: Unknown app frameworks
|
2
|
-
To increase to usefulness of Spork
|
3
|
-
Spork will work with unknown (or no) application frameworks
|
4
|
-
|
5
|
-
Scenario: Unsporked spec_helper
|
6
|
-
|
7
|
-
Given a file named "spec/spec_helper.rb" with:
|
8
|
-
"""
|
9
|
-
require 'rubygems'
|
10
|
-
require 'spec'
|
11
|
-
"""
|
12
|
-
When I run spork
|
13
|
-
Then the error output should contain "Using RSpec"
|
14
|
-
Then the error output should match /You must bootstrap .+spec\/spec_helper\.rb to continue/
|
15
|
-
|
16
|
-
Scenario: Sporked spec_helper
|
17
|
-
Given a file named "spec/spec_helper.rb" with:
|
18
|
-
"""
|
19
|
-
require 'rubygems'
|
20
|
-
require 'spork'
|
21
|
-
|
22
|
-
Spork.prefork do
|
23
|
-
require 'spec'
|
24
|
-
end
|
25
|
-
|
26
|
-
Spork.each_run do
|
27
|
-
$each_run
|
28
|
-
end
|
29
|
-
"""
|
30
|
-
And a file named "spec/did_it_work_spec.rb" with:
|
31
|
-
"""
|
32
|
-
describe "Did it work?" do
|
33
|
-
it "checks to see if all worked" do
|
34
|
-
Spork.state.should == :using_spork
|
35
|
-
puts "Specs successfully run within spork"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
"""
|
39
|
-
When I fire up a spork instance with "spork rspec"
|
40
|
-
And I run spec --drb spec/did_it_work_spec.rb
|
41
|
-
Then the output should contain "Specs successfully run within spork"
|
1
|
+
Feature: Unknown app frameworks
|
2
|
+
To increase to usefulness of Spork
|
3
|
+
Spork will work with unknown (or no) application frameworks
|
4
|
+
|
5
|
+
Scenario: Unsporked spec_helper
|
6
|
+
|
7
|
+
Given a file named "spec/spec_helper.rb" with:
|
8
|
+
"""
|
9
|
+
require 'rubygems'
|
10
|
+
require 'spec'
|
11
|
+
"""
|
12
|
+
When I run spork
|
13
|
+
Then the error output should contain "Using RSpec"
|
14
|
+
Then the error output should match /You must bootstrap .+spec\/spec_helper\.rb to continue/
|
15
|
+
|
16
|
+
Scenario: Sporked spec_helper
|
17
|
+
Given a file named "spec/spec_helper.rb" with:
|
18
|
+
"""
|
19
|
+
require 'rubygems'
|
20
|
+
require 'spork'
|
21
|
+
|
22
|
+
Spork.prefork do
|
23
|
+
require 'spec'
|
24
|
+
end
|
25
|
+
|
26
|
+
Spork.each_run do
|
27
|
+
$each_run
|
28
|
+
end
|
29
|
+
"""
|
30
|
+
And a file named "spec/did_it_work_spec.rb" with:
|
31
|
+
"""
|
32
|
+
describe "Did it work?" do
|
33
|
+
it "checks to see if all worked" do
|
34
|
+
Spork.state.should == :using_spork
|
35
|
+
puts "Specs successfully run within spork"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
"""
|
39
|
+
When I fire up a spork instance with "spork rspec"
|
40
|
+
And I run spec --drb spec/did_it_work_spec.rb
|
41
|
+
Then the output should contain "Specs successfully run within spork"
|
42
42
|
|
data/geminstaller.yml
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
defaults:
|
2
|
-
install_options: "--no-ri --no-rdoc"
|
3
|
-
gems:
|
4
|
-
- { name: 'sqlite3-ruby', version: '>= 1.2.5' }
|
5
|
-
- { name: 'cucumber', version: '>= 0.4.0' }
|
6
|
-
- { name: 'rspec', version: '>= 1.2.9' }
|
7
|
-
- { name: 'rspec-rails', version: '>= 1.2.9' }
|
8
|
-
- { name: 'rails', version: '>= 2.3' }
|
9
|
-
- { name: 'ruby-debug', version: '>= 0.10.3' }
|
1
|
+
defaults:
|
2
|
+
install_options: "--no-ri --no-rdoc"
|
3
|
+
gems:
|
4
|
+
- { name: 'sqlite3-ruby', version: '>= 1.2.5' }
|
5
|
+
- { name: 'cucumber', version: '>= 0.4.0' }
|
6
|
+
- { name: 'rspec', version: '>= 1.2.9' }
|
7
|
+
- { name: 'rspec-rails', version: '>= 1.2.9' }
|
8
|
+
- { name: 'rails', version: '>= 2.3' }
|
9
|
+
- { name: 'ruby-debug', version: '>= 0.10.3' }
|
@@ -1,158 +1,158 @@
|
|
1
|
-
class Spork::AppFramework::Rails < Spork::AppFramework
|
2
|
-
|
3
|
-
# TODO - subclass this out to handle different versions of rails
|
4
|
-
# Also... this is the nastiest duck punch ever. Clean this up.
|
5
|
-
module NinjaPatcher
|
6
|
-
def self.included(klass)
|
7
|
-
klass.class_eval do
|
8
|
-
unless method_defined?(:load_environment_without_spork)
|
9
|
-
alias :load_environment_without_spork :load_environment
|
10
|
-
alias :load_environment :load_environment_with_spork
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.run_with_spork(*args, &block) # it's all fun and games until someone gets an eye poked out
|
14
|
-
if ENV['RAILS_ENV']
|
15
|
-
Object.send(:remove_const, :RAILS_ENV)
|
16
|
-
Object.const_set(:RAILS_ENV, ENV['RAILS_ENV'].dup)
|
17
|
-
end
|
18
|
-
run_without_spork(*args, &block)
|
19
|
-
end
|
20
|
-
|
21
|
-
class << self
|
22
|
-
unless method_defined?(:run_without_spork)
|
23
|
-
alias :run_without_spork :run
|
24
|
-
alias :run :run_with_spork
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def load_environment_with_spork
|
31
|
-
result = load_environment_without_spork
|
32
|
-
install_hooks
|
33
|
-
result
|
34
|
-
end
|
35
|
-
|
36
|
-
def install_hooks
|
37
|
-
auto_reestablish_db_connection
|
38
|
-
delay_observer_loading
|
39
|
-
delay_app_preload
|
40
|
-
delay_application_controller_loading
|
41
|
-
delay_route_loading
|
42
|
-
delay_eager_view_loading
|
43
|
-
end
|
44
|
-
|
45
|
-
def reset_rails_env
|
46
|
-
return unless ENV['RAILS_ENV']
|
47
|
-
Object.send(:remove_const, :RAILS_ENV)
|
48
|
-
Object.const_set(:RAILS_ENV, ENV['RAILS_ENV'].dup)
|
49
|
-
end
|
50
|
-
|
51
|
-
def delay_observer_loading
|
52
|
-
if ::Rails::Initializer.instance_methods.include?('load_observers')
|
53
|
-
Spork.trap_method(::Rails::Initializer, :load_observers)
|
54
|
-
end
|
55
|
-
if Object.const_defined?(:ActionController)
|
56
|
-
require "action_controller/dispatcher.rb"
|
57
|
-
Spork.trap_class_method(::ActionController::Dispatcher, :define_dispatcher_callbacks) if ActionController::Dispatcher.respond_to?(:define_dispatcher_callbacks)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def delay_app_preload
|
62
|
-
if ::Rails::Initializer.instance_methods.include?('load_application_classes')
|
63
|
-
Spork.trap_method(::Rails::Initializer, :load_application_classes)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def delay_application_controller_loading
|
68
|
-
if application_controller_source = ["#{Dir.pwd}/app/controllers/application.rb", "#{Dir.pwd}/app/controllers/application_controller.rb"].find { |f| File.exist?(f) }
|
69
|
-
application_helper_source = "#{Dir.pwd}/app/helpers/application_helper.rb"
|
70
|
-
load_paths = (::ActiveSupport.const_defined?(:Dependencies) ? ::ActiveSupport::Dependencies : ::Dependencies).load_paths
|
71
|
-
load_paths.unshift(File.expand_path('rails_stub_files', File.dirname(__FILE__)))
|
72
|
-
Spork.each_run do
|
73
|
-
require application_controller_source
|
74
|
-
require application_helper_source if File.exist?(application_helper_source)
|
75
|
-
# update the rails magic to refresh the module
|
76
|
-
ApplicationController.send(:helper, ApplicationHelper)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def auto_reestablish_db_connection
|
82
|
-
if Object.const_defined?(:ActiveRecord)
|
83
|
-
Spork.each_run do
|
84
|
-
# rails lib/test_help.rb is very aggressive about overriding RAILS_ENV and will switch it back to test after the cucumber env was loaded
|
85
|
-
reset_rails_env
|
86
|
-
ActiveRecord::Base.establish_connection
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def delay_route_loading
|
92
|
-
if ::Rails::Initializer.instance_methods.include?('initialize_routing')
|
93
|
-
Spork.trap_method(::Rails::Initializer, :initialize_routing)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def delay_eager_view_loading
|
98
|
-
# So, in testing mode it seems it would be optimal to not eager load
|
99
|
-
# views (as your may only run a test that uses one or two views).
|
100
|
-
# However, I decided to delay eager loading rather than force it to
|
101
|
-
# disable because you may wish to eager load your views (I.E. you're
|
102
|
-
# testing concurrency)
|
103
|
-
|
104
|
-
# Rails 2.3.x +
|
105
|
-
if defined?(::ActionView::Template::EagerPath)
|
106
|
-
Spork.trap_method(::ActionView::Template::EagerPath, :load!)
|
107
|
-
end
|
108
|
-
# Rails 2.2.x
|
109
|
-
if defined?(::ActionView::PathSet::Path)
|
110
|
-
Spork.trap_method(::ActionView::PathSet::Path, :load)
|
111
|
-
end
|
112
|
-
# Rails 2.0.5 - 2.1.x don't appear to eager cache views.
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
def preload(&block)
|
117
|
-
STDERR.puts "Preloading Rails environment"
|
118
|
-
STDERR.flush
|
119
|
-
ENV["RAILS_ENV"] ||= 'test'
|
120
|
-
preload_rails
|
121
|
-
yield
|
122
|
-
end
|
123
|
-
|
124
|
-
def entry_point
|
125
|
-
@entry_point ||= File.expand_path("config/environment.rb", Dir.pwd)
|
126
|
-
end
|
127
|
-
|
128
|
-
alias :environment_file :entry_point
|
129
|
-
|
130
|
-
def boot_file
|
131
|
-
@boot_file ||= File.join(File.dirname(environment_file), 'boot')
|
132
|
-
end
|
133
|
-
|
134
|
-
def environment_contents
|
135
|
-
@environment_contents ||= File.read(environment_file)
|
136
|
-
end
|
137
|
-
|
138
|
-
def vendor
|
139
|
-
@vendor ||= File.expand_path("vendor/rails", Dir.pwd)
|
140
|
-
end
|
141
|
-
|
142
|
-
def version
|
143
|
-
@version ||= (
|
144
|
-
if /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/.match(environment_contents)
|
145
|
-
$1
|
146
|
-
else
|
147
|
-
nil
|
148
|
-
end
|
149
|
-
)
|
150
|
-
end
|
151
|
-
|
152
|
-
def preload_rails
|
153
|
-
Object.const_set(:RAILS_GEM_VERSION, version) if version
|
154
|
-
require boot_file
|
155
|
-
::Rails::Initializer.send(:include, Spork::AppFramework::Rails::NinjaPatcher)
|
156
|
-
end
|
157
|
-
|
1
|
+
class Spork::AppFramework::Rails < Spork::AppFramework
|
2
|
+
|
3
|
+
# TODO - subclass this out to handle different versions of rails
|
4
|
+
# Also... this is the nastiest duck punch ever. Clean this up.
|
5
|
+
module NinjaPatcher
|
6
|
+
def self.included(klass)
|
7
|
+
klass.class_eval do
|
8
|
+
unless method_defined?(:load_environment_without_spork)
|
9
|
+
alias :load_environment_without_spork :load_environment
|
10
|
+
alias :load_environment :load_environment_with_spork
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.run_with_spork(*args, &block) # it's all fun and games until someone gets an eye poked out
|
14
|
+
if ENV['RAILS_ENV']
|
15
|
+
Object.send(:remove_const, :RAILS_ENV)
|
16
|
+
Object.const_set(:RAILS_ENV, ENV['RAILS_ENV'].dup)
|
17
|
+
end
|
18
|
+
run_without_spork(*args, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
class << self
|
22
|
+
unless method_defined?(:run_without_spork)
|
23
|
+
alias :run_without_spork :run
|
24
|
+
alias :run :run_with_spork
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def load_environment_with_spork
|
31
|
+
result = load_environment_without_spork
|
32
|
+
install_hooks
|
33
|
+
result
|
34
|
+
end
|
35
|
+
|
36
|
+
def install_hooks
|
37
|
+
auto_reestablish_db_connection
|
38
|
+
delay_observer_loading
|
39
|
+
delay_app_preload
|
40
|
+
delay_application_controller_loading
|
41
|
+
delay_route_loading
|
42
|
+
delay_eager_view_loading
|
43
|
+
end
|
44
|
+
|
45
|
+
def reset_rails_env
|
46
|
+
return unless ENV['RAILS_ENV']
|
47
|
+
Object.send(:remove_const, :RAILS_ENV)
|
48
|
+
Object.const_set(:RAILS_ENV, ENV['RAILS_ENV'].dup)
|
49
|
+
end
|
50
|
+
|
51
|
+
def delay_observer_loading
|
52
|
+
if ::Rails::Initializer.instance_methods.include?('load_observers')
|
53
|
+
Spork.trap_method(::Rails::Initializer, :load_observers)
|
54
|
+
end
|
55
|
+
if Object.const_defined?(:ActionController)
|
56
|
+
require "action_controller/dispatcher.rb"
|
57
|
+
Spork.trap_class_method(::ActionController::Dispatcher, :define_dispatcher_callbacks) if ActionController::Dispatcher.respond_to?(:define_dispatcher_callbacks)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def delay_app_preload
|
62
|
+
if ::Rails::Initializer.instance_methods.include?('load_application_classes')
|
63
|
+
Spork.trap_method(::Rails::Initializer, :load_application_classes)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def delay_application_controller_loading
|
68
|
+
if application_controller_source = ["#{Dir.pwd}/app/controllers/application.rb", "#{Dir.pwd}/app/controllers/application_controller.rb"].find { |f| File.exist?(f) }
|
69
|
+
application_helper_source = "#{Dir.pwd}/app/helpers/application_helper.rb"
|
70
|
+
load_paths = (::ActiveSupport.const_defined?(:Dependencies) ? ::ActiveSupport::Dependencies : ::Dependencies).load_paths
|
71
|
+
load_paths.unshift(File.expand_path('rails_stub_files', File.dirname(__FILE__)))
|
72
|
+
Spork.each_run do
|
73
|
+
require application_controller_source
|
74
|
+
require application_helper_source if File.exist?(application_helper_source)
|
75
|
+
# update the rails magic to refresh the module
|
76
|
+
ApplicationController.send(:helper, ApplicationHelper)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def auto_reestablish_db_connection
|
82
|
+
if Object.const_defined?(:ActiveRecord)
|
83
|
+
Spork.each_run do
|
84
|
+
# rails lib/test_help.rb is very aggressive about overriding RAILS_ENV and will switch it back to test after the cucumber env was loaded
|
85
|
+
reset_rails_env
|
86
|
+
ActiveRecord::Base.establish_connection
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def delay_route_loading
|
92
|
+
if ::Rails::Initializer.instance_methods.include?('initialize_routing')
|
93
|
+
Spork.trap_method(::Rails::Initializer, :initialize_routing)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def delay_eager_view_loading
|
98
|
+
# So, in testing mode it seems it would be optimal to not eager load
|
99
|
+
# views (as your may only run a test that uses one or two views).
|
100
|
+
# However, I decided to delay eager loading rather than force it to
|
101
|
+
# disable because you may wish to eager load your views (I.E. you're
|
102
|
+
# testing concurrency)
|
103
|
+
|
104
|
+
# Rails 2.3.x +
|
105
|
+
if defined?(::ActionView::Template::EagerPath)
|
106
|
+
Spork.trap_method(::ActionView::Template::EagerPath, :load!)
|
107
|
+
end
|
108
|
+
# Rails 2.2.x
|
109
|
+
if defined?(::ActionView::PathSet::Path)
|
110
|
+
Spork.trap_method(::ActionView::PathSet::Path, :load)
|
111
|
+
end
|
112
|
+
# Rails 2.0.5 - 2.1.x don't appear to eager cache views.
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def preload(&block)
|
117
|
+
STDERR.puts "Preloading Rails environment"
|
118
|
+
STDERR.flush
|
119
|
+
ENV["RAILS_ENV"] ||= 'test'
|
120
|
+
preload_rails
|
121
|
+
yield
|
122
|
+
end
|
123
|
+
|
124
|
+
def entry_point
|
125
|
+
@entry_point ||= File.expand_path("config/environment.rb", Dir.pwd)
|
126
|
+
end
|
127
|
+
|
128
|
+
alias :environment_file :entry_point
|
129
|
+
|
130
|
+
def boot_file
|
131
|
+
@boot_file ||= File.join(File.dirname(environment_file), 'boot')
|
132
|
+
end
|
133
|
+
|
134
|
+
def environment_contents
|
135
|
+
@environment_contents ||= File.read(environment_file)
|
136
|
+
end
|
137
|
+
|
138
|
+
def vendor
|
139
|
+
@vendor ||= File.expand_path("vendor/rails", Dir.pwd)
|
140
|
+
end
|
141
|
+
|
142
|
+
def version
|
143
|
+
@version ||= (
|
144
|
+
if /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/.match(environment_contents)
|
145
|
+
$1
|
146
|
+
else
|
147
|
+
nil
|
148
|
+
end
|
149
|
+
)
|
150
|
+
end
|
151
|
+
|
152
|
+
def preload_rails
|
153
|
+
Object.const_set(:RAILS_GEM_VERSION, version) if version
|
154
|
+
require boot_file
|
155
|
+
::Rails::Initializer.send(:include, Spork::AppFramework::Rails::NinjaPatcher)
|
156
|
+
end
|
157
|
+
|
158
158
|
end
|
@@ -1 +1 @@
|
|
1
|
-
load(File.dirname(__FILE__) + "/application_controller.rb")
|
1
|
+
load(File.dirname(__FILE__) + "/application_controller.rb")
|