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.
Files changed (54) hide show
  1. data/MIT-LICENSE +19 -19
  2. data/README.rdoc +99 -99
  3. data/assets/bootstrap.rb +29 -29
  4. data/bin/spork +20 -20
  5. data/features/cucumber_rails_integration.feature +118 -118
  6. data/features/diagnostic_mode.feature +40 -40
  7. data/features/rails_delayed_loading_workarounds.feature +115 -115
  8. data/features/rspec_rails_integration.feature +93 -93
  9. data/features/spork_debugger.feature +108 -108
  10. data/features/steps/general_steps.rb +3 -3
  11. data/features/steps/rails_steps.rb +52 -52
  12. data/features/steps/sandbox_steps.rb +115 -115
  13. data/features/support/background_job.rb +63 -63
  14. data/features/support/env.rb +111 -111
  15. data/features/unknown_app_framework.feature +41 -41
  16. data/geminstaller.yml +9 -9
  17. data/lib/spork/app_framework/rails.rb +157 -157
  18. data/lib/spork/app_framework/rails_stub_files/application.rb +1 -1
  19. data/lib/spork/app_framework/rails_stub_files/application_controller.rb +22 -22
  20. data/lib/spork/app_framework/rails_stub_files/application_helper.rb +2 -2
  21. data/lib/spork/app_framework/unknown.rb +5 -5
  22. data/lib/spork/app_framework.rb +73 -73
  23. data/lib/spork/custom_io_streams.rb +24 -24
  24. data/lib/spork/diagnoser.rb +103 -103
  25. data/lib/spork/ext/ruby-debug.rb +150 -150
  26. data/lib/spork/forker.rb +70 -70
  27. data/lib/spork/run_strategy/forking.rb +29 -29
  28. data/lib/spork/run_strategy/magazine/magazine_slave.rb +0 -0
  29. data/lib/spork/run_strategy/magazine/magazine_slave_provider.rb +0 -0
  30. data/lib/spork/run_strategy/magazine/ring_server.rb +0 -0
  31. data/lib/spork/run_strategy/magazine.rb +2 -2
  32. data/lib/spork/run_strategy.rb +44 -44
  33. data/lib/spork/runner.rb +90 -90
  34. data/lib/spork/server.rb +74 -74
  35. data/lib/spork/test_framework/cucumber.rb +24 -24
  36. data/lib/spork/test_framework/rspec.rb +14 -14
  37. data/lib/spork/test_framework.rb +167 -167
  38. data/lib/spork.rb +126 -126
  39. data/spec/spec_helper.rb +108 -108
  40. data/spec/spork/app_framework/rails_spec.rb +22 -22
  41. data/spec/spork/app_framework/unknown_spec.rb +12 -12
  42. data/spec/spork/app_framework_spec.rb +16 -16
  43. data/spec/spork/diagnoser_spec.rb +105 -105
  44. data/spec/spork/forker_spec.rb +44 -44
  45. data/spec/spork/run_strategy/forking_spec.rb +38 -38
  46. data/spec/spork/runner_spec.rb +50 -50
  47. data/spec/spork/server_spec.rb +15 -15
  48. data/spec/spork/test_framework/cucumber_spec.rb +11 -11
  49. data/spec/spork/test_framework/rspec_spec.rb +10 -10
  50. data/spec/spork/test_framework_spec.rb +114 -114
  51. data/spec/spork_spec.rb +151 -151
  52. data/spec/support/fake_framework.rb +15 -15
  53. data/spec/support/fake_run_strategy.rb +21 -21
  54. metadata +7 -15
