milhouse-spork 0.7.5.2 → 0.7.5.4

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.rb +126 -126
  18. data/lib/spork/app_framework.rb +73 -73
  19. data/lib/spork/app_framework/rails.rb +157 -157
  20. data/lib/spork/app_framework/rails_stub_files/application.rb +1 -1
  21. data/lib/spork/app_framework/rails_stub_files/application_controller.rb +22 -22
  22. data/lib/spork/app_framework/rails_stub_files/application_helper.rb +2 -2
  23. data/lib/spork/app_framework/unknown.rb +5 -5
  24. data/lib/spork/custom_io_streams.rb +24 -24
  25. data/lib/spork/diagnoser.rb +103 -103
  26. data/lib/spork/ext/ruby-debug.rb +150 -150
  27. data/lib/spork/forker.rb +70 -70
  28. data/lib/spork/run_strategy.rb +44 -44
  29. data/lib/spork/run_strategy/forking.rb +29 -29
  30. data/lib/spork/run_strategy/magazine.rb +8 -7
  31. data/lib/spork/run_strategy/magazine/magazine_slave.rb +0 -0
  32. data/lib/spork/run_strategy/magazine/magazine_slave_provider.rb +2 -2
  33. data/lib/spork/run_strategy/magazine/ring_server.rb +1 -1
  34. data/lib/spork/runner.rb +90 -90
  35. data/lib/spork/server.rb +74 -74
  36. data/lib/spork/test_framework.rb +167 -167
  37. data/lib/spork/test_framework/cucumber.rb +24 -24
  38. data/lib/spork/test_framework/rspec.rb +14 -14
  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 +14 -6
