nimboids-spork 0.8.99

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/Gemfile +6 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +129 -0
  4. data/assets/bootstrap.rb +29 -0
  5. data/bin/spork +20 -0
  6. data/ext/mkrf_conf.rb +26 -0
  7. data/features/at_exit_during_each_run.feature +36 -0
  8. data/features/cucumber_rails_integration.feature +107 -0
  9. data/features/diagnostic_mode.feature +41 -0
  10. data/features/gemfiles/rails3.0/Gemfile +10 -0
  11. data/features/gemfiles/rails3.0/Gemfile.lock +116 -0
  12. data/features/rails_delayed_loading_workarounds.feature +150 -0
  13. data/features/rspec_rails_integration.feature +92 -0
  14. data/features/spork_debugger.feature +108 -0
  15. data/features/steps/general_steps.rb +3 -0
  16. data/features/steps/rails_steps.rb +67 -0
  17. data/features/steps/sandbox_steps.rb +115 -0
  18. data/features/support/background_job.rb +63 -0
  19. data/features/support/bundler_helpers.rb +41 -0
  20. data/features/support/env.rb +105 -0
  21. data/features/unknown_app_framework.feature +42 -0
  22. data/lib/spork.rb +155 -0
  23. data/lib/spork/app_framework.rb +80 -0
  24. data/lib/spork/app_framework/padrino.rb +22 -0
  25. data/lib/spork/app_framework/rails.rb +82 -0
  26. data/lib/spork/app_framework/unknown.rb +6 -0
  27. data/lib/spork/custom_io_streams.rb +25 -0
  28. data/lib/spork/diagnoser.rb +105 -0
  29. data/lib/spork/ext/rails-reloader.rb +14 -0
  30. data/lib/spork/ext/ruby-debug.rb +150 -0
  31. data/lib/spork/forker.rb +71 -0
  32. data/lib/spork/run_strategy.rb +44 -0
  33. data/lib/spork/run_strategy/forking.rb +32 -0
  34. data/lib/spork/run_strategy/magazine.rb +141 -0
  35. data/lib/spork/run_strategy/magazine/magazine_slave.rb +30 -0
  36. data/lib/spork/run_strategy/magazine/magazine_slave_provider.rb +27 -0
  37. data/lib/spork/run_strategy/magazine/ring_server.rb +10 -0
  38. data/lib/spork/runner.rb +90 -0
  39. data/lib/spork/server.rb +76 -0
  40. data/lib/spork/test_framework.rb +167 -0
  41. data/lib/spork/test_framework/cucumber.rb +24 -0
  42. data/lib/spork/test_framework/rspec.rb +14 -0
  43. data/spec/spec_helper.rb +113 -0
  44. data/spec/spork/app_framework/rails_spec.rb +22 -0
  45. data/spec/spork/app_framework/unknown_spec.rb +12 -0
  46. data/spec/spork/app_framework_spec.rb +16 -0
  47. data/spec/spork/diagnoser_spec.rb +105 -0
  48. data/spec/spork/forker_spec.rb +44 -0
  49. data/spec/spork/run_strategy/forking_spec.rb +38 -0
  50. data/spec/spork/runner_spec.rb +50 -0
  51. data/spec/spork/server_spec.rb +15 -0
  52. data/spec/spork/test_framework/cucumber_spec.rb +11 -0
  53. data/spec/spork/test_framework/rspec_spec.rb +10 -0
  54. data/spec/spork/test_framework_shared_examples.rb +23 -0
  55. data/spec/spork/test_framework_spec.rb +90 -0
  56. data/spec/spork_spec.rb +153 -0
  57. data/spec/support/fake_framework.rb +15 -0
  58. data/spec/support/fake_run_strategy.rb +21 -0
  59. metadata +158 -0
