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
data/spec/spec_helper.rb CHANGED
@@ -1,108 +1,108 @@
1
- require 'rubygems'
2
-
3
- unless $spec_helper_loaded
4
- $spec_helper_loaded = true
5
-
6
- $LOAD_PATH.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
7
- SPEC_TMP_DIR = File.expand_path('tmp', File.dirname(__FILE__))
8
- require 'spork'
9
- require 'stringio'
10
- require 'fileutils'
11
-
12
- Spec::Runner.configure do |config|
13
- config.before(:each) do
14
- $test_stdout = StringIO.new
15
- $test_stderr = StringIO.new
16
- @current_dir = nil
17
- end
18
-
19
- config.after(:each) do
20
- FileUtils.rm_rf(SPEC_TMP_DIR) if File.directory?(SPEC_TMP_DIR)
21
-
22
- end
23
-
24
- def create_file(filename, contents)
25
- FileUtils.mkdir_p(SPEC_TMP_DIR) unless File.directory?(SPEC_TMP_DIR)
26
-
27
- in_current_dir do
28
- FileUtils.mkdir_p(File.dirname(filename))
29
- File.open(filename, 'wb') { |f| f << contents }
30
- end
31
- end
32
-
33
- def create_helper_file(test_framework = FakeFramework)
34
- create_file(test_framework.helper_file, "# stub spec helper file")
35
- end
36
-
37
- def in_current_dir(&block)
38
- Dir.chdir(current_dir, &block)
39
- end
40
-
41
- def current_dir
42
- @current_dir ||= SPEC_TMP_DIR
43
- end
44
-
45
- def change_current_dir(sub_path)
46
- @current_dir = File.expand_path(sub_path, SPEC_TMP_DIR)
47
- end
48
- end
49
-
50
-
51
- module Spec
52
- module Matchers
53
- class IncludeAStringLike
54
- def initialize(substring_or_regex)
55
- case substring_or_regex
56
- when String
57
- @regex = Regexp.new(Regexp.escape(substring_or_regex))
58
- when Regexp
59
- @regex = substring_or_regex
60
- else
61
- raise ArgumentError, "don't know what to do with the #{substring_or_regex.class} you provided"
62
- end
63
- end
64
-
65
- def matches?(list_of_strings)
66
- @list_of_strings = list_of_strings
67
- @list_of_strings.any? { |s| s =~ @regex }
68
- end
69
- def failure_message
70
- "#{@list_of_strings.inspect} expected to include a string like #{@regex.inspect}"
71
- end
72
- def negative_failure_message
73
- "#{@list_of_strings.inspect} expected to not include a string like #{@regex.inspect}, but did"
74
- end
75
- end
76
-
77
- def include_a_string_like(substring_or_regex)
78
- IncludeAStringLike.new(substring_or_regex)
79
- end
80
- end
81
- end
82
-
83
- module Spork::TestIOStreams
84
- def self.included(klass)
85
- klass.send(:extend, ::Spork::TestIOStreams::ClassMethods)
86
- end
87
-
88
- def stderr
89
- self.class.stderr
90
- end
91
-
92
- def stdout
93
- self.class.stdout
94
- end
95
-
96
- module ClassMethods
97
- def stderr
98
- $test_stderr
99
- end
100
-
101
- def stdout
102
- $test_stdout
103
- end
104
- end
105
- end
106
-
107
- Dir.glob(File.dirname(__FILE__) + "/support/*.rb").each { |f| require(f) }
108
- end
1
+ require 'rubygems'
2
+
3
+ unless $spec_helper_loaded
4
+ $spec_helper_loaded = true
5
+
6
+ $LOAD_PATH.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
7
+ SPEC_TMP_DIR = File.expand_path('tmp', File.dirname(__FILE__))
8
+ require 'spork'
9
+ require 'stringio'
10
+ require 'fileutils'
11
+
12
+ Spec::Runner.configure do |config|
13
+ config.before(:each) do
14
+ $test_stdout = StringIO.new
15
+ $test_stderr = StringIO.new
16
+ @current_dir = nil
17
+ end
18
+
19
+ config.after(:each) do
20
+ FileUtils.rm_rf(SPEC_TMP_DIR) if File.directory?(SPEC_TMP_DIR)
21
+
22
+ end
23
+
24
+ def create_file(filename, contents)
25
+ FileUtils.mkdir_p(SPEC_TMP_DIR) unless File.directory?(SPEC_TMP_DIR)
26
+
27
+ in_current_dir do
28
+ FileUtils.mkdir_p(File.dirname(filename))
29
+ File.open(filename, 'wb') { |f| f << contents }
30
+ end
31
+ end
32
+
33
+ def create_helper_file(test_framework = FakeFramework)
34
+ create_file(test_framework.helper_file, "# stub spec helper file")
35
+ end
36
+
37
+ def in_current_dir(&block)
38
+ Dir.chdir(current_dir, &block)
39
+ end
40
+
41
+ def current_dir
42
+ @current_dir ||= SPEC_TMP_DIR
43
+ end
44
+
45
+ def change_current_dir(sub_path)
46
+ @current_dir = File.expand_path(sub_path, SPEC_TMP_DIR)
47
+ end
48
+ end
49
+
50
+
51
+ module Spec
52
+ module Matchers
53
+ class IncludeAStringLike
54
+ def initialize(substring_or_regex)
55
+ case substring_or_regex
56
+ when String
57
+ @regex = Regexp.new(Regexp.escape(substring_or_regex))
58
+ when Regexp
59
+ @regex = substring_or_regex
60
+ else
61
+ raise ArgumentError, "don't know what to do with the #{substring_or_regex.class} you provided"
62
+ end
63
+ end
64
+
65
+ def matches?(list_of_strings)
66
+ @list_of_strings = list_of_strings
67
+ @list_of_strings.any? { |s| s =~ @regex }
68
+ end
69
+ def failure_message
70
+ "#{@list_of_strings.inspect} expected to include a string like #{@regex.inspect}"
71
+ end
72
+ def negative_failure_message
73
+ "#{@list_of_strings.inspect} expected to not include a string like #{@regex.inspect}, but did"
74
+ end
75
+ end
76
+
77
+ def include_a_string_like(substring_or_regex)
78
+ IncludeAStringLike.new(substring_or_regex)
79
+ end
80
+ end
81
+ end
82
+
83
+ module Spork::TestIOStreams
84
+ def self.included(klass)
85
+ klass.send(:extend, ::Spork::TestIOStreams::ClassMethods)
86
+ end
87
+
88
+ def stderr
89
+ self.class.stderr
90
+ end
91
+
92
+ def stdout
93
+ self.class.stdout
94
+ end
95
+
96
+ module ClassMethods
97
+ def stderr
98
+ $test_stderr
99
+ end
100
+
101
+ def stdout
102
+ $test_stdout
103
+ end
104
+ end
105
+ end
106
+
107
+ Dir.glob(File.dirname(__FILE__) + "/support/*.rb").each { |f| require(f) }
108
+ end
@@ -1,22 +1,22 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe Spork::AppFramework::Rails do
4
- describe ".version" do
5
- it "detects the current version of rails" do
6
- create_file("config/environment.rb", "RAILS_GEM_VERSION = '2.1.0'")
7
- in_current_dir do
8
- Spork::AppFramework::Rails.new.version.should == "2.1.0"
9
- end
10
-
11
- create_file("config/environment.rb", 'RAILS_GEM_VERSION = "2.1.0"')
12
- in_current_dir do
13
- Spork::AppFramework::Rails.new.version.should == "2.1.0"
14
- end
15
-
16
- create_file("config/environment.rb", 'RAILS_GEM_VERSION = "> 2.1.0"')
17
- in_current_dir do
18
- Spork::AppFramework::Rails.new.version.should == "> 2.1.0"
19
- end
20
- end
21
- end
22
- end
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Spork::AppFramework::Rails do
4
+ describe ".version" do
5
+ it "detects the current version of rails" do
6
+ create_file("config/environment.rb", "RAILS_GEM_VERSION = '2.1.0'")
7
+ in_current_dir do
8
+ Spork::AppFramework::Rails.new.version.should == "2.1.0"
9
+ end
10
+
11
+ create_file("config/environment.rb", 'RAILS_GEM_VERSION = "2.1.0"')
12
+ in_current_dir do
13
+ Spork::AppFramework::Rails.new.version.should == "2.1.0"
14
+ end
15
+
16
+ create_file("config/environment.rb", 'RAILS_GEM_VERSION = "> 2.1.0"')
17
+ in_current_dir do
18
+ Spork::AppFramework::Rails.new.version.should == "> 2.1.0"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,12 +1,12 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe Spork::AppFramework::Unknown do
4
- it "requires bootstrapping" do
5
- Spork::AppFramework::Unknown.new.bootstrap_required?.should == true
6
- end
7
-
8
- it "has no known entry point" do
9
- Spork::AppFramework::Unknown.new.entry_point.should be_nil
10
- end
11
- end
12
-
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Spork::AppFramework::Unknown do
4
+ it "requires bootstrapping" do
5
+ Spork::AppFramework::Unknown.new.bootstrap_required?.should == true
6
+ end
7
+
8
+ it "has no known entry point" do
9
+ Spork::AppFramework::Unknown.new.entry_point.should be_nil
10
+ end
11
+ end
12
+
@@ -1,16 +1,16 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- describe Spork::AppFramework do
4
- describe ".detect_framework" do
5
- it "detects when rails is installed and available" do
6
- create_file("config/environment.rb", "RAILS_GEM_VERSION = '2.1.0'")
7
- in_current_dir do
8
- Spork::AppFramework.detect_framework.short_name.should == "Rails"
9
- end
10
- end
11
-
12
- it "returns Unknown when no framework known detected" do
13
- Spork::AppFramework.detect_framework.short_name.should == "Unknown"
14
- end
15
- end
16
- end
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Spork::AppFramework do
4
+ describe ".detect_framework" do
5
+ it "detects when rails is installed and available" do
6
+ create_file("config/environment.rb", "RAILS_GEM_VERSION = '2.1.0'")
7
+ in_current_dir do
8
+ Spork::AppFramework.detect_framework.short_name.should == "Rails"
9
+ end
10
+ end
11
+
12
+ it "returns Unknown when no framework known detected" do
13
+ Spork::AppFramework.detect_framework.short_name.should == "Unknown"
14
+ end
15
+ end
16
+ end
@@ -1,105 +1,105 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
-
4
- describe Spork::Diagnoser do
5
- after(:each) do
6
- Spork::Diagnoser.remove_hook!
7
- Spork::Diagnoser.loaded_files.clear
8
- end
9
-
10
- def run_simulation(directory, filename = nil, contents = nil, &block)
11
- FileUtils.mkdir_p(directory)
12
- Dir.chdir(directory) do
13
- if filename
14
- File.open(filename, 'wb') { |f| f << contents }
15
- Spork::Diagnoser.install_hook!
16
- require filename
17
- end
18
- yield if block_given?
19
- end
20
- end
21
-
22
- it "installs it's hook and tells you when files have been loaded" do
23
- run_simulation(SPEC_TMP_DIR, 'my_awesome_library_include.rb', '1 + 5')
24
- Spork::Diagnoser.loaded_files.keys.should include_a_string_like('my_awesome_library_include')
25
- end
26
-
27
- it 'excludes files outside of Dir.pwd' do
28
- run_simulation(SPEC_TMP_DIR + '/project_root', '../external_dependency.rb', '1 + 5')
29
- Spork::Diagnoser.loaded_files.keys.should_not include_a_string_like('external_dependency')
30
- end
31
-
32
- it "excludes files outside of Dir.pwd but in ruby's include path" do
33
- directory = SPEC_TMP_DIR + '/project_root'
34
- external_dependency_dir = SPEC_TMP_DIR + '/external_dependency'
35
- $: << external_dependency_dir
36
- FileUtils.mkdir_p(directory)
37
- FileUtils.mkdir_p(external_dependency_dir)
38
- Dir.chdir(directory) do
39
- File.open(external_dependency_dir + '/the_most_awesome_external_dependency_ever.rb', 'wb') { |f| f << 'funtimes = true' }
40
- Spork::Diagnoser.install_hook!
41
- require 'the_most_awesome_external_dependency_ever'
42
- end
43
-
44
- Spork::Diagnoser.loaded_files.keys.should_not include_a_string_like('the_most_awesome_external_dependency_ever')
45
- $:.pop
46
- end
47
-
48
- it "expands files to their fully their fully qualified path" do
49
- directory = SPEC_TMP_DIR + '/project_root'
50
- lib_directory = directory + '/lib'
51
- $: << lib_directory
52
- FileUtils.mkdir_p(lib_directory)
53
- Dir.chdir(directory) do
54
- File.open(lib_directory + "/the_most_awesome_lib_file_ever.rb", "wb") { |f| f << "funtimes = true" }
55
- Spork::Diagnoser.install_hook!
56
- require 'the_most_awesome_lib_file_ever'
57
- end
58
-
59
- Spork::Diagnoser.loaded_files.keys.should include_a_string_like('lib/the_most_awesome_lib_file_ever')
60
- $:.pop
61
- end
62
-
63
- it "can tell the difference between a folder in the project path and a file in an external path" do
64
- directory = SPEC_TMP_DIR + '/project_root'
65
- external_dependency_dir = SPEC_TMP_DIR + '/external_dependency'
66
- $: << external_dependency_dir
67
- FileUtils.mkdir_p(directory)
68
- FileUtils.mkdir_p(external_dependency_dir)
69
- Dir.chdir(directory) do
70
- FileUtils.mkdir_p(directory + '/a_popular_folder_name')
71
- File.open(external_dependency_dir + '/a_popular_folder_name.rb', 'wb') { |f| f << 'funtimes = true' }
72
- Spork::Diagnoser.install_hook!
73
- require 'a_popular_folder_name'
74
- end
75
-
76
- Spork::Diagnoser.loaded_files.keys.should_not include_a_string_like('a_popular_folder_name')
77
- $:.pop
78
- end
79
-
80
- it "filters backtrace beyond the last line matching the entry point" do
81
- Spork::Diagnoser.install_hook!("test_filter/environment.rb")
82
- create_file("test_filter/environment.rb", "require 'test_filter/app.rb'")
83
- create_file("test_filter/app.rb", "require 'test_filter/my_model.rb'")
84
- create_file("test_filter/my_model.rb", "'my model here'")
85
- in_current_dir do
86
- require 'test_filter/environment.rb'
87
- end
88
- f = Spork::Diagnoser.loaded_files
89
- f[f.keys.grep(/app.rb/).first].last.should include('test_filter/environment.rb')
90
- f[f.keys.grep(/my_model.rb/).first].last.should include('test_filter/environment.rb')
91
- f[f.keys.grep(/environment.rb/).first].should == []
92
- end
93
-
94
- describe ".output_results" do
95
- it "outputs the results relative to the current directory" do
96
- Spork::Diagnoser.loaded_files["/project_path/lib/file.rb"] = "/project_path/lib/parent_file.rb:35"
97
- Dir.stub!(:pwd).and_return("/project_path")
98
- out = StringIO.new
99
- Spork::Diagnoser.output_results(out)
100
- out.string.should =~ %r([^/]lib/file.rb)
101
- out.string.should =~ %r([^/]lib/parent_file.rb)
102
- out.string.should_not include("/project_path/")
103
- end
104
- end
105
- end
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+
4
+ describe Spork::Diagnoser do
5
+ after(:each) do
6
+ Spork::Diagnoser.remove_hook!
7
+ Spork::Diagnoser.loaded_files.clear
8
+ end
9
+
10
+ def run_simulation(directory, filename = nil, contents = nil, &block)
11
+ FileUtils.mkdir_p(directory)
12
+ Dir.chdir(directory) do
13
+ if filename
14
+ File.open(filename, 'wb') { |f| f << contents }
15
+ Spork::Diagnoser.install_hook!
16
+ require filename
17
+ end
18
+ yield if block_given?
19
+ end
20
+ end
21
+
22
+ it "installs it's hook and tells you when files have been loaded" do
23
+ run_simulation(SPEC_TMP_DIR, 'my_awesome_library_include.rb', '1 + 5')
24
+ Spork::Diagnoser.loaded_files.keys.should include_a_string_like('my_awesome_library_include')
25
+ end
26
+
27
+ it 'excludes files outside of Dir.pwd' do
28
+ run_simulation(SPEC_TMP_DIR + '/project_root', '../external_dependency.rb', '1 + 5')
29
+ Spork::Diagnoser.loaded_files.keys.should_not include_a_string_like('external_dependency')
30
+ end
31
+
32
+ it "excludes files outside of Dir.pwd but in ruby's include path" do
33
+ directory = SPEC_TMP_DIR + '/project_root'
34
+ external_dependency_dir = SPEC_TMP_DIR + '/external_dependency'
35
+ $: << external_dependency_dir
36
+ FileUtils.mkdir_p(directory)
37
+ FileUtils.mkdir_p(external_dependency_dir)
38
+ Dir.chdir(directory) do
39
+ File.open(external_dependency_dir + '/the_most_awesome_external_dependency_ever.rb', 'wb') { |f| f << 'funtimes = true' }
40
+ Spork::Diagnoser.install_hook!
41
+ require 'the_most_awesome_external_dependency_ever'
42
+ end
43
+
44
+ Spork::Diagnoser.loaded_files.keys.should_not include_a_string_like('the_most_awesome_external_dependency_ever')
45
+ $:.pop
46
+ end
47
+
48
+ it "expands files to their fully their fully qualified path" do
49
+ directory = SPEC_TMP_DIR + '/project_root'
50
+ lib_directory = directory + '/lib'
51
+ $: << lib_directory
52
+ FileUtils.mkdir_p(lib_directory)
53
+ Dir.chdir(directory) do
54
+ File.open(lib_directory + "/the_most_awesome_lib_file_ever.rb", "wb") { |f| f << "funtimes = true" }
55
+ Spork::Diagnoser.install_hook!
56
+ require 'the_most_awesome_lib_file_ever'
57
+ end
58
+
59
+ Spork::Diagnoser.loaded_files.keys.should include_a_string_like('lib/the_most_awesome_lib_file_ever')
60
+ $:.pop
61
+ end
62
+
63
+ it "can tell the difference between a folder in the project path and a file in an external path" do
64
+ directory = SPEC_TMP_DIR + '/project_root'
65
+ external_dependency_dir = SPEC_TMP_DIR + '/external_dependency'
66
+ $: << external_dependency_dir
67
+ FileUtils.mkdir_p(directory)
68
+ FileUtils.mkdir_p(external_dependency_dir)
69
+ Dir.chdir(directory) do
70
+ FileUtils.mkdir_p(directory + '/a_popular_folder_name')
71
+ File.open(external_dependency_dir + '/a_popular_folder_name.rb', 'wb') { |f| f << 'funtimes = true' }
72
+ Spork::Diagnoser.install_hook!
73
+ require 'a_popular_folder_name'
74
+ end
75
+
76
+ Spork::Diagnoser.loaded_files.keys.should_not include_a_string_like('a_popular_folder_name')
77
+ $:.pop
78
+ end
79
+
80
+ it "filters backtrace beyond the last line matching the entry point" do
81
+ Spork::Diagnoser.install_hook!("test_filter/environment.rb")
82
+ create_file("test_filter/environment.rb", "require 'test_filter/app.rb'")
83
+ create_file("test_filter/app.rb", "require 'test_filter/my_model.rb'")
84
+ create_file("test_filter/my_model.rb", "'my model here'")
85
+ in_current_dir do
86
+ require 'test_filter/environment.rb'
87
+ end
88
+ f = Spork::Diagnoser.loaded_files
89
+ f[f.keys.grep(/app.rb/).first].last.should include('test_filter/environment.rb')
90
+ f[f.keys.grep(/my_model.rb/).first].last.should include('test_filter/environment.rb')
91
+ f[f.keys.grep(/environment.rb/).first].should == []
92
+ end
93
+
94
+ describe ".output_results" do
95
+ it "outputs the results relative to the current directory" do
96
+ Spork::Diagnoser.loaded_files["/project_path/lib/file.rb"] = "/project_path/lib/parent_file.rb:35"
97
+ Dir.stub!(:pwd).and_return("/project_path")
98
+ out = StringIO.new
99
+ Spork::Diagnoser.output_results(out)
100
+ out.string.should =~ %r([^/]lib/file.rb)
101
+ out.string.should =~ %r([^/]lib/parent_file.rb)
102
+ out.string.should_not include("/project_path/")
103
+ end
104
+ end
105
+ end
@@ -1,44 +1,44 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- describe Spork::Forker do
4
- describe ".new" do
5
- it "runs a block in a fork" do
6
- $var = "hello world"
7
- Spork::Forker.new { $var = "booyah" }.result
8
- $var.should == "hello world"
9
- end
10
- end
11
-
12
- describe "#result" do
13
- it "returns the result" do
14
- Spork::Forker.new { "results" }.result.should == "results"
15
- end
16
- end
17
-
18
- describe "#running?" do
19
- it "reports when the fork is running" do
20
- forker = Spork::Forker.new { sleep 0.1 }
21
- forker.running?.should == true
22
- forker.result
23
- sleep 0.1
24
- forker.running?.should == false
25
- end
26
- end
27
-
28
- describe "#abort" do
29
- it "aborts a fork and returns nil for the result" do
30
- started_at = Time.now
31
- ended_at = nil
32
- forker = Spork::Forker.new { sleep 5 }
33
- Thread.new do
34
- forker.result.should == nil
35
- ended_at = Time.now
36
- end
37
- sleep 0.5
38
- forker.abort
39
- sleep 0.1
40
- (ended_at - started_at).should be_close(0.5, 0.1)
41
- forker.running?.should == false
42
- end
43
- end
44
- end
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Spork::Forker do
4
+ describe ".new" do
5
+ it "runs a block in a fork" do
6
+ $var = "hello world"
7
+ Spork::Forker.new { $var = "booyah" }.result
8
+ $var.should == "hello world"
9
+ end
10
+ end
11
+
12
+ describe "#result" do
13
+ it "returns the result" do
14
+ Spork::Forker.new { "results" }.result.should == "results"
15
+ end
16
+ end
17
+
18
+ describe "#running?" do
19
+ it "reports when the fork is running" do
20
+ forker = Spork::Forker.new { sleep 0.1 }
21
+ forker.running?.should == true
22
+ forker.result
23
+ sleep 0.1
24
+ forker.running?.should == false
25
+ end
26
+ end
27
+
28
+ describe "#abort" do
29
+ it "aborts a fork and returns nil for the result" do
30
+ started_at = Time.now
31
+ ended_at = nil
32
+ forker = Spork::Forker.new { sleep 5 }
33
+ Thread.new do
34
+ forker.result.should == nil
35
+ ended_at = Time.now
36
+ end
37
+ sleep 0.5
38
+ forker.abort
39
+ sleep 0.1
40
+ (ended_at - started_at).should be_close(0.5, 0.1)
41
+ forker.running?.should == false
42
+ end
43
+ end
44
+ end