@@ -1,22 +1,22 @@
1
- # This is a stub used to help Spork delay the loading of the real ApplicationController
2
- class ::ApplicationController < ActionController::Base
3
- @@preloading = true
4
- class << self
5
- def inherited(klass)
6
- (@_descendants ||= []) << klass if @@preloading
7
- super
8
- end
9
-
10
- def reapply_inheritance!
11
- @@preloading = false
12
- Array(@_descendants).each do |descendant|
13
- descendant.master_helper_module.send(:include, master_helper_module)
14
- descendant.send(:default_helper_module!)
15
-
16
- descendant.respond_to?(:reapply_inheritance!) && descendant.reapply_inheritance!
17
- end
18
- end
19
- end
20
- end
21
-
22
- Spork.each_run { ApplicationController.reapply_inheritance! }
1
+ # This is a stub used to help Spork delay the loading of the real ApplicationController
2
+ class ::ApplicationController < ActionController::Base
3
+ @@preloading = true
4
+ class << self
5
+ def inherited(klass)
6
+ (@_descendants ||= []) << klass if @@preloading
7
+ super
8
+ end
9
+
10
+ def reapply_inheritance!
11
+ @@preloading = false
12
+ Array(@_descendants).each do |descendant|
13
+ descendant.master_helper_module.send(:include, master_helper_module)
14
+ descendant.send(:default_helper_module!)
15
+
16
+ descendant.respond_to?(:reapply_inheritance!) && descendant.reapply_inheritance!
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ Spork.each_run { ApplicationController.reapply_inheritance! }
@@ -1,3 +1,3 @@
1
- # This is a stub used to help Spork delay the loading of the real ApplicationHelper
2
- module ::ApplicationHelper
1
+ # This is a stub used to help Spork delay the loading of the real ApplicationHelper
2
+ module ::ApplicationHelper
3
3
  end
@@ -1,6 +1,6 @@
1
- # This is used if no supported appliction framework is detected
2
- class Spork::AppFramework::Unknown < Spork::AppFramework
3
- def entry_point
4
- nil
5
- end
1
+ # This is used if no supported appliction framework is detected
2
+ class Spork::AppFramework::Unknown < Spork::AppFramework
3
+ def entry_point
4
+ nil
5
+ end
6
6
  end
