milhouse-spork 0.7.5 → 0.7.5.1

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 +0 -0
  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 +19 -20
data/lib/spork/runner.rb CHANGED
@@ -1,90 +1,90 @@
1
- require 'optparse'
2
-
3
- module Spork
4
- # This is used by bin/spork. It's wrapped in a class because it's easier to test that way.
5
- class Runner
6
- attr_reader :test_framework
7
-
8
- def self.run(args, output, error)
9
- self.new(args, output, error).run
10
- end
11
-
12
- def initialize(args, output, error)
13
- raise ArgumentError, "expected array of args" unless args.is_a?(Array)
14
- @output = output
15
- @error = error
16
- @options = {}
17
- opt = OptionParser.new
18
- opt.banner = "Usage: spork [test framework name] [options]\n\n"
19
-
20
- opt.separator "Options:"
21
- opt.on("-b", "--bootstrap") {|ignore| @options[:bootstrap] = true }
22
- opt.on("-d", "--diagnose") {|ignore| @options[:diagnose] = true }
23
- opt.on("-h", "--help") {|ignore| @options[:help] = true }
24
- opt.on("-p", "--port [PORT]") {|port| @options[:port] = port }
25
- non_option_args = args.select { |arg| ! args[0].match(/^-/) }
26
- @options[:server_matcher] = non_option_args[0]
27
- opt.parse!(args)
28
-
29
- if @options[:help]
30
- @output.puts opt
31
- @output.puts
32
- @output.puts supported_test_frameworks_text
33
- exit(0)
34
- end
35
- end
36
-
37
- def supported_test_frameworks_text
38
- text = StringIO.new
39
-
40
- text.puts "Supported test frameworks:"
41
- text.puts Spork::TestFramework.supported_test_frameworks.sort { |a,b| a.short_name <=> b.short_name }.map { |s| (s.available? ? '(*) ' : '( ) ') + s.short_name }
42
- text.puts "\nLegend: ( ) - not detected in project (*) - detected\n"
43
- text.string
44
- end
45
-
46
- # Returns a server for the specified (or the detected default) testing framework. Returns nil if none detected, or if the specified is not supported or available.
47
- def find_test_framework
48
- Spork::TestFramework.factory(@output, @error, options[:server_matcher])
49
- rescue Spork::TestFramework::NoFrameworksAvailable => e
50
- @error.puts e.message
51
- rescue Spork::TestFramework::FactoryException => e
52
- @error.puts "#{e.message}\n\n#{supported_test_frameworks_text}"
53
- end
54
-
55
- def run
56
- return false unless test_framework = find_test_framework
57
- ENV["DRB"] = 'true'
58
- @error.puts "Using #{test_framework.short_name}"
59
- @error.flush
60
-
61
- case
62
- when options[:bootstrap]
63
- test_framework.bootstrap
64
- when options[:diagnose]
65
- require 'spork/diagnoser'
66
-
67
- Spork::Diagnoser.install_hook!(test_framework.entry_point)
68
- test_framework.preload
69
- Spork::Diagnoser.output_results(@output)
70
- return true
71
- else
72
- Spork.using_spork!
73
- run_strategy = Spork::RunStrategy.factory(test_framework)
74
- return(false) unless run_strategy.preload
75
- Spork::Server.run(:port => @options[:port] || test_framework.default_port, :run_strategy => run_strategy)
76
- return true
77
- end
78
- end
79
-
80
- private
81
- attr_reader :options
82
-
83
- end
84
- end
85
-
86
-
87
-
88
-
89
-
90
-
1
+ require 'optparse'
2
+
3
+ module Spork
4
+ # This is used by bin/spork. It's wrapped in a class because it's easier to test that way.
5
+ class Runner
6
+ attr_reader :test_framework
7
+
8
+ def self.run(args, output, error)
9
+ self.new(args, output, error).run
10
+ end
11
+
12
+ def initialize(args, output, error)
13
+ raise ArgumentError, "expected array of args" unless args.is_a?(Array)
14
+ @output = output
15
+ @error = error
16
+ @options = {}
17
+ opt = OptionParser.new
18
+ opt.banner = "Usage: spork [test framework name] [options]\n\n"
19
+
20
+ opt.separator "Options:"
21
+ opt.on("-b", "--bootstrap") {|ignore| @options[:bootstrap] = true }
22
+ opt.on("-d", "--diagnose") {|ignore| @options[:diagnose] = true }
23
+ opt.on("-h", "--help") {|ignore| @options[:help] = true }
24
+ opt.on("-p", "--port [PORT]") {|port| @options[:port] = port }
25
+ non_option_args = args.select { |arg| ! args[0].match(/^-/) }
26
+ @options[:server_matcher] = non_option_args[0]
27
+ opt.parse!(args)
28
+
29
+ if @options[:help]
30
+ @output.puts opt
31
+ @output.puts
32
+ @output.puts supported_test_frameworks_text
33
+ exit(0)
34
+ end
35
+ end
36
+
37
+ def supported_test_frameworks_text
38
+ text = StringIO.new
39
+
40
+ text.puts "Supported test frameworks:"
41
+ text.puts Spork::TestFramework.supported_test_frameworks.sort { |a,b| a.short_name <=> b.short_name }.map { |s| (s.available? ? '(*) ' : '( ) ') + s.short_name }
42
+ text.puts "\nLegend: ( ) - not detected in project (*) - detected\n"
43
+ text.string
44
+ end
45
+
46
+ # Returns a server for the specified (or the detected default) testing framework. Returns nil if none detected, or if the specified is not supported or available.
47
+ def find_test_framework
48
+ Spork::TestFramework.factory(@output, @error, options[:server_matcher])
49
+ rescue Spork::TestFramework::NoFrameworksAvailable => e
50
+ @error.puts e.message
51
+ rescue Spork::TestFramework::FactoryException => e
52
+ @error.puts "#{e.message}\n\n#{supported_test_frameworks_text}"
53
+ end
54
+
55
+ def run
56
+ return false unless test_framework = find_test_framework
57
+ ENV["DRB"] = 'true'
58
+ @error.puts "Using #{test_framework.short_name}"
59
+ @error.flush
60
+
61
+ case
62
+ when options[:bootstrap]
63
+ test_framework.bootstrap
64
+ when options[:diagnose]
65
+ require 'spork/diagnoser'
66
+
67
+ Spork::Diagnoser.install_hook!(test_framework.entry_point)
68
+ test_framework.preload
69
+ Spork::Diagnoser.output_results(@output)
70
+ return true
71
+ else
72
+ Spork.using_spork!
73
+ run_strategy = Spork::RunStrategy.factory(test_framework)
74
+ return(false) unless run_strategy.preload
75
+ Spork::Server.run(:port => @options[:port] || test_framework.default_port, :run_strategy => run_strategy)
76
+ return true
77
+ end
78
+ end
79
+
80
+ private
81
+ attr_reader :options
82
+
83
+ end
84
+ end
85
+
86
+
87
+
88
+
89
+
90
+
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,24 +1,24 @@
1
- class Spork::TestFramework::Cucumber < Spork::TestFramework
2
- DEFAULT_PORT = 8990
3
- HELPER_FILE = File.join(Dir.pwd, "features/support/env.rb")
4
-
5
- class << self
6
- # REMOVE WHEN SUPPORT FOR 0.3.95 AND EARLIER IS DROPPED
7
- attr_accessor :mother_object
8
- end
9
-
10
- def preload
11
- require 'cucumber'
12
- begin
13
- @step_mother = ::Cucumber::StepMother.new
14
- @step_mother.load_programming_language('rb')
15
- rescue NoMethodError => pre_cucumber_0_4 # REMOVE WHEN SUPPORT FOR PRE-0.4 IS DROPPED
16
- @step_mother = Spork::Server::Cucumber.mother_object
17
- end
18
- super
19
- end
20
-
21
- def run_tests(argv, stderr, stdout)
22
- ::Cucumber::Cli::Main.new(argv, stdout, stderr).execute!(@step_mother)
23
- end
24
- end
1
+ class Spork::TestFramework::Cucumber < Spork::TestFramework
2
+ DEFAULT_PORT = 8990
3
+ HELPER_FILE = File.join(Dir.pwd, "features/support/env.rb")
4
+
5
+ class << self
6
+ # REMOVE WHEN SUPPORT FOR 0.3.95 AND EARLIER IS DROPPED
7
+ attr_accessor :mother_object
8
+ end
9
+
10
+ def preload
11
+ require 'cucumber'
12
+ begin
13
+ @step_mother = ::Cucumber::StepMother.new
14
+ @step_mother.load_programming_language('rb')
15
+ rescue NoMethodError => pre_cucumber_0_4 # REMOVE WHEN SUPPORT FOR PRE-0.4 IS DROPPED
16
+ @step_mother = Spork::Server::Cucumber.mother_object
17
+ end
18
+ super
19
+ end
20
+
21
+ def run_tests(argv, stderr, stdout)
22
+ ::Cucumber::Cli::Main.new(argv, stdout, stderr).execute!(@step_mother)
23
+ end
24
+ end
@@ -1,14 +1,14 @@
1
- class Spork::TestFramework::RSpec < Spork::TestFramework
2
- DEFAULT_PORT = 8989
3
- HELPER_FILE = File.join(Dir.pwd, "spec/spec_helper.rb")
4
-
5
- def run_tests(argv, stderr, stdout)
6
- ::Spec::Runner::CommandLine.run(
7
- ::Spec::Runner::OptionParser.parse(
8
- argv,
9
- stderr,
10
- stdout
11
- )
12
- )
13
- end
14
- end
1
+ class Spork::TestFramework::RSpec < Spork::TestFramework
2
+ DEFAULT_PORT = 8989
3
+ HELPER_FILE = File.join(Dir.pwd, "spec/spec_helper.rb")
4
+
5
+ def run_tests(argv, stderr, stdout)
6
+ ::Spec::Runner::CommandLine.run(
7
+ ::Spec::Runner::OptionParser.parse(
8
+ argv,
9
+ stderr,
10
+ stdout
11
+ )
12
+ )
13
+ end
14
+ end