spork 0.9.0.rc8-x86-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +10 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +134 -0
- data/assets/bootstrap.rb +47 -0
- data/bin/spork +20 -0
- data/features/at_exit_during_each_run.feature +36 -0
- data/features/cucumber_rails_integration.feature +107 -0
- data/features/diagnostic_mode.feature +41 -0
- data/features/gemfiles/rails3.0/Gemfile +14 -0
- data/features/gemfiles/rails3.0/Gemfile.lock +120 -0
- data/features/rails_delayed_loading_workarounds.feature +177 -0
- data/features/rspec_rails_integration.feature +92 -0
- data/features/spork_debugger.feature +108 -0
- data/features/steps/general_steps.rb +3 -0
- data/features/steps/rails_steps.rb +67 -0
- data/features/steps/sandbox_steps.rb +115 -0
- data/features/support/background_job.rb +63 -0
- data/features/support/bundler_helpers.rb +41 -0
- data/features/support/env.rb +105 -0
- data/features/unknown_app_framework.feature +42 -0
- data/lib/spork.rb +155 -0
- data/lib/spork/app_framework.rb +80 -0
- data/lib/spork/app_framework/padrino.rb +22 -0
- data/lib/spork/app_framework/rails.rb +82 -0
- data/lib/spork/app_framework/unknown.rb +6 -0
- data/lib/spork/custom_io_streams.rb +25 -0
- data/lib/spork/diagnoser.rb +105 -0
- data/lib/spork/ext/rails-reloader.rb +14 -0
- data/lib/spork/ext/ruby-debug.rb +150 -0
- data/lib/spork/forker.rb +71 -0
- data/lib/spork/gem_helpers.rb +38 -0
- data/lib/spork/run_strategy.rb +48 -0
- data/lib/spork/run_strategy/forking.rb +35 -0
- data/lib/spork/run_strategy/magazine.rb +151 -0
- data/lib/spork/run_strategy/magazine/magazine_slave.rb +30 -0
- data/lib/spork/run_strategy/magazine/magazine_slave_provider.rb +30 -0
- data/lib/spork/run_strategy/magazine/ring_server.rb +10 -0
- data/lib/spork/runner.rb +90 -0
- data/lib/spork/server.rb +77 -0
- data/lib/spork/test_framework.rb +167 -0
- data/lib/spork/test_framework/cucumber.rb +38 -0
- data/lib/spork/test_framework/rspec.rb +14 -0
- data/spec/spec_helper.rb +113 -0
- data/spec/spork/app_framework/rails_spec.rb +22 -0
- data/spec/spork/app_framework/unknown_spec.rb +12 -0
- data/spec/spork/app_framework_spec.rb +16 -0
- data/spec/spork/diagnoser_spec.rb +105 -0
- data/spec/spork/forker_spec.rb +44 -0
- data/spec/spork/run_strategy/forking_spec.rb +38 -0
- data/spec/spork/runner_spec.rb +50 -0
- data/spec/spork/server_spec.rb +15 -0
- data/spec/spork/test_framework/cucumber_spec.rb +11 -0
- data/spec/spork/test_framework/rspec_spec.rb +10 -0
- data/spec/spork/test_framework_shared_examples.rb +23 -0
- data/spec/spork/test_framework_spec.rb +90 -0
- data/spec/spork_spec.rb +153 -0
- data/spec/support/fake_framework.rb +15 -0
- data/spec/support/fake_run_strategy.rb +21 -0
- metadata +173 -0
@@ -0,0 +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
|
@@ -0,0 +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
|
@@ -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
|
data/spec/spork_spec.rb
ADDED
@@ -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
|