bmabey-spork 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Tim Harper
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,72 @@
1
+ = Spork
2
+
3
+ * http://github.com/timcharper/spork
4
+
5
+ == SYNOPSIS:
6
+
7
+ Spork is Tim Harper's implementation of a Drb spec server (similar to the script/spec_server provided by rspec-rails), except rather than using the Rails constant unloading to reload your files, it forks a copy of the server each time you run your specs. The result? Spork runs more solid: it doesn't get corrupted over time, and it properly handles modules and any voo-doo meta programming you may have put in your app.
8
+
9
+ Because Spork uses Kernel.fork, it only works on POSIX systems. This means Windows users are not invited to this party. Sorry :(
10
+
11
+ Spork is still experimental, but is performing solid for us.
12
+
13
+ == INSTALL:
14
+
15
+ [sudo] gem install timcharper-spork --source http://gems.github.com/
16
+
17
+ alternatively:
18
+
19
+ git clone git://github.com/timcharper/spork.git
20
+ cd spork
21
+ gem build spork.gemspec
22
+ sudo gem install spork.gemspec
23
+
24
+ == Usage
25
+
26
+ From a terminal, change to your project directory.
27
+
28
+ Then, bootstrap your spec/spec_helper.rb file.
29
+
30
+ spork --bootstrap
31
+
32
+ Next, edit spec/spec_helper.rb and follow the instructions that were put at the top.
33
+
34
+ Finally, run spork. A spec DRb server will be running!
35
+
36
+ spork
37
+
38
+ To get the TextMate RSpec bundle to use spork, go to config->advanced->shell variables, and add TM_RSPEC_OPTS=--drb.
39
+
40
+ To run from the command line, use spec --drb spec/lib/my_spec.rb
41
+
42
+ Or, you could add --drb to your spec.opts file.
43
+
44
+ == Some potential issues and ways to overcome them:
45
+
46
+ === ActiveRecord reports "connection has gone away" for the first few specs
47
+
48
+ Not sure why this happens, but if you simply add a line to re-establish your database connection on each line as follows, the problem goes away:
49
+
50
+ Spork.each_run do
51
+ ActiveRecord::Base.establish_connection # make sure that the db connection is ready.
52
+ end
53
+
54
+ === Couldn't find formatter class Spec::Runner::Formatter::TextMateFormatter Make sure the --require option is specified *before* --format
55
+
56
+ On one of our projects, many of us using TextMate with spork, only one developer got this error message while the rest of us ran just fine. I don't know exactly why it happened, but requiring the textmate formatter in the prefork block made it go away, like this:
57
+
58
+ Spork.prefork do
59
+ gem "rspec", "= 1.2.6"
60
+ require 'spec'
61
+ ...
62
+ require 'spec/runner/formatter/text_mate_formatter'
63
+ ...
64
+ end
65
+
66
+ == Kudos to
67
+
68
+ * Ben Mabey - help with documentation, testing, suggestions, patches, collaborated with Cucumber support.
69
+ * David Chelimsky - for the fine RSpec testing framework, and the original rspec-rails spec_server implementation, which Spork has built upon.
70
+ * Lead Media Partners - just for being an awesome place to work.
71
+
72
+ Spork (c) 2009 Tim Harper, released under the MIT license
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'spork'
3
+
4
+ Spork.prefork do
5
+ # Loading more in this block will cause your specs to run faster. However,
6
+ # if you change any configuration or code from libraries loaded here, you'll
7
+ # need to restart spork for it take effect.
8
+
9
+ end
10
+
11
+ Spork.each_run do
12
+ # This code will be run each time you run your specs.
13
+
14
+ end
15
+
16
+ # --- Instructions ---
17
+ # - Sort through your spec_helper file. Place as much environment loading
18
+ # code that you don't normally modify during development in the
19
+ # Spork.prefork block.
20
+ # - Place the rest under Spork.each_run block
21
+ # - Any code that is left outside of the blocks will be ran during preforking
22
+ # and during each_run!
23
+ # - These instructions should self-destruct in 10 seconds. If they don't,
24
+ # feel free to delete them.
25
+ #
26
+
27
+
28
+
29
+
data/bin/spork ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9 # Why do we need this?
4
+
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib') unless $LOAD_PATH.include?(File.dirname(__FILE__) + '/../lib')
6
+
7
+ require 'spork'
8
+ require 'spork/runner'
9
+
10
+ begin
11
+ success = Spork::Runner.run(ARGV, STDOUT, STDERR)
12
+ Kernel.exit(success ? 0 : 1)
13
+ rescue SystemExit => e
14
+ Kernel.exit(e.status)
15
+ rescue Exception => e
16
+ STDERR.puts("#{e.message} (#{e.class})")
17
+ STDERR.puts(e.backtrace.join("\n"))
18
+ Kernel.exit 1
19
+ end
20
+
21
+
data/lib/spork.rb ADDED
@@ -0,0 +1,40 @@
1
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
2
+ module Spork
3
+ SPEC_HELPER_FILE = File.join(Dir.pwd, "spec/spec_helper.rb")
4
+
5
+ class << self
6
+ def prefork(&block)
7
+ return if @already_preforked
8
+ @already_preforked = true
9
+ yield
10
+ end
11
+
12
+ def each_run(&block)
13
+ return if @state == :preforking || (@state != :not_using_spork && @already_run)
14
+ @already_run = true
15
+ yield
16
+ end
17
+
18
+ def preforking!
19
+ @state = :preforking
20
+ end
21
+
22
+ def running!
23
+ @state = :running
24
+ end
25
+
26
+ def state
27
+ @state ||= :not_using_spork
28
+ end
29
+
30
+ def exec_prefork(helper_file)
31
+ preforking!
32
+ load(helper_file)
33
+ end
34
+
35
+ def exec_each_run(helper_file)
36
+ running!
37
+ load(helper_file)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,97 @@
1
+ require 'optparse'
2
+ require 'spork/server'
3
+
4
+ module Spork
5
+ class Runner
6
+ attr_reader :server
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("-h", "--help") {|ignore| @options[:help] = true }
23
+ non_option_args = args.select { |arg| ! args[0].match(/^-/) }
24
+ @options[:server_matcher] = non_option_args[0]
25
+ opt.parse!(args)
26
+
27
+ if @options[:help]
28
+ @output.puts opt
29
+ @output.puts
30
+ @output.puts supported_servers_text
31
+ exit(0)
32
+ end
33
+ end
34
+
35
+ def supported_servers_text
36
+ text = StringIO.new
37
+
38
+ text.puts "Supported test frameworks:"
39
+ text.puts Spork::Server.supported_servers.sort { |a,b| a.server_name <=> b.server_name }.map { |s| (s.available? ? '(*) ' : '( ) ') + s.server_name }
40
+ text.puts "\nLegend: ( ) - not detected in project (*) - detected\n"
41
+ text.string
42
+ end
43
+
44
+ def find_server
45
+ if options[:server_matcher]
46
+ @server = Spork::Server.supported_servers(options[:server_matcher]).first
47
+ unless @server
48
+ @output.puts <<-ERROR
49
+ #{options[:server_matcher].inspect} didn't match a supported test framework.
50
+
51
+ #{supported_servers_text}
52
+ ERROR
53
+ return
54
+ end
55
+
56
+ unless @server.available?
57
+ @output.puts <<-USEFUL_ERROR
58
+ I can't find the helper file #{@server.helper_file} for the #{@server.server_name} testing framework.
59
+ Are you running me from the project directory?
60
+ USEFUL_ERROR
61
+ return
62
+ end
63
+ else
64
+ @server = Spork::Server.available_servers.first
65
+ if @server.nil?
66
+ @output.puts <<-USEFUL_ERROR
67
+ I can't find any testing frameworks to use.
68
+ Are you running me from a project directory?
69
+ USEFUL_ERROR
70
+ return
71
+ end
72
+ end
73
+ @server
74
+ end
75
+
76
+ def run
77
+ return false unless find_server
78
+ ENV["DRB"] = 'true'
79
+ ENV["RAILS_ENV"] ||= 'test' if server.using_rails?
80
+ @output.puts "Using #{server.server_name}"
81
+ return server.bootstrap if options[:bootstrap]
82
+ return(false) unless server.preload
83
+ server.run
84
+ return true
85
+ end
86
+
87
+ private
88
+ attr_reader :options
89
+
90
+ end
91
+ end
92
+
93
+
94
+
95
+
96
+
97
+
@@ -0,0 +1,159 @@
1
+ require 'drb/drb'
2
+ require 'rbconfig'
3
+
4
+ # This is based off of spec_server.rb from rspec-rails (David Chelimsky), which was based on Florian Weber's TDDMate
5
+ class Spork::Server
6
+ @@supported_servers = []
7
+
8
+ LOAD_PREFERENCE = ['RSpec', 'Cucumber']
9
+ BOOTSTRAP_FILE = File.dirname(__FILE__) + "/../../assets/bootstrap.rb"
10
+
11
+ def self.port
12
+ raise NotImplemented
13
+ end
14
+
15
+ def self.helper_file
16
+ raise NotImplemented
17
+ end
18
+
19
+ def self.server_name
20
+ self.name.gsub('Spork::Server::', '')
21
+ end
22
+
23
+ def self.inherited(subclass)
24
+ @@supported_servers << subclass
25
+ end
26
+
27
+ def self.available_servers
28
+ supported_servers.select { |s| s.available? }
29
+ end
30
+
31
+ def self.supported_servers(starting_with = nil)
32
+ @@supported_servers.sort! { |a,b| a.load_preference_index <=> b.load_preference_index }
33
+ return @@supported_servers if starting_with.nil?
34
+ @@supported_servers.select do |s|
35
+ s.server_name.match(/^#{Regexp.escape(starting_with)}/i)
36
+ end
37
+ end
38
+
39
+ def self.available?
40
+ File.exist?(helper_file)
41
+ end
42
+
43
+ def self.load_preference_index
44
+ LOAD_PREFERENCE.index(server_name) || LOAD_PREFERENCE.length
45
+ end
46
+
47
+ def self.using_rails?
48
+ File.exist?("config/environment.rb")
49
+ end
50
+
51
+ def self.bootstrapped?
52
+ File.read(helper_file).include?("Spork.prefork")
53
+ end
54
+
55
+ def self.bootstrap
56
+ if bootstrapped?
57
+ puts "Already bootstrapped!"
58
+ return
59
+ end
60
+ puts "Bootstrapping #{helper_file}."
61
+ contents = File.read(helper_file)
62
+ bootstrap_code = File.read(BOOTSTRAP_FILE)
63
+ File.open(helper_file, "wb") do |f|
64
+ f.puts bootstrap_code
65
+ f.puts contents
66
+ end
67
+
68
+ puts "Done. Edit #{helper_file} now with your favorite text editor and follow the instructions."
69
+ true
70
+ end
71
+
72
+ def self.run
73
+ return unless available?
74
+ new.listen
75
+ end
76
+
77
+ def listen
78
+ trap("SIGINT") { sig_int_received }
79
+ trap("SIGTERM") { abort; exit!(0) }
80
+ trap("USR2") { abort; restart } if Signal.list.has_key?("USR2")
81
+ DRb.start_service("druby://127.0.0.1:#{port}", self)
82
+ puts "Spork is ready and listening on #{port}!"
83
+ DRb.thread.join
84
+ end
85
+
86
+ def port
87
+ self.class.port
88
+ end
89
+
90
+ def helper_file
91
+ self.class.helper_file
92
+ end
93
+
94
+ def run(argv, stderr, stdout)
95
+ return false if running?
96
+ $stdout = stdout
97
+ $stderr = stderr
98
+ @child_pid = Kernel.fork do
99
+ Spork.exec_each_run(helper_file)
100
+ run_tests(argv, stderr, stdout)
101
+ end
102
+ Process.wait(@child_pid)
103
+ @child_pid = nil
104
+ true
105
+ end
106
+
107
+ def running?
108
+ !! @child_pid
109
+ end
110
+
111
+ private
112
+ def self.preload
113
+ if bootstrapped?
114
+ puts "Loading Spork.prefork block..."
115
+ Spork.exec_prefork(helper_file)
116
+ else
117
+ puts "#{helper_file} has not been sporked. Run spork --bootstrap to do so."
118
+ # are we in a rails app?
119
+ if using_rails?
120
+ puts "Preloading Rails environment"
121
+ require "config/environment.rb"
122
+ else
123
+ puts "There's nothing I can really do for you. Bailing."
124
+ return false
125
+ end
126
+ end
127
+ true
128
+ end
129
+
130
+ def run_tests(argv, input, output)
131
+ raise NotImplemented
132
+ end
133
+
134
+ def restart
135
+ puts "restarting"
136
+ config = ::Config::CONFIG
137
+ ruby = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
138
+ command_line = [ruby, $0, ARGV].flatten.join(' ')
139
+ exec(command_line)
140
+ end
141
+
142
+ def abort
143
+ if running?
144
+ Process.kill(Signal.list['TERM'], @child_pid)
145
+ true
146
+ end
147
+ end
148
+
149
+ def sig_int_received
150
+ if running?
151
+ abort
152
+ puts "Running specs stopped. Press CTRL-C again to stop the server."
153
+ else
154
+ exit!(0)
155
+ end
156
+ end
157
+ end
158
+
159
+ Dir[File.dirname(__FILE__) + "/server/*.rb"].each { |file| require file }
@@ -0,0 +1,28 @@
1
+ class Spork::Server::Cucumber < Spork::Server
2
+ CUCUMBER_PORT = 8990
3
+ CUCUMBER_HELPER_FILE = File.join(Dir.pwd, "features/support/env.rb")
4
+
5
+ class << self
6
+ def port
7
+ CUCUMBER_PORT
8
+ end
9
+
10
+ def helper_file
11
+ CUCUMBER_HELPER_FILE
12
+ end
13
+
14
+ attr_accessor :step_mother
15
+ end
16
+
17
+ def step_mother
18
+ self.class.step_mother
19
+ end
20
+
21
+ def run_tests(argv, stderr, stdout)
22
+ require 'cucumber/cli/main'
23
+ ::Cucumber::Cli::Main.step_mother = step_mother
24
+ ::Cucumber::Cli::Main.new(argv, stdout, stderr).execute!(step_mother)
25
+ end
26
+ end
27
+
28
+ Spork::Server::Cucumber.step_mother = self
@@ -0,0 +1,22 @@
1
+ class Spork::Server::RSpec < Spork::Server
2
+ RSPEC_PORT = 8989
3
+ RSPEC_HELPER_FILE = File.join(Dir.pwd, "spec/spec_helper.rb")
4
+
5
+ def self.port
6
+ RSPEC_PORT
7
+ end
8
+
9
+ def self.helper_file
10
+ RSPEC_HELPER_FILE
11
+ end
12
+
13
+ def run_tests(argv, stderr, stdout)
14
+ ::Spec::Runner::CommandLine.run(
15
+ ::Spec::Runner::OptionParser.parse(
16
+ argv,
17
+ stderr,
18
+ stdout
19
+ )
20
+ )
21
+ end
22
+ end
@@ -0,0 +1,49 @@
1
+ require 'rubygems'
2
+ require 'spork'
3
+
4
+ Spork.prefork do
5
+ # Loading more in this block will cause your specs to run faster. However,
6
+ # if you change any configuration or code from libraries loaded here, you'll
7
+ # need to restart spork for it take effect.
8
+
9
+ end
10
+
11
+ Spork.each_run do
12
+ # This code will be run each time you run your specs.
13
+
14
+ end
15
+
16
+ # --- Instructions ---
17
+ # - Sort through your spec_helper file. Place as much environment loading
18
+ # code that you don't normally modify during development in the
19
+ # Spork.prefork block.
20
+ # - Place the rest under Spork.each_run block
21
+ # - Any code that is left outside of the blocks will be ran during preforking
22
+ # and during each_run!
23
+ # - These instructions should self-destruct in 10 seconds. If they don't,
24
+ # feel free to delete them.
25
+ #
26
+
27
+
28
+
29
+
30
+ require 'rubygems'
31
+ require 'spec'
32
+
33
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
34
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
35
+ SPEC_TMP_DIR = File.dirname(__FILE__) + "/tmp"
36
+ require 'spork'
37
+ require 'spork/runner.rb'
38
+ require 'spork/server.rb'
39
+ require 'stringio'
40
+
41
+ Spec::Runner.configure do |config|
42
+ config.before(:each) do
43
+ $test_stdout = StringIO.new
44
+ end
45
+
46
+ config.after(:each) do
47
+ FileUtils.rm_rf(SPEC_TMP_DIR)
48
+ end
49
+ end
@@ -0,0 +1,63 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Spork::Runner do
4
+ before(:each) do
5
+ @out, @err = StringIO.new, StringIO.new
6
+ end
7
+
8
+ it "finds a matching server with a prefix" do
9
+ Spork::Runner.new(["rs"], @out, @err).find_server.should == Spork::Server::RSpec
10
+ end
11
+
12
+ it "shows an error message if no matching server was found" do
13
+ Spork::Runner.new(["argle_bargle"], @out, @err).run.should == false
14
+ @out.string.should include(%("argle_bargle" didn't match a supported test framework))
15
+ end
16
+
17
+ it "defaults to use rspec over cucumber" do
18
+ Spork::Server::RSpec.stub!(:available?).and_return(true)
19
+ Spork::Server::Cucumber.stub!(:available?).and_return(true)
20
+ Spork::Runner.new([], @out, @err).find_server.should == Spork::Server::RSpec
21
+ end
22
+
23
+ it "defaults to use cucumber when rspec not available" do
24
+ Spork::Server::RSpec.stub!(:available?).and_return(false)
25
+ Spork::Server::Cucumber.stub!(:available?).and_return(true)
26
+ Spork::Runner.new([], @out, @err).find_server.should == Spork::Server::Cucumber
27
+ end
28
+
29
+ it "bootstraps a server when -b is passed in" do
30
+ Spork::Server::RSpec.stub!(:available?).and_return(true)
31
+ Spork::Server::RSpec.should_receive(:bootstrap).and_return(true)
32
+ Spork::Runner.new(['rspec', '-b'], @out, @err).run
33
+ end
34
+
35
+ it "aborts if it can't preload" do
36
+ Spork::Server::RSpec.stub!(:available?).and_return(true)
37
+ Spork::Server::RSpec.should_receive(:preload).and_return(false)
38
+ Spork::Server::RSpec.should_not_receive(:run)
39
+ Spork::Runner.new(['rspec'], @out, @err).run
40
+ end
41
+
42
+ it "runs the server if all is well" do
43
+ Spork::Server::RSpec.stub!(:available?).and_return(true)
44
+ Spork::Server::RSpec.should_receive(:preload).and_return(true)
45
+ Spork::Server::RSpec.should_receive(:run).and_return(true)
46
+ Spork::Runner.new(['rspec'], @out, @err).run
47
+ @out.string.should include("Using RSpec")
48
+ end
49
+
50
+ it "outputs a list of supported servers, along with supported asterisk" do
51
+ Spork::Server.stub!(:supported_servers).and_return([Spork::Server::RSpec, Spork::Server::Cucumber])
52
+ Spork::Server::RSpec.stub!(:available?).and_return(true)
53
+ Spork::Server::Cucumber.stub!(:available?).and_return(false)
54
+
55
+ Spork::Runner.new(['rspec'], @out, @err).supported_servers_text.should == <<-EOF
56
+ Supported test frameworks:
57
+ ( ) Cucumber
58
+ (*) RSpec
59
+
60
+ Legend: ( ) - not detected in project (*) - detected
61
+ EOF
62
+ end
63
+ end
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Spork::Server::RSpec do
4
+ before(:each) do
5
+ @adapter = Spork::Adapter::RSpec.new
6
+ end
7
+
8
+ it "uses the RSPEC_PORT for it's port" do
9
+ @adapter.port.should == Spork::Adapter::RSpec::RSPEC_PORT
10
+ end
11
+ end
@@ -0,0 +1,126 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ class FakeServer < Spork::Server
4
+ attr_accessor :wait_time
5
+ def self.helper_file
6
+ SPEC_TMP_DIR + "/fake/test_helper.rb"
7
+ end
8
+
9
+ def self.port
10
+ 1000
11
+ end
12
+
13
+ def self.puts(string)
14
+ $test_stdout.puts(string)
15
+ end
16
+
17
+ def puts(string)
18
+ $test_stdout.puts(string)
19
+ end
20
+
21
+ def run_tests(argv, input, output)
22
+ sleep(@wait_time || 0.5)
23
+ end
24
+ end
25
+
26
+ describe Spork::Server do
27
+ describe ".available_servers" do
28
+ before(:each) do
29
+ Spork::Server.supported_servers.each { |s| s.stub!(:available?).and_return(false) }
30
+ end
31
+
32
+ it "returns a list of all available servers" do
33
+ Spork::Server.available_servers.should == []
34
+ Spork::Server::RSpec.stub!(:available?).and_return(true)
35
+ Spork::Server.available_servers.should == [Spork::Server::RSpec]
36
+ end
37
+
38
+ it "returns rspec before cucumber when both are available" do
39
+ Spork::Server::RSpec.stub!(:available?).and_return(true)
40
+ Spork::Server::Cucumber.stub!(:available?).and_return(true)
41
+ Spork::Server.available_servers.should == [Spork::Server::RSpec, Spork::Server::Cucumber]
42
+ end
43
+ end
44
+
45
+ describe ".supported_servers" do
46
+ it "returns all defined servers" do
47
+ Spork::Server.supported_servers.should include(Spork::Server::RSpec)
48
+ Spork::Server.supported_servers.should include(Spork::Server::Cucumber)
49
+ end
50
+
51
+ it "returns a list of servers matching a case-insensitive prefix" do
52
+ Spork::Server.supported_servers("rspec").should == [Spork::Server::RSpec]
53
+ Spork::Server.supported_servers("rs").should == [Spork::Server::RSpec]
54
+ Spork::Server.supported_servers("cuc").should == [Spork::Server::Cucumber]
55
+ end
56
+ end
57
+
58
+ describe "a fake server" do
59
+ def create_helper_file
60
+ FileUtils.mkdir_p(File.dirname(FakeServer.helper_file))
61
+ FileUtils.touch(FakeServer.helper_file)
62
+ end
63
+
64
+ before(:each) do
65
+ @fake = FakeServer.new
66
+ end
67
+
68
+ it "should be available when the helper_file exists" do
69
+ FakeServer.available?.should == false
70
+ create_helper_file
71
+ FakeServer.available?.should == true
72
+ end
73
+
74
+ it "has a name" do
75
+ FakeServer.server_name.should == "FakeServer"
76
+ end
77
+
78
+ it "tells if it's testing framework is being used" do
79
+ Spork::Server.available_servers.should_not include(FakeServer)
80
+ create_helper_file
81
+ Spork::Server.available_servers.should include(FakeServer)
82
+ end
83
+
84
+ it "recognizes if the helper_file has been bootstrapped" do
85
+ bootstrap_contents = File.read(FakeServer::BOOTSTRAP_FILE)
86
+ File.stub!(:read).with(FakeServer.helper_file).and_return("")
87
+ FakeServer.bootstrapped?.should == false
88
+ File.stub!(:read).with(FakeServer.helper_file).and_return(bootstrap_contents)
89
+ FakeServer.bootstrapped?.should == true
90
+ end
91
+
92
+ it "bootstraps a file" do
93
+ create_helper_file
94
+ FakeServer.bootstrap
95
+
96
+ $test_stdout.string.should include("Bootstrapping")
97
+ $test_stdout.string.should include("Edit")
98
+ $test_stdout.string.should include("favorite text editor")
99
+
100
+ File.read(FakeServer.helper_file).should include(File.read(FakeServer::BOOTSTRAP_FILE))
101
+ end
102
+
103
+ it "prevents you from running specs twice in parallel" do
104
+ create_helper_file
105
+ @fake.wait_time = 0.25
106
+ first_run = Thread.new { @fake.run("test", STDOUT, STDIN).should == true }
107
+ sleep(0.05)
108
+ @fake.run("test", STDOUT, STDIN).should == false
109
+
110
+ # wait for the first to finish
111
+ first_run.join
112
+ end
113
+
114
+ it "can abort the current run" do
115
+ create_helper_file
116
+ @fake.wait_time = 5
117
+ started_at = Time.now
118
+ first_run = Thread.new { @fake.run("test", STDOUT, STDIN).should == true }
119
+ sleep(0.05)
120
+ @fake.send(:abort)
121
+ sleep(0.01) while @fake.running?
122
+
123
+ (Time.now - started_at).should < @fake.wait_time
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,44 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ Spork.class_eval do
4
+ def self.reset!
5
+ @state = nil
6
+ @already_run = nil
7
+ @already_preforked = nil
8
+ end
9
+ end
10
+
11
+ describe Spork do
12
+ before(:each) do
13
+ Spork.reset!
14
+ end
15
+
16
+ def spec_helper_simulator
17
+ ran = []
18
+ Spork.prefork do
19
+ ran << :prefork
20
+ end
21
+
22
+ Spork.each_run do
23
+ ran << :each_run
24
+ end
25
+ ran
26
+ end
27
+
28
+ it "only runs the preload block when preforking" do
29
+ ran = []
30
+ Spork.preforking!
31
+ spec_helper_simulator.should == [:prefork]
32
+ end
33
+
34
+ it "only runs the each_run block when running" do
35
+ Spork.preforking!
36
+ spec_helper_simulator
37
+ Spork.running!
38
+ spec_helper_simulator.should == [:each_run]
39
+ end
40
+
41
+ it "runs both blocks when Spork not activated" do
42
+ spec_helper_simulator.should == [:prefork, :each_run]
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bmabey-spork
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.4
5
+ platform: ruby
6
+ authors:
7
+ - Tim Harper
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-30 00:00:00 -07:00
13
+ default_executable: spork
14
+ dependencies: []
15
+
16
+ description: A forking Drb spec server
17
+ email:
18
+ - timcharper+spork@gmail.com
19
+ executables:
20
+ - spork
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - MIT-LICENSE
25
+ - README.rdoc
26
+ files:
27
+ - MIT-LICENSE
28
+ - README.rdoc
29
+ - assets/bootstrap.rb
30
+ - lib/spork.rb
31
+ - lib/spork/runner.rb
32
+ - lib/spork/server.rb
33
+ - lib/spork/server/cucumber.rb
34
+ - lib/spork/server/rspec.rb
35
+ - spec/spec_helper.rb
36
+ - spec/spork/runner_spec.rb
37
+ - spec/spork/server/rspec_spec.rb
38
+ - spec/spork/server_spec.rb
39
+ - spec/spork_spec.rb
40
+ has_rdoc: false
41
+ homepage: http://github.com/timcharper/spork
42
+ post_install_message:
43
+ rdoc_options:
44
+ - --main
45
+ - README.rdoc
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ requirements: []
61
+
62
+ rubyforge_project: spork
63
+ rubygems_version: 1.2.0
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: spork
67
+ test_files:
68
+ - spec/spec_helper.rb
69
+ - spec/spork/runner_spec.rb
70
+ - spec/spork/server/rspec_spec.rb
71
+ - spec/spork/server_spec.rb
72
+ - spec/spork_spec.rb