spork 0.7.5 → 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,34 @@
1
+ Feature: At exit during each run
2
+ In order to make sure at_exit hooks defined during the run get called
3
+ I want to override kernel #at_exit
4
+
5
+ Scenario: at exit
6
+
7
+ Given a file named "spec/spec_helper.rb" with:
8
+ """
9
+ require 'rubygems'
10
+ require 'spec'
11
+ Spork.prefork do
12
+ puts "loading"
13
+ at_exit { puts "prefork at_exit called" }
14
+ end
15
+
16
+ Spork.each_run do
17
+ puts "running"
18
+ at_exit { puts "each_run at_exit called" }
19
+ end
20
+
21
+ """
22
+
23
+ And a file named "spec/did_it_work_spec.rb" with:
24
+ """
25
+ describe "Did it work?" do
26
+ it "checks to see if all worked" do
27
+ puts "ran specs"
28
+ end
29
+ end
30
+ """
31
+ When I fire up a spork instance with "spork rspec"
32
+ And I run spec --drb spec/did_it_work_spec.rb
33
+ Then the output should contain "each_run at_exit called"
34
+ Then the output should not contain "prefork at_exit called"
@@ -37,6 +37,16 @@ module Spork
37
37
  end
38
38
  end
39
39
 
40
+ # Run a block after specs are run.
41
+ #
42
+ # == Parameters
43
+ #
44
+ # * +prevent_double_run+ - Pass false to disable double run prevention
45
+ def after_each_run(prevent_double_run = true, &block)
46
+ return if prevent_double_run && already_ran?(caller.first)
47
+ after_each_run_procs << block
48
+ end
49
+
40
50
  # Used by the server. Sets the state to activate spork. Otherwise, prefork and each_run are run in passive mode, allowing specs without a Spork server.
41
51
  def using_spork!
42
52
  @state = :using_spork
@@ -59,11 +69,18 @@ module Spork
59
69
 
60
70
  # Used by the server. Called to run all of the prefork blocks.
61
71
  def exec_each_run(&block)
72
+ activate_after_each_run_at_exit_hook
62
73
  each_run_procs.each { |p| p.call }
63
74
  each_run_procs.clear
64
75
  yield if block_given?
65
76
  end
66
77
 
78
+ # Used by the server. Called to run all of the after_each_run blocks.
79
+ def exec_after_each_run
80
+ after_each_run_procs.each { |p| p.call }
81
+ after_each_run_procs.clear
82
+ end
83
+
67
84
  # Traps an instance method of a class (or module) so any calls to it don't actually run until Spork.exec_each_run
68
85
  def trap_method(klass, method_name)
69
86
  method_name_without_spork, method_name_with_spork = alias_method_names(method_name, :spork)
@@ -98,6 +115,14 @@ module Spork
98
115
  end
99
116
 
100
117
  private
118
+ def activate_after_each_run_at_exit_hook
119
+ Kernel.module_eval do
120
+ def at_exit(&block)
121
+ Spork.after_each_run(false, &block)
122
+ end
123
+ end
124
+ end
125
+
101
126
  def alias_method_names(method_name, feature)
102
127
  /^(.+?)([\?\!]{0,1})$/.match(method_name.to_s)
103
128
  ["#{$1}_without_spork#{$2}", "#{$1}_with_spork#{$2}"]
@@ -122,5 +147,9 @@ module Spork
122
147
  def each_run_procs
123
148
  @each_run_procs ||= []
124
149
  end
150
+
151
+ def after_each_run_procs
152
+ @after_each_run_procs ||= []
153
+ end
125
154
  end
126
155
  end
@@ -8,7 +8,7 @@ class Spork::AppFramework
8
8
  :Rails => lambda {
9
9
  File.exist?("config/environment.rb") && File.read("config/environment.rb").include?('RAILS_GEM_VERSION')
10
10
  }
11
- }
11
+ } unless defined? SUPPORTED_FRAMEWORKS
12
12
 
13
13
  def self.setup_autoload
14
14
  ([:Unknown] + SUPPORTED_FRAMEWORKS.keys).each do |name|
@@ -41,7 +41,7 @@ class Spork::Forker
41
41
  begin
42
42
  @result = Marshal.load(@server_io)
43
43
  Marshal.dump('ACK', @server_io)
44
- rescue ForkDiedException
44
+ rescue ForkDiedException, EOFError
45
45
  @result = nil
46
46
  end
47
47
  end
@@ -10,7 +10,9 @@ class Spork::RunStrategy::Forking < Spork::RunStrategy
10
10
  $stdout, $stderr = stdout, stderr
11
11
  load test_framework.helper_file
12
12
  Spork.exec_each_run
13
- test_framework.run_tests(argv, stderr, stdout)
13
+ result = test_framework.run_tests(argv, stderr, stdout)
14
+ Spork.exec_after_each_run
15
+ result
14
16
  end
15
17
  @child.result
16
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spork
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.5
4
+ version: 0.7.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Harper
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-28 00:00:00 -07:00
12
+ date: 2010-03-02 00:00:00 -07:00
13
13
  default_executable: spork
14
14
  dependencies: []
15
15
 
@@ -27,6 +27,7 @@ files:
27
27
  - MIT-LICENSE
28
28
  - README.rdoc
29
29
  - assets/bootstrap.rb
30
+ - features/at_exit_during_each_run.feature
30
31
  - features/cucumber_rails_integration.feature
31
32
  - features/diagnostic_mode.feature
32
33
  - features/rails_delayed_loading_workarounds.feature