@@ -1,74 +1,74 @@
1
- class Spork::AppFramework
2
- # A hash of procs where the key is the class name, and the proc takes no arguments and returns true if it detects that said application framework is being used in the project.
3
- #
4
- # The key :Rails maps to Spork::AppFramework::Rails
5
- #
6
- # This is used to reduce the amount of code needed to be loaded - only the detected application framework's support code is loaded.
7
- SUPPORTED_FRAMEWORKS = {
8
- :Rails => lambda {
9
- File.exist?("config/environment.rb") && File.read("config/environment.rb").include?('RAILS_GEM_VERSION')
10
- }
11
- } unless defined? SUPPORTED_FRAMEWORKS
12
-
13
- def self.setup_autoload
14
- ([:Unknown] + SUPPORTED_FRAMEWORKS.keys).each do |name|
15
- autoload name, File.join(File.dirname(__FILE__), "app_framework", name.to_s.downcase)
16
- end
17
- end
18
-
19
- # Iterates through all SUPPORTED_FRAMEWORKS and returns the symbolic name of the project application framework detected. Otherwise, returns :Unknown
20
- def self.detect_framework_name
21
- SUPPORTED_FRAMEWORKS.each do |key, value|
22
- return key if value.call
23
- end
24
- :Unknown
25
- end
26
-
27
- # Same as detect_framework_name, but returns an instance of the specific AppFramework class.
28
- def self.detect_framework
29
- name = detect_framework_name
30
- self[name]
31
- end
32
-
33
- # Initializes, stores, and returns a singleton instance of the named AppFramework.
34
- #
35
- # == Parameters
36
- #
37
- # # +name+ - A symbolic name of a AppFramework subclass
38
- #
39
- # == Example
40
- #
41
- # Spork::AppFramework[:Rails]
42
- def self.[](name)
43
- instances[name] ||= const_get(name).new
44
- end
45
-
46
- def self.short_name
47
- name.gsub('Spork::AppFramework::', '')
48
- end
49
-
50
- # If there is some stuff out of the box that the Spork can do to speed up tests without the test helper file being bootstrapped, this should return false.
51
- def bootstrap_required?
52
- entry_point.nil?
53
- end
54
-
55
- # Abstract: The path to the file that loads the project environment, ie config/environment.rb. Returns nil if there is none.
56
- def entry_point
57
- raise NotImplementedError
58
- end
59
-
60
- def preload(&block)
61
- yield
62
- end
63
-
64
- def short_name
65
- self.class.short_name
66
- end
67
-
68
- protected
69
- def self.instances
70
- @instances ||= {}
71
- end
72
- end
73
-
1
+ class Spork::AppFramework
2
+ # A hash of procs where the key is the class name, and the proc takes no arguments and returns true if it detects that said application framework is being used in the project.
3
+ #
4
+ # The key :Rails maps to Spork::AppFramework::Rails
5
+ #
6
+ # This is used to reduce the amount of code needed to be loaded - only the detected application framework's support code is loaded.
7
+ SUPPORTED_FRAMEWORKS = {
8
+ :Rails => lambda {
9
+ File.exist?("config/environment.rb") && File.read("config/environment.rb").include?('RAILS_GEM_VERSION')
10
+ }
11
+ } unless defined? SUPPORTED_FRAMEWORKS
12
+
13
+ def self.setup_autoload
14
+ ([:Unknown] + SUPPORTED_FRAMEWORKS.keys).each do |name|
15
+ autoload name, File.join(File.dirname(__FILE__), "app_framework", name.to_s.downcase)
16
+ end
17
+ end
18
+
19
+ # Iterates through all SUPPORTED_FRAMEWORKS and returns the symbolic name of the project application framework detected. Otherwise, returns :Unknown
20
+ def self.detect_framework_name
21
+ SUPPORTED_FRAMEWORKS.each do |key, value|
22
+ return key if value.call
23
+ end
24
+ :Unknown
25
+ end
26
+
27
+ # Same as detect_framework_name, but returns an instance of the specific AppFramework class.
28
+ def self.detect_framework
29
+ name = detect_framework_name
30
+ self[name]
31
+ end
32
+
33
+ # Initializes, stores, and returns a singleton instance of the named AppFramework.
34
+ #
35
+ # == Parameters
36
+ #
37
+ # # +name+ - A symbolic name of a AppFramework subclass
38
+ #
39
+ # == Example
40
+ #
41
+ # Spork::AppFramework[:Rails]
42
+ def self.[](name)
43
+ instances[name] ||= const_get(name).new
44
+ end
45
+
46
+ def self.short_name
47
+ name.gsub('Spork::AppFramework::', '')
48
+ end
49
+
50
+ # If there is some stuff out of the box that the Spork can do to speed up tests without the test helper file being bootstrapped, this should return false.
51
+ def bootstrap_required?
52
+ entry_point.nil?
53
+ end
54
+
55
+ # Abstract: The path to the file that loads the project environment, ie config/environment.rb. Returns nil if there is none.
56
+ def entry_point
57
+ raise NotImplementedError
58
+ end
59
+
60
+ def preload(&block)
61
+ yield
62
+ end
63
+
64
+ def short_name
65
+ self.class.short_name
66
+ end
67
+
68
+ protected
69
+ def self.instances
70
+ @instances ||= {}
71
+ end
72
+ end
73
+
74
74
  Spork::AppFramework.setup_autoload
@@ -1,25 +1,25 @@
1
- # This class is mainly used for testing.
2
- # When included (and used), it gives us an opportunity to stub out the output streams used for a given class
3
- module Spork::CustomIOStreams
4
- def self.included(klass)
5
- klass.send(:extend, ::Spork::CustomIOStreams::ClassMethods)
6
- end
7
-
8
- def stderr
9
- self.class.stderr
10
- end
11
-
12
- def stdout
13
- self.class.stdout
14
- end
15
-
16
- module ClassMethods
17
- def stderr
18
- $stderr
19
- end
20
-
21
- def stdout
22
- $stdout
23
- end
24
- end
1
+ # This class is mainly used for testing.
2
+ # When included (and used), it gives us an opportunity to stub out the output streams used for a given class
3
+ module Spork::CustomIOStreams
4
+ def self.included(klass)
5
+ klass.send(:extend, ::Spork::CustomIOStreams::ClassMethods)
6
+ end
7
+
8
+ def stderr
9
+ self.class.stderr
10
+ end
11
+
12
+ def stdout
13
+ self.class.stdout
14
+ end
15
+
16
+ module ClassMethods
17
+ def stderr
18
+ $stderr
19
+ end
20
+
21
+ def stdout
22
+ $stdout
23
+ end
24
+ end
25
25
  end