@@ -0,0 +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 unless windows?
@@ -0,0 +1,38 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Spork::RunStrategy::Forking do
4
+ before(:each) do
5
+ @fake_framework = FakeFramework.new
6
+ @run_strategy = Spork::RunStrategy::Forking.new(@fake_framework)
7
+
8
+ end
9
+
10
+ it "returns the result of the run_tests method from the forked child" do
11
+ create_helper_file
12
+ @fake_framework.stub!(:run_tests).and_return("tests were ran")
13
+ @run_strategy.run("test", STDOUT, STDIN).should == "tests were ran"
14
+ end
15
+
16
+ it "aborts the current running thread when another run is started" do
17
+ create_helper_file
18
+ @fake_framework.wait_time = 0.25
19
+ first_run = Thread.new { @run_strategy.run("test", STDOUT, STDIN).should == nil }
20
+ sleep(0.05)
21
+ @run_strategy.run("test", STDOUT, STDIN).should == true
22
+
23
+ # wait for the first to finish
24
+ first_run.join
25
+ end
26
+
27
+ it "can abort the current run" do
28
+ create_helper_file
29
+ @fake_framework.wait_time = 5
30
+ started_at = Time.now
31
+ first_run = Thread.new { @run_strategy.run("test", STDOUT, STDIN).should == true }
32
+ sleep(0.05)
33
+ @run_strategy.send(:abort)
34
+ sleep(0.01) while @run_strategy.running?
35
+
36
+ (Time.now - started_at).should < @fake_framework.wait_time
37
+ end
38
+ end unless windows?
@@ -0,0 +1,50 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Spork::Runner do
4
+ def use_test_server(klass = Spork::TestFramework::RSpec)
5
+ @test_framework = klass.new
6
+ Spork::TestFramework.stub!(:factory).and_return(@test_framework)
7
+ end
8
+
9
+ before(:each) do
10
+ @out, @err = StringIO.new, StringIO.new
11
+ end
12
+
13
+ it "finds a matching server with a prefix" do
14
+ Spork::Runner.new(["rs"], @out, @err).find_test_framework.class.should == Spork::TestFramework::RSpec
15
+ end
16
+
17
+ it "shows an error message if no matching server was found" do
18
+ Spork::Runner.new(["argle_bargle"], @out, @err).run.should == false
19
+ @err.string.should include(%(Couldn't find a supported test framework that begins with 'argle_bargle'))
20
+ end
21
+
22
+ it "bootstraps a server when -b is passed in" do
23
+ use_test_server
24
+ @test_framework.should_receive(:bootstrap)
25
+ Spork::Runner.new(['rspec', '-b'], @out, @err).run
26
+ end
27
+
28
+ it "aborts if it can't preload" do
29
+ use_test_server
30
+ @test_framework.should_receive(:preload).and_return(false)
31
+ Spork::Server.should_not_receive(:run)
32
+ Spork::Runner.new(['rspec'], @out, @err).run
33
+ end
34
+
35
+ it "runs the server if all is well" do
36
+ use_test_server
37
+ @test_framework.should_receive(:preload).and_return(true)
38
+ Spork::Server.should_receive(:run)
39
+ Spork::Runner.new(['rspec'], @out, @err).run
40
+ @err.string.should include("Using RSpec")
41
+ end
42
+
43
+ it "outputs a list of supported servers, along with supported asterisk" do
44
+ Spork::Server.stub!(:supported_test_frameworks).and_return([Spork::TestFramework::RSpec, Spork::TestFramework::Cucumber])
45
+ Spork::TestFramework::RSpec.stub!(:available?).and_return(true)
46
+ Spork::TestFramework::Cucumber.stub!(:available?).and_return(false)
47
+
48
+ Spork::Runner.new(['rspec'], @out, @err).supported_test_frameworks_text.should include("(*) RSpec")
49
+ end
50
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Spork::Server do
4
+ describe "a fake server" do
5
+ before(:each) do
6
+ @fake_run_strategy = FakeRunStrategy.new
7
+ @server = Spork::Server.new(:run_strategy => @fake_run_strategy)
8
+ end
9
+
10
+ it "accepts a port" do
11
+ @server.port = 12345
12
+ @server.port.should == 12345
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require File.dirname(__FILE__) + "/../test_framework_shared_examples"
3
+
4
+ describe Spork::TestFramework::Cucumber do
5
+ before(:each) do
6
+ @klass = Spork::TestFramework::Cucumber
7
+ @server = @klass.new
8
+ end
9
+
10
+ it_should_behave_like "a TestFramework"
11
+ end
@@ -0,0 +1,10 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require File.dirname(__FILE__) + "/../test_framework_shared_examples"
3
+
4
+ describe Spork::TestFramework::RSpec do
5
+ before(:each) do
6
+ @klass = Spork::TestFramework::RSpec
7
+ end
8
+
9
+ it_should_behave_like "a TestFramework"
10
+ end
@@ -0,0 +1,23 @@
1
+ shared_examples_for "a TestFramework" do
2
+ describe ".default_port" do
3
+ it "uses the DEFAULT_PORT when the environment variable is not set" do
4
+ @klass.default_port.should == @klass::DEFAULT_PORT
5
+ end
6
+
7
+ it 'uses ENV["#{short_name.upcase}_DRB"] as port if present' do
8
+ env_name = "#{@klass.short_name.upcase}_DRB"
9
+ orig, ENV[env_name] = ENV[env_name], "9000"
10
+ begin
11
+ @klass.default_port.should == 9000
12
+ ensure
13
+ ENV[env_name] = orig
14
+ end
15
+ end
16
+ end
17
+
18
+ describe ".helper_file" do
19
+ it "returns ::HELPER_FILE for the TestFramework" do
20
+ @klass.helper_file.should == @klass::HELPER_FILE
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,90 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Spork::TestFramework do
4
+
5
+ before(:each) do
6
+ @fake = FakeFramework.new
7
+ end
8
+
9
+ describe ".available_test_frameworks" do
10
+ before(:each) do
11
+ Spork::TestFramework.supported_test_frameworks.each { |s| s.stub!(:available?).and_return(false) }
12
+ end
13
+
14
+ it "returns a list of all available servers" do
15
+ Spork::TestFramework.available_test_frameworks.should == []
16
+ Spork::TestFramework::RSpec.stub!(:available?).and_return(true)
17
+ Spork::TestFramework.available_test_frameworks.should == [Spork::TestFramework::RSpec]
18
+ end
19
+
20
+ it "returns rspec before cucumber when both are available" do
21
+ Spork::TestFramework::RSpec.stub!(:available?).and_return(true)
22
+ Spork::TestFramework::Cucumber.stub!(:available?).and_return(true)
23
+ Spork::TestFramework.available_test_frameworks.should == [Spork::TestFramework::RSpec, Spork::TestFramework::Cucumber]
24
+ end
25
+ end
26
+
27
+ describe ".supported_test_frameworks" do
28
+ it "returns all defined servers" do
29
+ Spork::TestFramework.supported_test_frameworks.should include(Spork::TestFramework::RSpec)
30
+ Spork::TestFramework.supported_test_frameworks.should include(Spork::TestFramework::Cucumber)
31
+ end
32
+
33
+ it "returns a list of servers matching a case-insensitive prefix" do
34
+ Spork::TestFramework.supported_test_frameworks("rspec").should == [Spork::TestFramework::RSpec]
35
+ Spork::TestFramework.supported_test_frameworks("rs").should == [Spork::TestFramework::RSpec]
36
+ Spork::TestFramework.supported_test_frameworks("cuc").should == [Spork::TestFramework::Cucumber]
37
+ end
38
+ end
39
+
40
+ describe ".short_name" do
41
+ it "returns the name of the framework, without the namespace prefix" do
42
+ Spork::TestFramework::Cucumber.short_name.should == "Cucumber"
43
+ end
44
+ end
45
+
46
+ describe ".available?" do
47
+ it "returns true when the helper_file exists" do
48
+ FakeFramework.available?.should == false
49
+ create_helper_file(FakeFramework)
50
+ FakeFramework.available?.should == true
51
+ end
52
+ end
53
+
54
+ describe ".bootstrapped?" do
55
+ it "recognizes if the helper_file has been bootstrapped" do
56
+ bootstrap_contents = File.read(FakeFramework::BOOTSTRAP_FILE)
57
+ File.stub!(:read).with(@fake.helper_file).and_return("")
58
+ @fake.bootstrapped?.should == false
59
+ File.stub!(:read).with(@fake.helper_file).and_return(bootstrap_contents)
60
+ @fake.bootstrapped?.should == true
61
+ end
62
+ end
63
+
64
+ describe ".bootstrap" do
65
+ it "bootstraps a file" do
66
+ create_helper_file
67
+ @fake.bootstrap
68
+
69
+ $test_stderr.string.should include("Bootstrapping")
70
+ $test_stderr.string.should include("Edit")
71
+ $test_stderr.string.should include("favorite text editor")
72
+
73
+ File.read(@fake.helper_file).should include(File.read(FakeFramework::BOOTSTRAP_FILE))
74
+ end
75
+ end
76
+
77
+ describe ".factory" do
78
+ it "defaults to use rspec over cucumber" do
79
+ Spork::TestFramework::RSpec.stub!(:available?).and_return(true)
80
+ Spork::TestFramework::Cucumber.stub!(:available?).and_return(true)
81
+ Spork::TestFramework.factory(STDOUT, STDERR).class.should == Spork::TestFramework::RSpec
82
+ end
83
+
84
+ it "defaults to use cucumber when rspec not available" do
85
+ Spork::TestFramework::RSpec.stub!(:available?).and_return(false)
86
+ Spork::TestFramework::Cucumber.stub!(:available?).and_return(true)
87
+ Spork::TestFramework.factory(STDOUT, STDERR).class.should == Spork::TestFramework::Cucumber
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,153 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ Spork.class_eval do
4
+ def self.reset!
5
+ @state = nil
6
+ @using_spork = false
7
+ @already_ran = nil
8
+ @each_run_procs = nil
9
+ end
10
+ end
11
+
12
+ describe Spork do
13
+ before(:each) do
14
+ Spork.reset!
15
+ @ran = []
16
+ end
17
+
18
+ def spec_helper_simulator
19
+ Spork.prefork do
20
+ @ran << :prefork
21
+ end
22
+
23
+ Spork.each_run do
24
+ @ran << :each_run
25
+ end
26
+ @ran
27
+ end
28
+
29
+ it "only runs the preload block when preforking" do
30
+ Spork.exec_prefork { spec_helper_simulator }
31
+ @ran.should == [:prefork]
32
+ end
33
+
34
+ it "only runs the each_run block when running" do
35
+ Spork.exec_prefork { spec_helper_simulator }
36
+ @ran.should == [:prefork]
37
+
38
+ Spork.exec_each_run
39
+ @ran.should == [:prefork, :each_run]
40
+ end
41
+
42
+ it "runs both blocks when Spork not activated" do
43
+ spec_helper_simulator.should == [:prefork, :each_run]
44
+ end
45
+
46
+ it "prevents blocks from being ran twice" do
47
+ Spork.exec_prefork { spec_helper_simulator }
48
+ Spork.exec_each_run
49
+ @ran.clear
50
+ Spork.exec_prefork { spec_helper_simulator }
51
+ Spork.exec_each_run
52
+ @ran.should == []
53
+ end
54
+
55
+ it "runs multiple prefork and each_run blocks at different locations" do
56
+ Spork.prefork { }
57
+ Spork.each_run { }
58
+ spec_helper_simulator.should == [:prefork, :each_run]
59
+ end
60
+
61
+ it "expands a caller line, preserving the line number" do
62
+ Spork.send(:expanded_caller, "/boo/../yah.rb:31").should == "/yah.rb:31"
63
+ end
64
+
65
+ describe "#using_spork?" do
66
+ it "returns true if Spork is being used" do
67
+ Spork.using_spork?.should be_false
68
+ Spork.exec_prefork { }
69
+ Spork.using_spork?.should be_true
70
+ end
71
+ end
72
+
73
+ describe "#trap_method" do
74
+ before(:each) do
75
+ Spork.exec_prefork { }
76
+
77
+ Object.class_eval do
78
+ class TrapTest
79
+ def self.output
80
+ @output ||= []
81
+ end
82
+
83
+ def hello
84
+ TrapTest.output << 'hello'
85
+ end
86
+
87
+ def goodbye
88
+ TrapTest.output << 'goodbye'
89
+ end
90
+
91
+ def say_something!
92
+ TrapTest.output << 'something'
93
+ end
94
+ end
95
+ end
96
+ @trap_test = TrapTest.new
97
+ end
98
+
99
+ after(:each) do
100
+ Object.send(:remove_const, :TrapTest)
101
+ end
102
+
103
+ it "delays execution of a method until after Spork.exec_each_run is called" do
104
+ Spork.exec_prefork { }
105
+ Spork.trap_method(TrapTest, :hello)
106
+ @trap_test.hello
107
+ @trap_test.goodbye
108
+ Spork.exec_each_run
109
+ TrapTest.output.should == ['goodbye', 'hello']
110
+ end
111
+
112
+ it "works with methods that have punctuation" do
113
+ Spork.trap_method(TrapTest, :say_something!)
114
+ @trap_test.say_something!
115
+ TrapTest.output.should == []
116
+ Spork.exec_each_run
117
+ TrapTest.output.should == ['something']
118
+ end
119
+ end
120
+
121
+ describe "#trap_class_method" do
122
+ before(:each) do
123
+ Object.class_eval do
124
+ class TrapTest
125
+ def self.output
126
+ @output ||= []
127
+ end
128
+
129
+ def self.hello
130
+ output << 'hello'
131
+ end
132
+
133
+ def self.goodbye
134
+ output << 'goodbye'
135
+ end
136
+ end
137
+ end
138
+ end
139
+
140
+ after(:each) do
141
+ Object.send(:remove_const, :TrapTest)
142
+ end
143
+
144
+ it "delays execution of a method until after Spork.exec_each_run is called" do
145
+ Spork.exec_prefork { }
146
+ Spork.trap_class_method(TrapTest, :hello)
147
+ TrapTest.hello
148
+ TrapTest.goodbye
149
+ Spork.exec_each_run
150
+ TrapTest.output.should == ['goodbye', 'hello']
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,15 @@
1
+ class FakeFramework < Spork::TestFramework
2
+ include Spork::TestIOStreams
3
+
4
+ attr_accessor :wait_time
5
+ DEFAULT_PORT = 1000
6
+
7
+ def self.helper_file
8
+ SPEC_TMP_DIR + "/fake/test_helper.rb"
9
+ end
10
+
11
+ def run_tests(argv, input, output)
12
+ sleep(@wait_time || 0.5)
13
+ true
14
+ end
15
+ end