data/lib/spork/server.rb CHANGED
@@ -1,74 +1,74 @@
1
- require 'drb/drb'
2
- require 'rbconfig'
3
- require 'spork/forker.rb'
4
- require 'spork/custom_io_streams.rb'
5
- require 'spork/app_framework.rb'
6
-
7
- # An abstract class that is implemented to create a server
8
- #
9
- # (This was originally based off of spec_server.rb from rspec-rails (David Chelimsky), which was based on Florian Weber's TDDMate)
10
- class Spork::Server
11
- attr_reader :run_strategy
12
- include Spork::CustomIOStreams
13
-
14
- def initialize(options = {})
15
- @run_strategy = options[:run_strategy]
16
- @port = options[:port]
17
- end
18
-
19
- def self.run(options = {})
20
- new(options).listen
21
- end
22
-
23
- # Sets up signals and starts the DRb service. If it's successful, it doesn't return. Not ever. You don't need to override this.
24
- def listen
25
- raise RuntimeError, "you must call Spork.using_spork! before starting the server" unless Spork.using_spork?
26
- trap("SIGINT") { sig_int_received }
27
- trap("SIGTERM") { abort; exit!(0) }
28
- trap("USR2") { abort; restart } if Signal.list.has_key?("USR2")
29
- @drb_service = DRb.start_service("druby://127.0.0.1:#{port}", self)
30
- Spork.each_run { @drb_service.stop_service } if @run_strategy.class == Spork::RunStrategy::Forking
31
- stderr.puts "Spork is ready and listening on #{port}!"
32
- stderr.flush
33
- DRb.thread.join
34
- end
35
-
36
- attr_accessor :port
37
-
38
- # This is the public facing method that is served up by DRb. To use it from the client side (in a testing framework):
39
- #
40
- # DRb.start_service("druby://localhost:0") # this allows Ruby to do some magical stuff so you can pass an output stream over DRb.
41
- # # see http://redmine.ruby-lang.org/issues/show/496 to see why localhost:0 is used.
42
- # spec_server = DRbObject.new_with_uri("druby://127.0.0.1:8989")
43
- # spec_server.run(options.argv, $stderr, $stdout)
44
- #
45
- # When implementing a test server, don't override this method: override run_tests instead.
46
- def run(argv, stderr, stdout)
47
- run_strategy.run(argv, stderr, stdout)
48
- end
49
-
50
- def abort
51
- run_strategy.abort
52
- end
53
-
54
- private
55
- def restart
56
- stderr.puts "restarting"
57
- stderr.flush
58
- config = ::Config::CONFIG
59
- ruby = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
60
- command_line = [ruby, $0, ARGV].flatten.join(' ')
61
- exec(command_line)
62
- end
63
-
64
- def sig_int_received
65
- stdout.puts "\n"
66
- if run_strategy.running?
67
- abort
68
- stderr.puts "Running tests stopped. Press CTRL-C again to stop the server."
69
- stderr.flush
70
- else
71
- exit!(0)
72
- end
73
- end
74
- end
1
+ require 'drb/drb'
2
+ require 'rbconfig'
3
+ require 'spork/forker.rb'
4
+ require 'spork/custom_io_streams.rb'
5
+ require 'spork/app_framework.rb'
6
+
7
+ # An abstract class that is implemented to create a server
8
+ #
9
+ # (This was originally based off of spec_server.rb from rspec-rails (David Chelimsky), which was based on Florian Weber's TDDMate)
10
+ class Spork::Server
11
+ attr_reader :run_strategy
12
+ include Spork::CustomIOStreams
13
+
14
+ def initialize(options = {})
15
+ @run_strategy = options[:run_strategy]
16
+ @port = options[:port]
17
+ end
18
+
19
+ def self.run(options = {})
20
+ new(options).listen
21
+ end
22
+
23
+ # Sets up signals and starts the DRb service. If it's successful, it doesn't return. Not ever. You don't need to override this.
24
+ def listen
25
+ raise RuntimeError, "you must call Spork.using_spork! before starting the server" unless Spork.using_spork?
26
+ trap("SIGINT") { sig_int_received }
27
+ trap("SIGTERM") { abort; exit!(0) }
28
+ trap("USR2") { abort; restart } if Signal.list.has_key?("USR2")
29
+ @drb_service = DRb.start_service("druby://127.0.0.1:#{port}", self)
30
+ Spork.each_run { @drb_service.stop_service } if @run_strategy.class == Spork::RunStrategy::Forking
31
+ stderr.puts "Spork is ready and listening on #{port}!"
32
+ stderr.flush
33
+ DRb.thread.join
34
+ end
35
+
36
+ attr_accessor :port
37
+
38
+ # This is the public facing method that is served up by DRb. To use it from the client side (in a testing framework):
39
+ #
40
+ # DRb.start_service("druby://localhost:0") # this allows Ruby to do some magical stuff so you can pass an output stream over DRb.
41
+ # # see http://redmine.ruby-lang.org/issues/show/496 to see why localhost:0 is used.
42
+ # spec_server = DRbObject.new_with_uri("druby://127.0.0.1:8989")
43
+ # spec_server.run(options.argv, $stderr, $stdout)
44
+ #
45
+ # When implementing a test server, don't override this method: override run_tests instead.
46
+ def run(argv, stderr, stdout)
47
+ run_strategy.run(argv, stderr, stdout)
48
+ end
49
+
50
+ def abort
51
+ run_strategy.abort
52
+ end
53
+
54
+ private
55
+ def restart
56
+ stderr.puts "restarting"
57
+ stderr.flush
58
+ config = ::Config::CONFIG
59
+ ruby = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
60
+ command_line = [ruby, $0, ARGV].flatten.join(' ')
61
+ exec(command_line)
62
+ end
63
+
64
+ def sig_int_received
65
+ stdout.puts "\n"
66
+ if run_strategy.running?
67
+ abort
68
+ stderr.puts "Running tests stopped. Press CTRL-C again to stop the server."
69
+ stderr.flush
70
+ else
71
+ exit!(0)
72
+ end
73
+ end
74
+ end
@@ -1,167 +1,167 @@
1
- class Spork::TestFramework
2
- LOAD_PREFERENCE = ['RSpec', 'Cucumber']
3
- BOOTSTRAP_FILE = File.dirname(__FILE__) + "/../../assets/bootstrap.rb"
4
-
5
- @@supported_test_frameworks = []
6
- attr_reader :stdout, :stderr
7
-
8
- class FactoryException < Exception; end
9
-
10
- class NoFrameworksAvailable < FactoryException
11
- def message
12
- "I can't find any testing frameworks to use. Are you running me from a project directory?"
13
- end
14
- end
15
-
16
- class FrameworkNotAvailable < FactoryException
17
- def initialize(framework)
18
- @framework = framework
19
- end
20
-
21
- def message
22
- "I can't find the file #{@framework.helper_file} for the #{@framework.short_name} testing framework.\nAre you running me from the project directory?"
23
- end
24
- end
25
-
26
- class NoFrameworkMatched < FactoryException
27
- def initialize(beginning_with)
28
- @beginning_with = beginning_with
29
- end
30
-
31
- def message
32
- "Couldn't find a supported test framework that begins with '#{@beginning_with}'"
33
- end
34
- end
35
-
36
- def initialize(stdout = STDOUT, stderr = STDERR)
37
- @stdout, @stderr = stdout, stderr
38
- end
39
-
40
- def self.factory(output = STDOUT, error = STDERR, beginning_with = nil)
41
- if beginning_with
42
- @klass = supported_test_frameworks(beginning_with).first
43
- raise(NoFrameworkMatched.new(beginning_with)) if @klass.nil?
44
- raise(FrameworkNotAvailable.new(@klass)) unless @klass.available?
45
- else
46
- @klass = available_test_frameworks.first
47
- raise(NoFrameworksAvailable.new) unless @klass
48
- end
49
- @klass.new(output, error)
50
- end
51
-
52
- def self.helper_file
53
- self::HELPER_FILE
54
- end
55
-
56
- def self.default_port
57
- (ENV["#{short_name.upcase}_DRB"] || self::DEFAULT_PORT).to_i
58
- end
59
-
60
- def self.short_name
61
- self.name.gsub('Spork::TestFramework::', '')
62
- end
63
-
64
- # Returns a list of all testing servers that have detected their testing framework being used in the project.
65
- def self.available_test_frameworks
66
- supported_test_frameworks.select { |s| s.available? }
67
- end
68
-
69
- # Returns a list of all servers that have been implemented (it keeps track of them automatically via Class.inherited)
70
- def self.supported_test_frameworks(starting_with = nil)
71
- @@supported_test_frameworks.sort! { |a,b| a.load_preference_index <=> b.load_preference_index }
72
- return @@supported_test_frameworks if starting_with.nil?
73
- @@supported_test_frameworks.select do |s|
74
- s.short_name.match(/^#{Regexp.escape(starting_with)}/i)
75
- end
76
- end
77
-
78
- def short_name
79
- self.class.short_name
80
- end
81
-
82
- def helper_file
83
- self.class.helper_file
84
- end
85
-
86
- # Detects if the test helper has been bootstrapped.
87
- def bootstrapped?
88
- File.read(helper_file).include?("Spork.prefork")
89
- end
90
-
91
- # Bootstraps the current test helper file by prepending a Spork.prefork and Spork.each_run block at the beginning.
92
- def bootstrap
93
- if bootstrapped?
94
- stderr.puts "Already bootstrapped!"
95
- return
96
- end
97
- stderr.puts "Bootstrapping #{helper_file}."
98
- contents = File.read(helper_file)
99
- bootstrap_code = File.read(BOOTSTRAP_FILE)
100
- File.open(helper_file, "wb") do |f|
101
- f.puts bootstrap_code
102
- f.puts contents
103
- end
104
-
105
- stderr.puts "Done. Edit #{helper_file} now with your favorite text editor and follow the instructions."
106
- true
107
- end
108
-
109
- # Returns true if the testing frameworks helper file exists. Override if this is not sufficient to detect your testing framework.
110
- def self.available?
111
- File.exist?(helper_file)
112
- end
113
-
114
- # Used to specify
115
- def self.load_preference_index
116
- LOAD_PREFERENCE.index(short_name) || LOAD_PREFERENCE.length
117
- end
118
-
119
- def preload
120
- Spork.exec_prefork do
121
- unless bootstrapped?
122
- stderr.puts "#{helper_file} has not been bootstrapped. Run spork --bootstrap to do so."
123
- stderr.flush
124
-
125
- if framework.bootstrap_required?
126
- stderr.puts "I can't do anything for you by default for the framework your using: #{framework.short_name}.\nYou must bootstrap #{helper_file} to continue."
127
- stderr.flush
128
- return false
129
- else
130
- load(framework.entry_point)
131
- end
132
- end
133
-
134
- framework.preload do
135
- if bootstrapped?
136
- stderr.puts "Loading Spork.prefork block..."
137
- stderr.flush
138
- load(helper_file)
139
- end
140
- end
141
- end
142
- true
143
- end
144
-
145
- def run_tests(argv, stderr, stdout)
146
- raise NotImplementedError
147
- end
148
-
149
- def entry_point
150
- bootstrapped? ? helper_file : framework.entry_point
151
- end
152
-
153
- def default_port
154
- self.class.default_port
155
- end
156
-
157
- protected
158
- def self.inherited(subclass)
159
- @@supported_test_frameworks << subclass
160
- end
161
-
162
- def framework
163
- @framework ||= Spork::AppFramework.detect_framework
164
- end
165
- end
166
-
167
- Spork.detect_and_require('spork/test_framework/*.rb')
1
+ class Spork::TestFramework
2
+ LOAD_PREFERENCE = ['RSpec', 'Cucumber']
3
+ BOOTSTRAP_FILE = File.dirname(__FILE__) + "/../../assets/bootstrap.rb"
4
+
5
+ @@supported_test_frameworks = []
6
+ attr_reader :stdout, :stderr
7
+
8
+ class FactoryException < Exception; end
9
+
10
+ class NoFrameworksAvailable < FactoryException
11
+ def message
12
+ "I can't find any testing frameworks to use. Are you running me from a project directory?"
13
+ end
14
+ end
15
+
16
+ class FrameworkNotAvailable < FactoryException
17
+ def initialize(framework)
18
+ @framework = framework
19
+ end
20
+
21
+ def message
22
+ "I can't find the file #{@framework.helper_file} for the #{@framework.short_name} testing framework.\nAre you running me from the project directory?"
23
+ end
24
+ end
25
+
26
+ class NoFrameworkMatched < FactoryException
27
+ def initialize(beginning_with)
28
+ @beginning_with = beginning_with
29
+ end
30
+
31
+ def message
32
+ "Couldn't find a supported test framework that begins with '#{@beginning_with}'"
33
+ end
34
+ end
35
+
36
+ def initialize(stdout = STDOUT, stderr = STDERR)
37
+ @stdout, @stderr = stdout, stderr
38
+ end
39
+
40
+ def self.factory(output = STDOUT, error = STDERR, beginning_with = nil)
41
+ if beginning_with
42
+ @klass = supported_test_frameworks(beginning_with).first
43
+ raise(NoFrameworkMatched.new(beginning_with)) if @klass.nil?
44
+ raise(FrameworkNotAvailable.new(@klass)) unless @klass.available?
45
+ else
46
+ @klass = available_test_frameworks.first
47
+ raise(NoFrameworksAvailable.new) unless @klass
48
+ end
49
+ @klass.new(output, error)
50
+ end
51
+
52
+ def self.helper_file
53
+ self::HELPER_FILE
54
+ end
55
+
56
+ def self.default_port
57
+ (ENV["#{short_name.upcase}_DRB"] || self::DEFAULT_PORT).to_i
58
+ end
59
+
60
+ def self.short_name
61
+ self.name.gsub('Spork::TestFramework::', '')
62
+ end
63
+
64
+ # Returns a list of all testing servers that have detected their testing framework being used in the project.
65
+ def self.available_test_frameworks
66
+ supported_test_frameworks.select { |s| s.available? }
67
+ end
68
+
69
+ # Returns a list of all servers that have been implemented (it keeps track of them automatically via Class.inherited)
70
+ def self.supported_test_frameworks(starting_with = nil)
71
+ @@supported_test_frameworks.sort! { |a,b| a.load_preference_index <=> b.load_preference_index }
72
+ return @@supported_test_frameworks if starting_with.nil?
73
+ @@supported_test_frameworks.select do |s|
74
+ s.short_name.match(/^#{Regexp.escape(starting_with)}/i)
75
+ end
76
+ end
77
+
78
+ def short_name
79
+ self.class.short_name
80
+ end
81
+
82
+ def helper_file
83
+ self.class.helper_file
84
+ end
85
+
86
+ # Detects if the test helper has been bootstrapped.
87
+ def bootstrapped?
88
+ File.read(helper_file).include?("Spork.prefork")
89
+ end
90
+
91
+ # Bootstraps the current test helper file by prepending a Spork.prefork and Spork.each_run block at the beginning.
92
+ def bootstrap
93
+ if bootstrapped?
94
+ stderr.puts "Already bootstrapped!"
95
+ return
96
+ end
97
+ stderr.puts "Bootstrapping #{helper_file}."
98
+ contents = File.read(helper_file)
99
+ bootstrap_code = File.read(BOOTSTRAP_FILE)
100
+ File.open(helper_file, "wb") do |f|
101
+ f.puts bootstrap_code
102
+ f.puts contents
103
+ end
104
+
105
+ stderr.puts "Done. Edit #{helper_file} now with your favorite text editor and follow the instructions."
106
+ true
107
+ end
108
+
109
+ # Returns true if the testing frameworks helper file exists. Override if this is not sufficient to detect your testing framework.
110
+ def self.available?
111
+ File.exist?(helper_file)
112
+ end
113
+
114
+ # Used to specify
115
+ def self.load_preference_index
116
+ LOAD_PREFERENCE.index(short_name) || LOAD_PREFERENCE.length
117
+ end
118
+
119
+ def preload
120
+ Spork.exec_prefork do
121
+ unless bootstrapped?
122
+ stderr.puts "#{helper_file} has not been bootstrapped. Run spork --bootstrap to do so."
123
+ stderr.flush
124
+
125
+ if framework.bootstrap_required?
126
+ stderr.puts "I can't do anything for you by default for the framework your using: #{framework.short_name}.\nYou must bootstrap #{helper_file} to continue."
127
+ stderr.flush
128
+ return false
129
+ else
130
+ load(framework.entry_point)
131
+ end
132
+ end
133
+
134
+ framework.preload do
135
+ if bootstrapped?
136
+ stderr.puts "Loading Spork.prefork block..."
137
+ stderr.flush
138
+ load(helper_file)
139
+ end
140
+ end
141
+ end
142
+ true
143
+ end
144
+
145
+ def run_tests(argv, stderr, stdout)
146
+ raise NotImplementedError
147
+ end
148
+
149
+ def entry_point
150
+ bootstrapped? ? helper_file : framework.entry_point
151
+ end
152
+
153
+ def default_port
154
+ self.class.default_port
155
+ end
156
+
157
+ protected
158
+ def self.inherited(subclass)
159
+ @@supported_test_frameworks << subclass
160
+ end
161
+
162
+ def framework
163
+ @framework ||= Spork::AppFramework.detect_framework
164
+ end
165
+ end
166
+
167
+ Spork.detect_and_require('spork/test_framework/*.rb')