@@ -1,103 +1,103 @@
1
- # The Diagnoser hooks into load and require and keeps track of when files are required / loaded, and who loaded them.
2
- # It's used when you run spork --diagnose
3
- #
4
- # = Example
5
- #
6
- # Spork::Diagnoser.install_hook!('/path/env.rb', '/path')
7
- # require '/path/to/env.rb'
8
- # Spork::Diagnoser.output_results(STDOUT)
9
- class Spork::Diagnoser
10
- class << self
11
- def loaded_files
12
- @loaded_files ||= {}
13
- end
14
-
15
- # Installs the diagnoser hook into Kernel#require and Kernel#load
16
- #
17
- # == Parameters
18
- #
19
- # * +entry_file+ - The file that is used to load the project. Used to filter the backtrace so anything that happens after it is hidden.
20
- # * +dir+ - The project directory. Any file loaded outside of this directory will not be logged.
21
- def install_hook!(entry_file = nil, dir = Dir.pwd)
22
- @dir = File.expand_path(Dir.pwd, dir)
23
- @entry_file = entry_file
24
-
25
- Kernel.class_eval do
26
- alias :require_without_diagnoser :require
27
- alias :load_without_diagnoser :load
28
-
29
- def require(string)
30
- ::Spork::Diagnoser.add_included_file(string, caller)
31
- require_without_diagnoser(string)
32
- end
33
-
34
- def load(string)
35
- ::Spork::Diagnoser.add_included_file(string, caller)
36
- load_without_diagnoser(string)
37
- end
38
- end
39
- end
40
-
41
- def add_included_file(filename, callstack)
42
- filename = expand_filename(filename)
43
- return unless File.exist?(filename)
44
- loaded_files[filename] = filter_callstack(caller) if subdirectory?(filename)
45
- end
46
-
47
- # Uninstall the hook. Generally useful only for testing the Diagnoser.
48
- def remove_hook!
49
- return unless Kernel.private_instance_methods.include?('require_without_diagnoser')
50
- Kernel.class_eval do
51
- alias :require :require_without_diagnoser
52
- alias :load :load_without_diagnoser
53
-
54
- undef_method(:require_without_diagnoser)
55
- undef_method(:load_without_diagnoser)
56
- end
57
- true
58
- end
59
-
60
- # output the results of a diagnostic run.
61
- #
62
- # == Parameters
63
- #
64
- # * +stdout+ - An IO stream to output the results to.
65
- def output_results(stdout)
66
- project_prefix = Dir.pwd + "/"
67
- minimify = lambda { |f| f.gsub(project_prefix, '')}
68
- stdout.puts "- Spork Diagnosis -\n"
69
- stdout.puts "-- Summary --"
70
- stdout.puts loaded_files.keys.sort.map(&minimify)
71
- stdout.puts "\n\n\n"
72
- stdout.puts "-- Detail --"
73
- loaded_files.keys.sort.each do |file|
74
- stdout.puts "\n\n\n--- #{minimify.call(file)} ---\n"
75
- stdout.puts loaded_files[file].map(&minimify)
76
- end
77
- end
78
-
79
- private
80
- def filter_callstack(callstack, entry_file = @entry_file)
81
- callstack.pop until callstack.empty? || callstack.last.include?(@entry_file) if @entry_file
82
- callstack.map do |line|
83
- next if line.include?('lib/spork/diagnoser.rb')
84
- line.gsub!('require_without_diagnoser', 'require')
85
- line
86
- end.compact
87
- end
88
-
89
- def expand_filename(filename)
90
- ([Dir.pwd] + $:).each do |attempted_path|
91
- attempted_filename = File.expand_path(filename, attempted_path)
92
- return attempted_filename if File.file?(attempted_filename)
93
- attempted_filename = attempted_filename + ".rb"
94
- return attempted_filename if File.file?(attempted_filename)
95
- end
96
- filename
97
- end
98
-
99
- def subdirectory?(directory)
100
- File.expand_path(directory, Dir.pwd).include?(@dir)
101
- end
102
- end
103
- end
1
+ # The Diagnoser hooks into load and require and keeps track of when files are required / loaded, and who loaded them.
2
+ # It's used when you run spork --diagnose
3
+ #
4
+ # = Example
5
+ #
6
+ # Spork::Diagnoser.install_hook!('/path/env.rb', '/path')
7
+ # require '/path/to/env.rb'
8
+ # Spork::Diagnoser.output_results(STDOUT)
9
+ class Spork::Diagnoser
10
+ class << self
11
+ def loaded_files
12
+ @loaded_files ||= {}
13
+ end
14
+
15
+ # Installs the diagnoser hook into Kernel#require and Kernel#load
16
+ #
17
+ # == Parameters
18
+ #
19
+ # * +entry_file+ - The file that is used to load the project. Used to filter the backtrace so anything that happens after it is hidden.
20
+ # * +dir+ - The project directory. Any file loaded outside of this directory will not be logged.
21
+ def install_hook!(entry_file = nil, dir = Dir.pwd)
22
+ @dir = File.expand_path(Dir.pwd, dir)
23
+ @entry_file = entry_file
24
+
25
+ Kernel.class_eval do
26
+ alias :require_without_diagnoser :require
27
+ alias :load_without_diagnoser :load
28
+
29
+ def require(string)
30
+ ::Spork::Diagnoser.add_included_file(string, caller)
31
+ require_without_diagnoser(string)
32
+ end
33
+
34
+ def load(string)
35
+ ::Spork::Diagnoser.add_included_file(string, caller)
36
+ load_without_diagnoser(string)
37
+ end
38
+ end
39
+ end
40
+
41
+ def add_included_file(filename, callstack)
42
+ filename = expand_filename(filename)
43
+ return unless File.exist?(filename)
44
+ loaded_files[filename] = filter_callstack(caller) if subdirectory?(filename)
45
+ end
46
+
47
+ # Uninstall the hook. Generally useful only for testing the Diagnoser.
48
+ def remove_hook!
49
+ return unless Kernel.private_instance_methods.include?('require_without_diagnoser')
50
+ Kernel.class_eval do
51
+ alias :require :require_without_diagnoser
52
+ alias :load :load_without_diagnoser
53
+
54
+ undef_method(:require_without_diagnoser)
55
+ undef_method(:load_without_diagnoser)
56
+ end
57
+ true
58
+ end
59
+
60
+ # output the results of a diagnostic run.
61
+ #
62
+ # == Parameters
63
+ #
64
+ # * +stdout+ - An IO stream to output the results to.
65
+ def output_results(stdout)
66
+ project_prefix = Dir.pwd + "/"
67
+ minimify = lambda { |f| f.gsub(project_prefix, '')}
68
+ stdout.puts "- Spork Diagnosis -\n"
69
+ stdout.puts "-- Summary --"
70
+ stdout.puts loaded_files.keys.sort.map(&minimify)
71
+ stdout.puts "\n\n\n"
72
+ stdout.puts "-- Detail --"
73
+ loaded_files.keys.sort.each do |file|
74
+ stdout.puts "\n\n\n--- #{minimify.call(file)} ---\n"
75
+ stdout.puts loaded_files[file].map(&minimify)
76
+ end
77
+ end
78
+
79
+ private
80
+ def filter_callstack(callstack, entry_file = @entry_file)
81
+ callstack.pop until callstack.empty? || callstack.last.include?(@entry_file) if @entry_file
82
+ callstack.map do |line|
83
+ next if line.include?('lib/spork/diagnoser.rb')
84
+ line.gsub!('require_without_diagnoser', 'require')
85
+ line
86
+ end.compact
87
+ end
88
+
89
+ def expand_filename(filename)
90
+ ([Dir.pwd] + $:).each do |attempted_path|
91
+ attempted_filename = File.expand_path(filename, attempted_path)
92
+ return attempted_filename if File.file?(attempted_filename)
93
+ attempted_filename = attempted_filename + ".rb"
94
+ return attempted_filename if File.file?(attempted_filename)
95
+ end
96
+ filename
97
+ end
98
+
99
+ def subdirectory?(directory)
100
+ File.expand_path(directory, Dir.pwd).include?(@dir)
101
+ end
102
+ end
103
+ end