spork 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +39 -10
- data/features/cucumber_rails_integration.feature +96 -0
- data/features/rails_integration.feature +16 -23
- data/features/steps/rails_steps.rb +31 -0
- data/features/steps/sandbox_steps.rb +15 -12
- data/features/unknown_app_framework.feature +42 -0
- data/lib/spork/app_framework.rb +6 -2
- data/lib/spork/app_framework/rails.rb +38 -25
- data/lib/spork/app_framework/unknown.rb +0 -4
- data/lib/spork/diagnoser.rb +27 -16
- data/lib/spork/runner.rb +1 -1
- data/lib/spork/server.rb +6 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/spork/app_framework/unknown_spec.rb +14 -0
- data/spec/spork/app_framework_spec.rb +2 -2
- data/spec/spork/diagnoser_spec.rb +25 -11
- metadata +6 -2
data/README.rdoc
CHANGED
@@ -8,8 +8,6 @@ Spork is Tim Harper's implementation of a Drb spec server (similar to the script
|
|
8
8
|
|
9
9
|
Because Spork uses Kernel.fork, it only works on POSIX systems. This means Windows users are not invited to this party. Sorry :(
|
10
10
|
|
11
|
-
Spork is still experimental, but is performing solid for us.
|
12
|
-
|
13
11
|
== INSTALL:
|
14
12
|
|
15
13
|
[sudo] gem install timcharper-spork --source http://gems.github.com/
|
@@ -35,23 +33,54 @@ Finally, run spork. A spec DRb server will be running!
|
|
35
33
|
|
36
34
|
spork
|
37
35
|
|
38
|
-
|
36
|
+
== Diagnostic mode
|
37
|
+
|
38
|
+
Initially, you may find that a few files don't reload automatically. This is because they are being loaded during Spork startup. To identify which project files are being pre-loaded, and why, run:
|
39
|
+
|
40
|
+
spork --diagnose
|
41
|
+
(or spork -d, for short)
|
42
|
+
|
43
|
+
It will output a lot of stuff. At the top you'll find a summary of all project files loaded. Down below, the stack trace for each file (how it got loaded). Spork hooks into Rails and does some magic (TM) to prevent ApplicationController observers, etc from pre-loading. Similar hooks for other ruby frameworks may come as support demands.
|
44
|
+
|
45
|
+
== Running specs over Spork
|
46
|
+
|
47
|
+
=== RSpec
|
48
|
+
|
49
|
+
To get the TextMate RSpec bundle to use spork, go to config->advanced->shell variables, and add:
|
50
|
+
|
51
|
+
TM_RSPEC_OPTS=--drb.
|
39
52
|
|
40
|
-
To run from the command line, use
|
53
|
+
To run from the command line, use:
|
41
54
|
|
42
|
-
|
55
|
+
spec --drb spec/lib/my_spec.rb
|
56
|
+
|
57
|
+
Or, you could add the following flag to your +spec.opts+ file.
|
58
|
+
|
59
|
+
--drb
|
60
|
+
|
61
|
+
=== Cucumber
|
62
|
+
|
63
|
+
Cucumber --drb support for spork is not official yet (but it works). It's the hottest sauce boiling on the world wide web right now. If you can't wait to try it, head on over to Cucumber core-team member Ben Mabey's drb branch and build your own cucumber gem:
|
64
|
+
|
65
|
+
http://github.com/bmabey/cucumber/tree/drb_server
|
66
|
+
|
67
|
+
Use this as a guideline when "Sporking" your features/support/env.rb file
|
68
|
+
|
69
|
+
http://gist.github.com/123370
|
43
70
|
|
44
71
|
== Some potential issues and ways to overcome them:
|
45
72
|
|
46
|
-
===
|
73
|
+
=== Database connections don't work inside of Spork
|
47
74
|
|
48
|
-
|
75
|
+
If you're using ActiveRecord and Rails, Spork will automatically reconnect to the database. However, if you're not using ActiveRecord, or if you're doing some tricky stuff with connections, you'll have to make sure your connections get re-established on each run. In your spec/spec_helper.rb file:
|
49
76
|
|
50
77
|
Spork.each_run do
|
51
|
-
|
78
|
+
# Do your connection re-establishing here
|
52
79
|
end
|
53
80
|
|
54
|
-
=== Couldn't find formatter class Spec::Runner::Formatter::TextMateFormatter
|
81
|
+
=== Couldn't find formatter class Spec::Runner::Formatter::TextMateFormatter
|
82
|
+
|
83
|
+
Make sure the --require option is specified *before* --format
|
55
84
|
|
56
85
|
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
86
|
|
@@ -65,7 +94,7 @@ On one of our projects, many of us using TextMate with spork, only one developer
|
|
65
94
|
|
66
95
|
== Kudos to
|
67
96
|
|
68
|
-
* Ben Mabey - help with documentation, testing, suggestions, patches,
|
97
|
+
* Ben Mabey - help with documentation, testing, suggestions, patches, and bringing Cucumber support.
|
69
98
|
* David Chelimsky - for the fine RSpec testing framework, and the original rspec-rails spec_server implementation, which Spork has built upon.
|
70
99
|
* Lead Media Partners - just for being an awesome place to work.
|
71
100
|
|
@@ -0,0 +1,96 @@
|
|
1
|
+
Feature: Cucumber integration with rails
|
2
|
+
As a developer using cucumber and rails
|
3
|
+
I want to use Spork with Cucumber
|
4
|
+
In order to eliminate the startup cost of my application each time I run them
|
5
|
+
|
6
|
+
Background: Sporked env.rb
|
7
|
+
Given I am in a fresh rails project named "test_rails_project"
|
8
|
+
And the application has a model, observer, route, and application helper
|
9
|
+
And a file named "features/support/env.rb" with:
|
10
|
+
"""
|
11
|
+
require 'rubygems'
|
12
|
+
require 'spork'
|
13
|
+
|
14
|
+
Spork.prefork do
|
15
|
+
# Sets up the Rails environment for Cucumber
|
16
|
+
ENV['RAILS_ENV'] = "cucumber"
|
17
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
|
18
|
+
|
19
|
+
require 'webrat'
|
20
|
+
|
21
|
+
Webrat.configure do |config|
|
22
|
+
config.mode = :rails
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'webrat/core/matchers'
|
26
|
+
require 'cucumber' # I needed to add this... We could move this require to Spork if we think it is better there...
|
27
|
+
require 'cucumber/formatter/unicode' # Comment out this line if you don't want Cucumber Unicode support
|
28
|
+
require 'spec/rails' # I needed to add this as well to avoid the #records error...
|
29
|
+
require 'cucumber/rails/rspec'
|
30
|
+
class ActiveRecord::Base
|
31
|
+
class << self
|
32
|
+
def establish_connection
|
33
|
+
($loaded_stuff ||= []) << 'establish_connection'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
Spork.each_run do
|
40
|
+
# This code will be run each time you run your specs.
|
41
|
+
require 'cucumber/rails/world'
|
42
|
+
Cucumber::Rails.use_transactional_fixtures
|
43
|
+
Cucumber::Rails.bypass_rescue # Comment out this line if you want Rails own error handling
|
44
|
+
# (e.g. rescue_action_in_public / rescue_responses / rescue_from)
|
45
|
+
end
|
46
|
+
"""
|
47
|
+
And a file named "features/cucumber_rails.feature" with:
|
48
|
+
"""
|
49
|
+
Feature: cucumber rails
|
50
|
+
Scenario: did it work
|
51
|
+
Then it should work
|
52
|
+
"""
|
53
|
+
And a file named "features/support/cucumber_rails_helper.rb" with:
|
54
|
+
"""
|
55
|
+
($loaded_stuff ||= []) << 'features/support/cucumber_rails_helper.rb'
|
56
|
+
"""
|
57
|
+
And a file named "features/step_definitions/cucumber_rails_steps.rb" with:
|
58
|
+
"""
|
59
|
+
Then "it should work" do
|
60
|
+
Spork.state.should == :using_spork
|
61
|
+
RAILS_ENV.should == 'cucumber'
|
62
|
+
$loaded_stuff.should include('establish_connection')
|
63
|
+
$loaded_stuff.should include('User')
|
64
|
+
$loaded_stuff.should include('UserObserver')
|
65
|
+
$loaded_stuff.should include('ApplicationHelper')
|
66
|
+
$loaded_stuff.should include('config/routes.rb')
|
67
|
+
$loaded_stuff.should include('features/support/cucumber_rails_helper.rb')
|
68
|
+
puts "It worked!"
|
69
|
+
end
|
70
|
+
"""
|
71
|
+
And a file named "config/environments/cucumber.rb" with:
|
72
|
+
"""
|
73
|
+
$cucumber_used = true
|
74
|
+
"""
|
75
|
+
And a file named "config/database.yml" with:
|
76
|
+
"""
|
77
|
+
cucumber:
|
78
|
+
adapter: sqlite3
|
79
|
+
database: db/cucumber.sqlite3
|
80
|
+
timeout: 5000
|
81
|
+
"""
|
82
|
+
Scenario: Analyzing files were preloaded
|
83
|
+
When I run spork --diagnose
|
84
|
+
Then the output should not contain "user_observer.rb"
|
85
|
+
Then the output should not contain "user.rb"
|
86
|
+
Then the output should not contain "app/controllers/application.rb"
|
87
|
+
Then the output should not contain "app/controllers/application_controller.rb"
|
88
|
+
Then the output should not contain "app/controllers/application_helper.rb"
|
89
|
+
Then the output should not contain "config/routes.rb"
|
90
|
+
Then the output should not contain "features/step_definitions/cucumber_rails_steps.rb"
|
91
|
+
Then the output should not contain "features/support/cucumber_rails_helper.rb"
|
92
|
+
|
93
|
+
Scenario: Running spork with a rails app and observers
|
94
|
+
When I fire up a spork instance with "spork cucumber"
|
95
|
+
And I run cucumber --drb features/cucumber_rails.feature
|
96
|
+
Then the output should contain "It worked!"
|
@@ -13,6 +13,7 @@ Feature: Rails Integration
|
|
13
13
|
require 'spec'
|
14
14
|
|
15
15
|
Spork.prefork do
|
16
|
+
ENV["RAILS_ENV"] = "testeroni"
|
16
17
|
$run_phase = :prefork
|
17
18
|
require File.dirname(__FILE__) + '/../config/environment.rb'
|
18
19
|
end
|
@@ -26,42 +27,33 @@ Feature: Rails Integration
|
|
26
27
|
class << self
|
27
28
|
def establish_connection
|
28
29
|
($loaded_stuff ||= []) << 'establish_connection'
|
29
|
-
puts "Database connection was automatically re-established!"
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
33
33
|
"""
|
34
|
-
And a
|
34
|
+
And the application has a model, observer, route, and application helper
|
35
|
+
And a file named "config/environments/testeroni.rb" with:
|
35
36
|
"""
|
36
|
-
|
37
|
-
($loaded_stuff ||= []) << 'User'
|
38
|
-
end
|
39
|
-
"""
|
40
|
-
And a file named "app/helpers/application_helper.rb" with:
|
41
|
-
"""
|
42
|
-
module ApplicationHelper
|
43
|
-
($loaded_stuff ||= []) << 'ApplicationHelper'
|
44
|
-
end
|
45
|
-
"""
|
46
|
-
And a file named "app/models/user_observer.rb" with:
|
47
|
-
"""
|
48
|
-
class UserObserver < ActiveRecord::Observer
|
49
|
-
($loaded_stuff ||= []) << 'UserObserver'
|
50
|
-
end
|
37
|
+
$testeroni_used = true
|
51
38
|
"""
|
52
|
-
And
|
39
|
+
And a file named "config/database.yml" with:
|
53
40
|
"""
|
54
|
-
|
41
|
+
testeroni:
|
42
|
+
adapter: sqlite3
|
43
|
+
database: db/testeroni.sqlite3
|
44
|
+
timeout: 5000
|
55
45
|
"""
|
56
|
-
And a file named "spec/
|
46
|
+
And a file named "spec/did_it_work_spec.rb" with:
|
57
47
|
"""
|
58
|
-
describe
|
59
|
-
it "
|
48
|
+
describe "Did it work?" do
|
49
|
+
it "checks to see if all worked" do
|
60
50
|
Spork.state.should == :using_spork
|
51
|
+
RAILS_ENV.should == 'testeroni'
|
61
52
|
$loaded_stuff.should include('establish_connection')
|
62
53
|
$loaded_stuff.should include('User')
|
63
54
|
$loaded_stuff.should include('UserObserver')
|
64
55
|
$loaded_stuff.should include('ApplicationHelper')
|
56
|
+
$loaded_stuff.should include('config/routes.rb')
|
65
57
|
puts "Specs successfully run within spork, and all initialization files were loaded"
|
66
58
|
end
|
67
59
|
end
|
@@ -73,9 +65,10 @@ Feature: Rails Integration
|
|
73
65
|
Then the output should not contain "app/controllers/application.rb"
|
74
66
|
Then the output should not contain "app/controllers/application_controller.rb"
|
75
67
|
Then the output should not contain "app/controllers/application_helper.rb"
|
68
|
+
Then the output should not contain "config/routes.rb"
|
76
69
|
|
77
70
|
Scenario: Running spork with a rails app and observers
|
78
71
|
|
79
72
|
When I fire up a spork instance with "spork rspec"
|
80
|
-
And I run spec --drb spec/
|
73
|
+
And I run spec --drb spec/did_it_work_spec.rb
|
81
74
|
Then the output should contain "Specs successfully run within spork, and all initialization files were loaded"
|
@@ -5,3 +5,34 @@ Given /^I am in a fresh rails project named "(.+)"$/ do |folder_name|
|
|
5
5
|
run([SporkWorld::RUBY_BINARY, %x{which rails}.chomp, version_argument, folder_name].compact * " ")
|
6
6
|
@current_dir = File.join(File.join(SporkWorld::SANDBOX_DIR, folder_name))
|
7
7
|
end
|
8
|
+
|
9
|
+
|
10
|
+
Given "the application has a model, observer, route, and application helper" do
|
11
|
+
Given 'a file named "app/models/user.rb" with:',
|
12
|
+
"""
|
13
|
+
class User < ActiveRecord::Base
|
14
|
+
($loaded_stuff ||= []) << 'User'
|
15
|
+
end
|
16
|
+
"""
|
17
|
+
|
18
|
+
Given 'a file named "app/helpers/application_helper.rb" with:',
|
19
|
+
"""
|
20
|
+
module ApplicationHelper
|
21
|
+
($loaded_stuff ||= []) << 'ApplicationHelper'
|
22
|
+
end
|
23
|
+
"""
|
24
|
+
Given 'a file named "app/models/user_observer.rb" with:',
|
25
|
+
"""
|
26
|
+
class UserObserver < ActiveRecord::Observer
|
27
|
+
($loaded_stuff ||= []) << 'UserObserver'
|
28
|
+
end
|
29
|
+
"""
|
30
|
+
Given 'the following code appears in "config/environment.rb" after /Rails::Initializer.run/:',
|
31
|
+
"""
|
32
|
+
config.active_record.observers = :user_observer
|
33
|
+
"""
|
34
|
+
Given 'the following code appears in "config/routes.rb" after /^end/:',
|
35
|
+
"""
|
36
|
+
($loaded_stuff ||= []) << 'config/routes.rb'
|
37
|
+
"""
|
38
|
+
end
|
@@ -21,7 +21,6 @@ Given /^the following code appears in "([^\"]*)" after \/([^\\\/]*)\/:$/ do |fil
|
|
21
21
|
content_lines = File.read(file_name).split("\n")
|
22
22
|
0.upto(content_lines.length - 1) do |line_index|
|
23
23
|
if regex.match(content_lines[line_index])
|
24
|
-
puts "found: #{content_lines[line_index]}"
|
25
24
|
content_lines.insert(line_index + 1, content)
|
26
25
|
break
|
27
26
|
end
|
@@ -30,7 +29,7 @@ Given /^the following code appears in "([^\"]*)" after \/([^\\\/]*)\/:$/ do |fil
|
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
33
|
-
When /^I run (spork|spec)($| .*$)/ do |command, spork_opts|
|
32
|
+
When /^I run (spork|spec|cucumber)($| .*$)/ do |command, spork_opts|
|
34
33
|
if command == 'spork'
|
35
34
|
command = SporkWorld::BINARY
|
36
35
|
else
|
@@ -57,22 +56,26 @@ When /^I fire up a spork instance with "spork(.*)"$/ do |spork_opts|
|
|
57
56
|
end
|
58
57
|
end
|
59
58
|
|
60
|
-
Then /^the output should contain$/ do |text|
|
61
|
-
last_stdout.should include(text)
|
59
|
+
Then /^the (error output|output) should contain$/ do |which, text|
|
60
|
+
(which == "error output" ? last_stderr : last_stdout).should include(text)
|
62
61
|
end
|
63
62
|
|
64
|
-
Then /^the output should contain "(.+)"$/ do |text|
|
65
|
-
last_stdout.should include(text)
|
63
|
+
Then /^the (error output|output) should contain "(.+)"$/ do |which, text|
|
64
|
+
(which == "error output" ? last_stderr : last_stdout).should include(text)
|
66
65
|
end
|
67
66
|
|
68
|
-
Then /^the output should
|
69
|
-
last_stdout.
|
67
|
+
Then /^the (error output|output) should match \/(.+)\/$/ do |which, regex|
|
68
|
+
(which == "error output" ? last_stderr : last_stdout).should match(Regexp.new(regex))
|
70
69
|
end
|
71
70
|
|
72
|
-
Then /^the output should not contain
|
73
|
-
last_stdout.should_not include(text)
|
71
|
+
Then /^the (error output|output) should not contain$/ do |which, text|
|
72
|
+
(which == "error output" ? last_stderr : last_stdout).should_not include(text)
|
74
73
|
end
|
75
74
|
|
76
|
-
Then /^the output should
|
77
|
-
last_stdout.
|
75
|
+
Then /^the (error output|output) should not contain "(.+)"$/ do |which, text|
|
76
|
+
(which == "error output" ? last_stderr : last_stdout).should_not include(text)
|
77
|
+
end
|
78
|
+
|
79
|
+
Then /^the (error output|output) should be$/ do |which, text|
|
80
|
+
(which == "error output" ? last_stderr : last_stdout).should == text
|
78
81
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
Feature: Unknown app frameworks
|
2
|
+
To increase to usefulness of Spork
|
3
|
+
Spork will work with unknown (or no) application frameworks
|
4
|
+
|
5
|
+
Scenario: Unsporked spec_helper
|
6
|
+
|
7
|
+
Given a file named "spec/spec_helper.rb" with:
|
8
|
+
"""
|
9
|
+
require 'rubygems'
|
10
|
+
require 'spec'
|
11
|
+
"""
|
12
|
+
When I run spork
|
13
|
+
Then the error output should contain "Using RSpec"
|
14
|
+
Then the error output should match /You must bootstrap .+spec\/spec_helper\.rb to continue/
|
15
|
+
|
16
|
+
Scenario: Sporked spec_helper
|
17
|
+
Given a file named "spec/spec_helper.rb" with:
|
18
|
+
"""
|
19
|
+
require 'rubygems'
|
20
|
+
require 'spork'
|
21
|
+
|
22
|
+
Spork.prefork do
|
23
|
+
require 'spec'
|
24
|
+
end
|
25
|
+
|
26
|
+
Spork.each_run do
|
27
|
+
$each_run
|
28
|
+
end
|
29
|
+
"""
|
30
|
+
And a file named "spec/did_it_work_spec.rb" with:
|
31
|
+
"""
|
32
|
+
describe "Did it work?" do
|
33
|
+
it "checks to see if all worked" do
|
34
|
+
Spork.state.should == :using_spork
|
35
|
+
puts "Specs successfully run within spork"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
"""
|
39
|
+
When I fire up a spork instance with "spork rspec"
|
40
|
+
And I run spec --drb spec/did_it_work_spec.rb
|
41
|
+
Then the output should contain "Specs successfully run within spork"
|
42
|
+
|
data/lib/spork/app_framework.rb
CHANGED
@@ -33,14 +33,18 @@ class Spork::AppFramework
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def bootstrap_required?
|
36
|
-
|
36
|
+
entry_point.nil?
|
37
|
+
end
|
38
|
+
|
39
|
+
def entry_point
|
40
|
+
nil
|
37
41
|
end
|
38
42
|
|
39
43
|
def preload(&block)
|
40
44
|
yield
|
41
45
|
end
|
42
46
|
|
43
|
-
def
|
47
|
+
def short_name
|
44
48
|
self.class.short_name
|
45
49
|
end
|
46
50
|
end
|
@@ -1,26 +1,38 @@
|
|
1
1
|
class Spork::AppFramework::Rails < Spork::AppFramework
|
2
2
|
|
3
3
|
# TODO - subclass this out to handle different versions of rails
|
4
|
-
|
5
|
-
def self.
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
Spork::AppFramework[:Rails].ninja_patcher.install_hooks
|
11
|
-
result
|
4
|
+
module NinjaPatcher
|
5
|
+
def self.included(klass)
|
6
|
+
klass.class_eval do
|
7
|
+
unless method_defined?(:load_environment_without_spork)
|
8
|
+
alias :load_environment_without_spork :load_environment
|
9
|
+
alias :load_environment :load_environment_with_spork
|
12
10
|
end
|
13
11
|
end
|
14
12
|
end
|
15
13
|
|
16
|
-
def
|
14
|
+
def load_environment_with_spork
|
15
|
+
reset_rails_env
|
16
|
+
result = load_environment_without_spork
|
17
|
+
install_hooks
|
18
|
+
result
|
19
|
+
end
|
20
|
+
|
21
|
+
def install_hooks
|
17
22
|
auto_reestablish_db_connection
|
18
23
|
delay_observer_loading
|
19
24
|
delay_app_preload
|
20
25
|
delay_application_controller_loading
|
26
|
+
delay_route_loading
|
27
|
+
end
|
28
|
+
|
29
|
+
def reset_rails_env
|
30
|
+
return unless ENV['RAILS_ENV']
|
31
|
+
Object.send(:remove_const, :RAILS_ENV)
|
32
|
+
Object.const_set(:RAILS_ENV, ENV['RAILS_ENV'].dup)
|
21
33
|
end
|
22
34
|
|
23
|
-
def
|
35
|
+
def delay_observer_loading
|
24
36
|
if ::Rails::Initializer.instance_methods.include?('load_observers')
|
25
37
|
Spork.trap_method(::Rails::Initializer, :load_observers)
|
26
38
|
end
|
@@ -30,13 +42,13 @@ class Spork::AppFramework::Rails < Spork::AppFramework
|
|
30
42
|
end
|
31
43
|
end
|
32
44
|
|
33
|
-
def
|
45
|
+
def delay_app_preload
|
34
46
|
if ::Rails::Initializer.instance_methods.include?('load_application_classes')
|
35
47
|
Spork.trap_method(::Rails::Initializer, :load_application_classes)
|
36
48
|
end
|
37
49
|
end
|
38
50
|
|
39
|
-
def
|
51
|
+
def delay_application_controller_loading
|
40
52
|
if application_controller_source = ["#{Dir.pwd}/app/controllers/application.rb", "#{Dir.pwd}/app/controllers/application_controller.rb"].find { |f| File.exist?(f) }
|
41
53
|
application_helper_source = "#{Dir.pwd}/app/helpers/application_helper.rb"
|
42
54
|
load_paths = (::ActiveSupport.const_defined?(:Dependencies) ? ::ActiveSupport::Dependencies : ::Dependencies).load_paths
|
@@ -48,17 +60,21 @@ class Spork::AppFramework::Rails < Spork::AppFramework
|
|
48
60
|
end
|
49
61
|
end
|
50
62
|
|
51
|
-
def
|
63
|
+
def auto_reestablish_db_connection
|
52
64
|
if Object.const_defined?(:ActiveRecord)
|
53
65
|
Spork.each_run do
|
66
|
+
# spec/rails is very aggressive about overriding RAILS_ENV and will switch it back to test after the cucumber env was loaded
|
67
|
+
reset_rails_env
|
54
68
|
ActiveRecord::Base.establish_connection
|
55
69
|
end
|
56
70
|
end
|
57
71
|
end
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
72
|
+
|
73
|
+
def delay_route_loading
|
74
|
+
if ::Rails::Initializer.instance_methods.include?('initialize_routing')
|
75
|
+
Spork.trap_method(::Rails::Initializer, :initialize_routing)
|
76
|
+
end
|
77
|
+
end
|
62
78
|
end
|
63
79
|
|
64
80
|
def preload(&block)
|
@@ -66,14 +82,15 @@ class Spork::AppFramework::Rails < Spork::AppFramework
|
|
66
82
|
STDERR.flush
|
67
83
|
ENV["RAILS_ENV"] ||= 'test'
|
68
84
|
preload_rails
|
69
|
-
require environment_file
|
70
85
|
yield
|
71
86
|
end
|
72
87
|
|
73
|
-
def
|
74
|
-
@
|
88
|
+
def entry_point
|
89
|
+
@entry_point ||= File.expand_path("config/environment.rb", Dir.pwd)
|
75
90
|
end
|
76
91
|
|
92
|
+
alias :environment_file :entry_point
|
93
|
+
|
77
94
|
def boot_file
|
78
95
|
@boot_file ||= File.join(File.dirname(environment_file), 'boot')
|
79
96
|
end
|
@@ -96,14 +113,10 @@ class Spork::AppFramework::Rails < Spork::AppFramework
|
|
96
113
|
)
|
97
114
|
end
|
98
115
|
|
99
|
-
def ninja_patcher
|
100
|
-
::Spork::AppFramework::Rails::NinjaPatcher
|
101
|
-
end
|
102
|
-
|
103
116
|
def preload_rails
|
104
117
|
Object.const_set(:RAILS_GEM_VERSION, version) if version
|
105
118
|
require boot_file
|
106
|
-
|
119
|
+
::Rails::Initializer.send(:include, Spork::AppFramework::Rails::NinjaPatcher)
|
107
120
|
end
|
108
121
|
|
109
122
|
end
|
data/lib/spork/diagnoser.rb
CHANGED
@@ -4,8 +4,9 @@ class Spork::Diagnoser
|
|
4
4
|
@loaded_files ||= {}
|
5
5
|
end
|
6
6
|
|
7
|
-
def install_hook!(dir = Dir.pwd)
|
7
|
+
def install_hook!(entry_file = nil, dir = Dir.pwd)
|
8
8
|
@dir = File.expand_path(Dir.pwd, dir)
|
9
|
+
@entry_file = entry_file
|
9
10
|
|
10
11
|
Kernel.class_eval do
|
11
12
|
alias :require_without_diagnoser :require
|
@@ -26,21 +27,7 @@ class Spork::Diagnoser
|
|
26
27
|
def add_included_file(filename, callstack)
|
27
28
|
filename = expand_filename(filename)
|
28
29
|
return unless File.exist?(filename)
|
29
|
-
loaded_files[filename] = caller
|
30
|
-
end
|
31
|
-
|
32
|
-
def expand_filename(filename)
|
33
|
-
([Dir.pwd] + $:).each do |attempted_path|
|
34
|
-
attempted_filename = File.expand_path(filename, attempted_path)
|
35
|
-
return attempted_filename if File.file?(attempted_filename)
|
36
|
-
attempted_filename = attempted_filename + ".rb"
|
37
|
-
return attempted_filename if File.file?(attempted_filename)
|
38
|
-
end
|
39
|
-
filename
|
40
|
-
end
|
41
|
-
|
42
|
-
def subdirectory?(directory)
|
43
|
-
File.expand_path(directory, Dir.pwd).include?(@dir)
|
30
|
+
loaded_files[filename] = filter_callstack(caller) if subdirectory?(filename)
|
44
31
|
end
|
45
32
|
|
46
33
|
def remove_hook!
|
@@ -68,5 +55,29 @@ class Spork::Diagnoser
|
|
68
55
|
stdout.puts loaded_files[file].map(&minimify)
|
69
56
|
end
|
70
57
|
end
|
58
|
+
|
59
|
+
private
|
60
|
+
def filter_callstack(callstack, entry_file = @entry_file)
|
61
|
+
callstack.pop until callstack.empty? || callstack.last.include?(@entry_file) if @entry_file
|
62
|
+
callstack.map do |line|
|
63
|
+
next if line.include?('lib/spork/diagnoser.rb')
|
64
|
+
line.gsub!('require_without_diagnoser', 'require')
|
65
|
+
line
|
66
|
+
end.compact
|
67
|
+
end
|
68
|
+
|
69
|
+
def expand_filename(filename)
|
70
|
+
([Dir.pwd] + $:).each do |attempted_path|
|
71
|
+
attempted_filename = File.expand_path(filename, attempted_path)
|
72
|
+
return attempted_filename if File.file?(attempted_filename)
|
73
|
+
attempted_filename = attempted_filename + ".rb"
|
74
|
+
return attempted_filename if File.file?(attempted_filename)
|
75
|
+
end
|
76
|
+
filename
|
77
|
+
end
|
78
|
+
|
79
|
+
def subdirectory?(directory)
|
80
|
+
File.expand_path(directory, Dir.pwd).include?(@dir)
|
81
|
+
end
|
71
82
|
end
|
72
83
|
end
|
data/lib/spork/runner.rb
CHANGED
@@ -85,7 +85,7 @@ Are you running me from a project directory?
|
|
85
85
|
when options[:diagnose]
|
86
86
|
require 'spork/diagnoser'
|
87
87
|
|
88
|
-
Spork::Diagnoser.install_hook!
|
88
|
+
Spork::Diagnoser.install_hook!(server.entry_point)
|
89
89
|
server.preload
|
90
90
|
Spork::Diagnoser.output_results(@output)
|
91
91
|
return true
|
data/lib/spork/server.rb
CHANGED
@@ -113,6 +113,10 @@ class Spork::Server
|
|
113
113
|
@framework ||= Spork::AppFramework.detect_framework
|
114
114
|
end
|
115
115
|
|
116
|
+
def self.entry_point
|
117
|
+
bootstrapped? ? helper_file : framework.entry_point
|
118
|
+
end
|
119
|
+
|
116
120
|
def self.preload
|
117
121
|
Spork.exec_prefork do
|
118
122
|
unless bootstrapped?
|
@@ -123,6 +127,8 @@ class Spork::Server
|
|
123
127
|
stderr.puts "I can't do anything for you by default for the framework your using: #{framework.short_name}.\nYou must bootstrap #{helper_file} to continue."
|
124
128
|
stderr.flush
|
125
129
|
return false
|
130
|
+
else
|
131
|
+
load(framework.entry_point)
|
126
132
|
end
|
127
133
|
end
|
128
134
|
|
data/spec/spec_helper.rb
CHANGED
@@ -18,6 +18,7 @@ unless $spec_helper_loaded
|
|
18
18
|
config.before(:each) do
|
19
19
|
$test_stdout = StringIO.new
|
20
20
|
$test_stderr = StringIO.new
|
21
|
+
@current_dir = nil
|
21
22
|
end
|
22
23
|
|
23
24
|
config.after(:each) do
|
@@ -41,6 +42,10 @@ unless $spec_helper_loaded
|
|
41
42
|
def current_dir
|
42
43
|
@current_dir ||= SPEC_TMP_DIR
|
43
44
|
end
|
45
|
+
|
46
|
+
def change_current_dir(sub_path)
|
47
|
+
@current_dir = File.expand_path(sub_path, SPEC_TMP_DIR)
|
48
|
+
end
|
44
49
|
end
|
45
50
|
|
46
51
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
Spork::AppFramework[:Unknown]
|
4
|
+
|
5
|
+
describe Spork::AppFramework::Unknown do
|
6
|
+
it "requires bootstrapping" do
|
7
|
+
Spork::AppFramework::Unknown.new.bootstrap_required?.should == true
|
8
|
+
end
|
9
|
+
|
10
|
+
it "has no known entry point" do
|
11
|
+
Spork::AppFramework::Unknown.new.entry_point.should be_nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
@@ -5,12 +5,12 @@ describe Spork::AppFramework do
|
|
5
5
|
it "detects when rails is installed and available" do
|
6
6
|
create_file("config/environment.rb", "RAILS_GEM_VERSION = '2.1.0'")
|
7
7
|
in_current_dir do
|
8
|
-
Spork::AppFramework.detect_framework.
|
8
|
+
Spork::AppFramework.detect_framework.short_name.should == "Rails"
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
it "returns Unknown when no framework known detected" do
|
13
|
-
Spork::AppFramework.detect_framework.
|
13
|
+
Spork::AppFramework.detect_framework.short_name.should == "Unknown"
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -22,13 +22,11 @@ describe Spork::Diagnoser do
|
|
22
22
|
it "installs it's hook and tells you when files have been loaded" do
|
23
23
|
run_simulation(SPEC_TMP_DIR, 'my_awesome_library_include.rb', '1 + 5')
|
24
24
|
Spork::Diagnoser.loaded_files.keys.should include_a_string_like('my_awesome_library_include')
|
25
|
-
|
26
25
|
end
|
27
|
-
|
26
|
+
|
28
27
|
it 'excludes files outside of Dir.pwd' do
|
29
28
|
run_simulation(SPEC_TMP_DIR + '/project_root', '../external_dependency.rb', '1 + 5')
|
30
29
|
Spork::Diagnoser.loaded_files.keys.should_not include_a_string_like('external_dependency')
|
31
|
-
|
32
30
|
end
|
33
31
|
|
34
32
|
it "excludes files outside of Dir.pwd but in ruby's include path" do
|
@@ -79,13 +77,29 @@ describe Spork::Diagnoser do
|
|
79
77
|
$:.pop
|
80
78
|
end
|
81
79
|
|
82
|
-
it "
|
83
|
-
Spork::Diagnoser.
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
90
104
|
end
|
91
105
|
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.5.
|
4
|
+
version: 0.5.2
|
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-06-
|
12
|
+
date: 2009-06-08 00:00:00 -06:00
|
13
13
|
default_executable: spork
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -27,11 +27,13 @@ files:
|
|
27
27
|
- MIT-LICENSE
|
28
28
|
- README.rdoc
|
29
29
|
- assets/bootstrap.rb
|
30
|
+
- features/cucumber_rails_integration.feature
|
30
31
|
- features/diagnostic_mode.feature
|
31
32
|
- features/rails_integration.feature
|
32
33
|
- features/steps/rails_steps.rb
|
33
34
|
- features/steps/sandbox_steps.rb
|
34
35
|
- features/support/env.rb
|
36
|
+
- features/unknown_app_framework.feature
|
35
37
|
- lib/spork.rb
|
36
38
|
- lib/spork/app_framework.rb
|
37
39
|
- lib/spork/app_framework/rails.rb
|
@@ -48,6 +50,7 @@ files:
|
|
48
50
|
- lib/spork/server/rspec.rb
|
49
51
|
- spec/spec_helper.rb
|
50
52
|
- spec/spork/app_framework/rails_spec.rb
|
53
|
+
- spec/spork/app_framework/unknown_spec.rb
|
51
54
|
- spec/spork/app_framework_spec.rb
|
52
55
|
- spec/spork/diagnoser_spec.rb
|
53
56
|
- spec/spork/forker_spec.rb
|
@@ -85,6 +88,7 @@ summary: spork
|
|
85
88
|
test_files:
|
86
89
|
- spec/spec_helper.rb
|
87
90
|
- spec/spork/app_framework/rails_spec.rb
|
91
|
+
- spec/spork/app_framework/unknown_spec.rb
|
88
92
|
- spec/spork/app_framework_spec.rb
|
89
93
|
- spec/spork/diagnoser_spec.rb
|
90
94
|
- spec/spork/forker_spec.rb
|