spork 0.8.5 → 0.9.0.rc

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source :gemcutter
2
+ gem 'cucumber', '0.7.3'
3
+ gem 'gherkin', '1.0.27'
4
+ gem 'rspec', '1.3.0'
5
+ gem 'rake'
6
+ gem 'ruby-debug'
@@ -22,22 +22,22 @@ And more to come! Vote for your favorite at http://github.com/timcharper/spork/
22
22
 
23
23
  == Supported Application Frameworks
24
24
 
25
- Actually, Spork ~can~ work with any application framework. But, it ships with hooks and helpers to help make the experience much more "out of the box"
25
+ Actually, Spork ~can~ work with any application framework. But, it ships with hooks and helpers to make an "out of the box" experience.
26
26
 
27
- * Rails
28
-
29
- More can be added! Vote for your favorite at http://github.com/timcharper/spork/issues
27
+ * Rails 3.0 (for Rails 2.{1,2,3}.x, please try spork 0.8.x)
28
+ * Padrino
30
29
 
31
30
  == INSTALL:
32
31
 
32
+ === rubygems:
33
+
33
34
  [sudo] gem install spork
34
35
 
35
- alternatively:
36
+ === bundler:
36
37
 
37
- git clone git://github.com/timcharper/spork.git
38
- cd spork
39
- gem build spork.gemspec
40
- sudo gem install spork.gemspec
38
+ Add to your Gemfile:
39
+
40
+ gem "spork"
41
41
 
42
42
  == Usage
43
43
 
@@ -72,7 +72,7 @@ To get the TextMate RSpec bundle to use spork, go to config->advanced->shell var
72
72
 
73
73
  To run from the command line, use:
74
74
 
75
- spec --drb spec/lib/my_spec.rb
75
+ rspec --drb spec/lib/my_spec.rb
76
76
 
77
77
  Or, you could add the following flag to your +spec.opts+ file.
78
78
 
@@ -88,6 +88,26 @@ Use this as a guideline when "Sporking" your features/support/env.rb file
88
88
 
89
89
  http://gist.github.com/123370
90
90
 
91
+ == Running the Spork test suite
92
+
93
+ If you wish to hack on spork, you will want to run the automated test suite to make sure your changes don't break anything. Spork uses bundler to manage and install dependencies. To start:
94
+
95
+ bundle install
96
+
97
+ Then, to run the specs:
98
+
99
+ bundle exec rspec spec/
100
+
101
+ (or, alternatively...)
102
+
103
+ bundle exec rake
104
+
105
+ === running features ===
106
+
107
+ Essentially:
108
+
109
+ bundle exec cucumber features
110
+
91
111
  == Some potential issues and ways to overcome them:
92
112
 
93
113
  See http://wiki.github.com/timcharper/spork/troubleshooting
@@ -96,6 +116,6 @@ See http://wiki.github.com/timcharper/spork/troubleshooting
96
116
 
97
117
  * Ben Mabey - help with documentation, testing, suggestions, patches, and bringing Cucumber support.
98
118
  * David Chelimsky - for the fine RSpec testing framework, and the original rspec-rails spec_server implementation, which Spork has built upon.
99
- * Lead Media Partners - just for being an awesome place to work.
119
+ * LeadTune - just for being an awesome place to work.
100
120
 
101
- Spork (c) 2009 Tim Harper, released under the MIT license
121
+ Spork (c) 2010 Tim Harper, released under the MIT license
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ require 'rubygems/command.rb'
3
+ require 'rubygems/dependency_installer.rb'
4
+ STDERR.puts "Actually, there aren't any native extensions. I'm just dynamically installing dependencies based off of your operating system"
5
+ inst = Gem::DependencyInstaller.new
6
+
7
+ # this will fail if rake isn't installed.
8
+ begin
9
+ inst.install "rake"
10
+ rescue
11
+ # oh well. Let it fail later.
12
+ end
13
+
14
+ if RUBY_PLATFORM =~ /mswin|mingw/ and RUBY_VERSION < '1.9.1'
15
+ STDERR.puts "installing windows dependencies"
16
+ begin
17
+ inst.install "win32-process", "~> 0.6.1"
18
+ rescue => e
19
+ STDERR.puts "Failed to install necessary dependency gem win32-process: #{e}"
20
+ exit(1)
21
+ end
22
+ end
23
+
24
+ f = File.open(File.join(File.dirname(__FILE__), "Rakefile"), "w") # create dummy rakefile to indicate success
25
+ f.write("task :default\n")
26
+ f.close
@@ -7,7 +7,7 @@ Feature: At exit during each run
7
7
  Given a file named "spec/spec_helper.rb" with:
8
8
  """
9
9
  require 'rubygems'
10
- require 'spec'
10
+ require 'rspec'
11
11
  Spork.prefork do
12
12
  puts "loading"
13
13
  at_exit { puts "prefork at_exit called" }
@@ -23,6 +23,7 @@ Feature: At exit during each run
23
23
 
24
24
  And a file named "spec/did_it_work_spec.rb" with:
25
25
  """
26
+ require 'spec_helper'
26
27
  describe "Did it work?" do
27
28
  it "checks to see if all worked" do
28
29
  puts "ran specs"
@@ -30,6 +31,6 @@ Feature: At exit during each run
30
31
  end
31
32
  """
32
33
  When I fire up a spork instance with "spork rspec"
33
- And I run spec --drb spec/did_it_work_spec.rb
34
+ And I run rspec --drb spec/did_it_work_spec.rb
34
35
  Then the output should contain "second first"
35
36
  Then the output should not contain "prefork at_exit called"
@@ -22,7 +22,7 @@ Feature: Cucumber integration with rails
22
22
 
23
23
  require 'cucumber'
24
24
  require 'cucumber/formatter/unicode' # Comment out this line if you don't want Cucumber Unicode support
25
- require 'spec/rails'
25
+ require 'rspec/rails'
26
26
  require 'cucumber/rails/rspec'
27
27
 
28
28
  #### this is for this test only #######
@@ -45,13 +45,6 @@ Feature: Cucumber integration with rails
45
45
  Scenario: did it work again?
46
46
  Then it should work
47
47
  """
48
- And a file named "features/cucumber_rails_fr.feature" with:
49
- """
50
- # language: fr
51
- Fonction: French
52
- Scénario: ca marche?
53
- Alors ca marche
54
- """
55
48
  And a file named "features/support/cucumber_rails_helper.rb" with:
56
49
  """
57
50
  $loaded_stuff << 'features/support/cucumber_rails_helper.rb'
@@ -0,0 +1,10 @@
1
+ source :gemcutter
2
+ gem 'sqlite3-ruby', '1.2.5'
3
+ gem 'cucumber', '0.7.3'
4
+ gem 'cucumber-rails', '0.3.1'
5
+ gem "gherkin", "1.0.30"
6
+ gem "rspec", "2.0.0.beta.20"
7
+ gem 'rspec-rails', "2.0.0.beta.20"
8
+ gem 'rails', '3.0.0'
9
+ gem 'ruby-debug', '>= 0.10.3'
10
+ gem 'spork', :path => File.expand_path("../../..", File.dirname(__FILE__))
@@ -0,0 +1,116 @@
1
+ PATH
2
+ remote: /Users/timcharper/projects/spork
3
+ specs:
4
+ spork (0.8.4)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ abstract (1.0.0)
10
+ actionmailer (3.0.0)
11
+ actionpack (= 3.0.0)
12
+ mail (~> 2.2.5)
13
+ actionpack (3.0.0)
14
+ activemodel (= 3.0.0)
15
+ activesupport (= 3.0.0)
16
+ builder (~> 2.1.2)
17
+ erubis (~> 2.6.6)
18
+ i18n (~> 0.4.1)
19
+ rack (~> 1.2.1)
20
+ rack-mount (~> 0.6.12)
21
+ rack-test (~> 0.5.4)
22
+ tzinfo (~> 0.3.23)
23
+ activemodel (3.0.0)
24
+ activesupport (= 3.0.0)
25
+ builder (~> 2.1.2)
26
+ i18n (~> 0.4.1)
27
+ activerecord (3.0.0)
28
+ activemodel (= 3.0.0)
29
+ activesupport (= 3.0.0)
30
+ arel (~> 1.0.0)
31
+ tzinfo (~> 0.3.23)
32
+ activeresource (3.0.0)
33
+ activemodel (= 3.0.0)
34
+ activesupport (= 3.0.0)
35
+ activesupport (3.0.0)
36
+ arel (1.0.1)
37
+ activesupport (~> 3.0.0)
38
+ builder (2.1.2)
39
+ columnize (0.3.1)
40
+ cucumber (0.7.3)
41
+ builder (>= 2.1.2)
42
+ diff-lcs (>= 1.1.2)
43
+ gherkin (>= 1.0.27)
44
+ json_pure (>= 1.2.4)
45
+ term-ansicolor (>= 1.0.4)
46
+ cucumber-rails (0.3.1)
47
+ cucumber (>= 0.7.2)
48
+ diff-lcs (1.1.2)
49
+ erubis (2.6.6)
50
+ abstract (>= 1.0.0)
51
+ gherkin (1.0.30)
52
+ trollop (>= 1.16.2)
53
+ i18n (0.4.1)
54
+ json_pure (1.4.6)
55
+ linecache (0.43)
56
+ mail (2.2.6)
57
+ activesupport (>= 2.3.6)
58
+ mime-types
59
+ treetop (>= 1.4.5)
60
+ mime-types (1.16)
61
+ polyglot (0.3.1)
62
+ rack (1.2.1)
63
+ rack-mount (0.6.13)
64
+ rack (>= 1.0.0)
65
+ rack-test (0.5.4)
66
+ rack (>= 1.0)
67
+ rails (3.0.0)
68
+ actionmailer (= 3.0.0)
69
+ actionpack (= 3.0.0)
70
+ activerecord (= 3.0.0)
71
+ activeresource (= 3.0.0)
72
+ activesupport (= 3.0.0)
73
+ bundler (~> 1.0.0)
74
+ railties (= 3.0.0)
75
+ railties (3.0.0)
76
+ actionpack (= 3.0.0)
77
+ activesupport (= 3.0.0)
78
+ rake (>= 0.8.4)
79
+ thor (~> 0.14.0)
80
+ rake (0.8.7)
81
+ rspec (2.0.0.beta.20)
82
+ rspec-core (= 2.0.0.beta.20)
83
+ rspec-expectations (= 2.0.0.beta.20)
84
+ rspec-mocks (= 2.0.0.beta.20)
85
+ rspec-core (2.0.0.beta.20)
86
+ rspec-expectations (2.0.0.beta.20)
87
+ diff-lcs (>= 1.1.2)
88
+ rspec-mocks (2.0.0.beta.20)
89
+ rspec-rails (2.0.0.beta.20)
90
+ rspec (= 2.0.0.beta.20)
91
+ ruby-debug (0.10.3)
92
+ columnize (>= 0.1)
93
+ ruby-debug-base (~> 0.10.3.0)
94
+ ruby-debug-base (0.10.3)
95
+ linecache (>= 0.3)
96
+ sqlite3-ruby (1.2.5)
97
+ term-ansicolor (1.0.5)
98
+ thor (0.14.0)
99
+ treetop (1.4.8)
100
+ polyglot (>= 0.3.1)
101
+ trollop (1.16.2)
102
+ tzinfo (0.3.23)
103
+
104
+ PLATFORMS
105
+ ruby
106
+
107
+ DEPENDENCIES
108
+ cucumber (= 0.7.3)
109
+ cucumber-rails (= 0.3.1)
110
+ gherkin (= 1.0.30)
111
+ rails (= 3.0.0)
112
+ rspec (= 2.0.0.beta.20)
113
+ rspec-rails (= 2.0.0.beta.20)
114
+ ruby-debug (>= 0.10.3)
115
+ spork!
116
+ sqlite3-ruby (= 1.2.5)
@@ -1,7 +1,6 @@
1
1
  Feature: Rails Delayed Work arounds
2
2
  To allow a rails developer to update as many parts of his application as possible without needing to restart Spork
3
3
  Spork automatically tells rails to delay loading certain parts of the application until after the fork occurs
4
- Providing work arounds
5
4
 
6
5
  Background: Rails App with RSpec and Spork
7
6
 
@@ -10,19 +9,26 @@ Feature: Rails Delayed Work arounds
10
9
  """
11
10
  require 'rubygems'
12
11
  require 'spork'
12
+ require 'spork/ext/ruby-debug'
13
13
 
14
14
  Spork.prefork do
15
15
  require File.dirname(__FILE__) + '/../config/environment.rb'
16
- require 'spec'
17
- require 'spec/rails'
16
+ require 'rspec'
17
+ require 'rspec/rails'
18
18
  end
19
19
 
20
20
  Spork.each_run do
21
21
  end
22
22
  """
23
23
  And the application has a model, observer, route, and application helper
24
+
25
+ Given the following code appears in "config/routes.rb" after /routes\.draw/:
26
+ """
27
+ resources :users
28
+ """
24
29
  Given a file named "app/helpers/application_helper.rb" with:
25
30
  """
31
+ require 'reverseatron'
26
32
  module ApplicationHelper
27
33
  include Reverseatron
28
34
  end
@@ -64,8 +70,9 @@ Feature: Rails Delayed Work arounds
64
70
  Scenario: within a view rendered by a controller, calling helper methods from an included module in ApplicationHelper
65
71
  Given a file named "spec/controllers/users_controller_spec.rb" with:
66
72
  """
73
+ require "spec_helper"
67
74
  describe UsersController do
68
- integrate_views
75
+ render_views
69
76
  it "renders a page, using a method inherited from ApplicationController" do
70
77
  get :index
71
78
  response.body.should_not include('Original View')
@@ -81,17 +88,18 @@ Feature: Rails Delayed Work arounds
81
88
  """
82
89
  Given a file named "spec/views/index.html.erb_spec.rb" with:
83
90
  """
91
+ require "spec_helper"
84
92
  describe "/users/index.html.erb" do
85
93
 
86
94
  it "renders the view" do
87
95
  render
88
- response.body.should_not include('Original View')
96
+ rendered.should_not include('Original View')
89
97
  puts "Views are not being cached when rendering directly"
90
98
 
91
- response.body.should include('listing users')
99
+ rendered.should include('listing users')
92
100
  puts "Controller stack is functioning when rendering directly"
93
101
 
94
- response.body.should include('hello miscellaneous')
102
+ rendered.should include('hello miscellaneous')
95
103
  puts "All helper modules were included when rendering directly"
96
104
  end
97
105
  end
@@ -104,12 +112,39 @@ Feature: Rails Delayed Work arounds
104
112
  <p>Here is a list of users</p>
105
113
  """
106
114
 
107
- And I run spec --drb spec/controllers/users_controller_spec.rb
115
+ And I run rspec --drb spec/controllers/users_controller_spec.rb
108
116
  Then the output should contain "Controller stack is functioning when rendering from a controller"
109
- Then the output should contain "Views are not being cached when rendering from a controller"
110
- Then the output should contain "All helper modules were included when rendering from a controller"
117
+ And the output should contain "Views are not being cached when rendering from a controller"
118
+ And the output should contain "All helper modules were included when rendering from a controller"
111
119
 
112
- And I run spec --drb spec/views/index.html.erb_spec.rb
120
+ When I run rspec --drb spec/views/index.html.erb_spec.rb
113
121
  Then the output should contain "Controller stack is functioning when rendering directly"
114
- Then the output should contain "Views are not being cached when rendering directly"
115
- Then the output should contain "All helper modules were included when rendering directly"
122
+ And the output should contain "Views are not being cached when rendering directly"
123
+ And the output should contain "All helper modules were included when rendering directly"
124
+
125
+ Given the contents of "app/helpers/application_helper.rb" are changed to:
126
+ """
127
+ module ApplicationHelper
128
+ def make_it_loud(message)
129
+ message.upcase
130
+ end
131
+ end
132
+ """
133
+ And the contents of "app/views/users/index.html.erb" are changed to:
134
+ """
135
+ <%= make_it_loud('listing users') %>
136
+ """
137
+ And the contents of "spec/controllers/users_controller_spec.rb" are changed to:
138
+ """
139
+ require "spec_helper"
140
+ describe UsersController do
141
+ render_views
142
+ it "renders a page, using a method inherited from ApplicationController" do
143
+ get :index
144
+ response.body.should include('LISTING USERS')
145
+ puts "Helpers aren't being cached"
146
+ end
147
+ end
148
+ """
149
+ When I run rspec --drb spec/controllers/users_controller_spec.rb
150
+ Then the output should contain "Helpers aren't being cached"
@@ -4,7 +4,6 @@ Feature: Rails Integration
4
4
  Providing default hooks and behaviors
5
5
 
6
6
  Background: Rails App with RSpec and Spork
7
-
8
7
  Given I am in a fresh rails project named "test_rails_project"
9
8
  And a file named "spec/spec_helper.rb" with:
10
9
  """
@@ -16,8 +15,8 @@ Feature: Rails Integration
16
15
  # if you change any configuration or code from libraries loaded here, you'll
17
16
  # need to restart spork for it take effect.
18
17
  require File.dirname(__FILE__) + '/../config/environment.rb'
19
- require 'spec'
20
- require 'spec/rails'
18
+ require 'rspec'
19
+ require 'rspec/rails'
21
20
 
22
21
  #### this is for this test only #######
23
22
  $loaded_stuff << 'prefork block' ######
@@ -40,11 +39,12 @@ Feature: Rails Integration
40
39
  Then the output should not contain "app/controllers/application.rb"
41
40
  Then the output should not contain "app/controllers/application_controller.rb"
42
41
  Then the output should not contain "app/controllers/application_helper.rb"
43
- Then the output should not contain "config/routes.rb"
42
+ # Then the output should not contain "config/routes.rb"
44
43
 
45
44
  Scenario: Running spork with a rails app and observers
46
45
  Given a file named "spec/did_it_work_spec.rb" with:
47
46
  """
47
+ require 'spec_helper'
48
48
  describe "Did it work?" do
49
49
  it "checks to see if all worked" do
50
50
  Spork.state.should == :using_spork
@@ -61,14 +61,13 @@ Feature: Rails Integration
61
61
  end
62
62
  """
63
63
  When I fire up a spork instance with "spork rspec"
64
- And I run spec --drb spec/did_it_work_spec.rb
64
+ And I run rspec --drb spec/did_it_work_spec.rb
65
65
  Then the error output should be empty
66
66
  And the output should contain "Specs successfully run within spork, and all initialization files were loaded"
67
67
  And the file "log/test.log" should include "hey there"
68
68
 
69
69
 
70
70
  Scenario: Running spork with a rails app and a non-standard port
71
- Given this scenario is pending until rspec releases a version that supports --port
72
71
  Given a file named "spec/did_it_work_spec.rb" with:
73
72
  """
74
73
  describe "Did it work?" do
@@ -87,7 +86,7 @@ Feature: Rails Integration
87
86
  end
88
87
  """
89
88
  When I fire up a spork instance with "spork rspec --port 7000"
90
- And I run spec --drb --port 7000 spec/did_it_work_spec.rb
89
+ And I run rspec --drb --drb-port 7000 spec/did_it_work_spec.rb
91
90
  Then the error output should be empty
92
91
  And the output should contain "Specs successfully run within spork, and all initialization files were loaded"
93
92
  And the file "log/test.log" should include "hey there"
@@ -10,12 +10,12 @@ Feature: Spork Debugger integration
10
10
  require 'spork'
11
11
  require 'spork/ext/ruby-debug'
12
12
 
13
- Spork.prefork { require 'spec' }
13
+ Spork.prefork { require 'rspec' }
14
14
  Spork.each_run { }
15
15
  """
16
16
  And a file named "spec/debugger_spec.rb" with:
17
17
  """
18
- require File.dirname(__FILE__) + '/spec_helper.rb'
18
+ require 'spec_helper.rb'
19
19
 
20
20
  describe "Debugger" do
21
21
  it "should debug" do
@@ -30,7 +30,7 @@ Feature: Spork Debugger integration
30
30
  """
31
31
 
32
32
  When I fire up a spork instance with "spork rspec"
33
- And I run this in the background: spec --drb spec/debugger_spec.rb
33
+ And I run this in the background: rspec --drb spec/debugger_spec.rb
34
34
 
35
35
  Then the spork window should output a line containing "Debug Session Started"
36
36
 
@@ -57,7 +57,7 @@ Feature: Spork Debugger integration
57
57
 
58
58
  require 'spork/ext/ruby-debug'
59
59
 
60
- Spork.prefork { require 'spec' }
60
+ Spork.prefork { require 'rspec' }
61
61
  Spork.each_run { }
62
62
  """
63
63
 
@@ -75,7 +75,7 @@ Feature: Spork Debugger integration
75
75
  """
76
76
 
77
77
  When I fire up a spork instance with "spork rspec"
78
- And I run this in the background: spec --drb spec/debugger_spec.rb
78
+ And I run this in the background: rspec --drb spec/debugger_spec.rb
79
79
 
80
80
  Then the spork window should output a line containing "Debug Session Started"
81
81
 
@@ -97,7 +97,7 @@ Feature: Spork Debugger integration
97
97
  STDERR.puts("Spork is ready and listening") # trick out the start spork step to believe spork is ready... naughty, but effective.
98
98
  @message = "it worked"
99
99
  debugger
100
- Spork.prefork { require 'spec' }
100
+ Spork.prefork { require 'rspec' }
101
101
  Spork.each_run { }
102
102
  """
103
103
 
@@ -1,13 +1,27 @@
1
1
  Given /^I am in a fresh rails project named "(.+)"$/ do |folder_name|
2
2
  @current_dir = SporkWorld::SANDBOX_DIR
3
- version_argument = ENV['RAILS_VERSION'] ? "_#{ENV['RAILS_VERSION']}_" : nil
3
+ # version_argument = ENV['RAILS_VERSION'] ? "_#{ENV['RAILS_VERSION']}_" : nil
4
4
  # run("#{SporkWorld::RUBY_BINARY} #{%x{which rails}.chomp} #{folder_name}")
5
- run([SporkWorld::RUBY_BINARY, '-I', Cucumber::LIBDIR, %x{which rails}.chomp, version_argument, folder_name].compact * " ")
5
+ run(["rails", "new", folder_name].compact * " ")
6
+
7
+ if last_exit_status != 0
8
+ puts "Couldn't generate project. Output:\nSTDERR:\n-------\n#{last_stderr}\n------\n\nSTDOUT:\n-------\n#{last_stdout}\n\n"
9
+ last_exit_status.should == 0
10
+ end
6
11
  @current_dir = File.join(File.join(SporkWorld::SANDBOX_DIR, folder_name))
12
+ in_current_dir do
13
+ FileUtils.ln_sf(ENV["BUNDLE_GEMFILE"], "Gemfile")
14
+ FileUtils.ln_sf(ENV["BUNDLE_GEMFILE"] + ".lock", "Gemfile.lock")
15
+ FileUtils.ln_sf(File.dirname(ENV["BUNDLE_GEMFILE"]) + "/.bundle", ".bundle")
16
+ end
7
17
  end
8
18
 
9
19
 
10
20
  Given "the application has a model, observer, route, and application helper" do
21
+ Given 'the following code appears in "config/application.rb" after /^end/:',
22
+ """
23
+ ActiveRecord::Base.observers = [:user_observer]
24
+ """
11
25
  Given 'a file named "app/models/user.rb" with:',
12
26
  """
13
27
  class User < ActiveRecord::Base
@@ -50,4 +64,4 @@ Given "the application has a model, observer, route, and application helper" do
50
64
  end
51
65
  end
52
66
  """
53
- end
67
+ end
@@ -17,7 +17,7 @@ When /^the contents of "([^\"]*)" are changed to:$/ do |file_name, file_content|
17
17
  end
18
18
 
19
19
  # the following code appears in "config/environment.rb" after /Rails::Initializer.run/:
20
- Given /^the following code appears in "([^\"]*)" after \/([^\\\/]*)\/:$/ do |file_name, regex, content|
20
+ Given /^the following code appears in "([^\"]*)" after \/([^\/]*)\/:$/ do |file_name, regex, content|
21
21
  regex = Regexp.new(regex)
22
22
  in_current_dir do
23
23
  content_lines = File.read(file_name).split("\n")
@@ -31,11 +31,11 @@ Given /^the following code appears in "([^\"]*)" after \/([^\\\/]*)\/:$/ do |fil
31
31
  end
32
32
  end
33
33
 
34
- When /^I run (spork|spec|cucumber)(| .*)$/ do |command, args|
34
+ When /^I run (spork|rspec|cucumber)(| .*)$/ do |command, args|
35
35
  run(localized_command(command, args))
36
36
  end
37
37
 
38
- When /^I run this in the background: (spork|spec|cucumber)(| .*)$/ do |command, args|
38
+ When /^I run this in the background: (spork|rspec|cucumber)(| .*)$/ do |command, args|
39
39
  @background_script = run_in_background(localized_command(command, args))
40
40
  end
41
41
 
@@ -0,0 +1,42 @@
1
+ require 'bundler'
2
+ module BundlerHelpers
3
+ extend self
4
+ def install_bundle(dir)
5
+ Dir.chdir(dir) do
6
+ command = "env RUBYOPT= BUNDLE_GEMFILE=Gemfile bundle install"
7
+ command << " --relock" unless File.exist?("Gemfile.lock")
8
+ system(command)
9
+ $?.exitstatus
10
+ end
11
+ end
12
+
13
+ def ensure_installed(dir)
14
+ gemfile_lock = dir + "/Gemfile.lock"
15
+ gemfile = dir + "/Gemfile"
16
+ bundle_environment = dir + "/.bundle/environment.rb"
17
+ case
18
+ when File.exist?(gemfile_lock) && File.mtime(gemfile) > File.mtime(gemfile_lock)
19
+ puts "Gemfile #{gemfile} has changed since it was locked. Re-locking..."
20
+ FileUtils.rm(gemfile_lock)
21
+ FileUtils.rm_rf(dir + "/.bundle")
22
+ when ! File.exist?(bundle_environment)
23
+ puts "Bundle #{gemfile} not installed. Installing..."
24
+ when File.mtime(bundle_environment) < File.mtime(gemfile_lock)
25
+ puts "#{gemfile_lock} is newer than #{bundle_environment}. Reinstalling"
26
+ else
27
+ return false
28
+ end
29
+ install_bundle(dir)
30
+ end
31
+
32
+ def expand_gemfile(gemfile)
33
+ possibilities = [File.expand_path(gemfile, Dir.pwd), SporkWorld::GEMFILES_ROOT + gemfile + "Gemfile"]
34
+ possibilities.detect {|f| File.exist?(f)} || raise(RuntimeError, %(Gemfile not found:\n #{possibilities * "\n"}))
35
+ end
36
+
37
+ def set_gemfile(gemfile)
38
+ gemfile = expand_gemfile(gemfile || "rails3.0")
39
+ ensure_installed(File.dirname(gemfile))
40
+ ENV["BUNDLE_GEMFILE"] = gemfile
41
+ end
42
+ end
@@ -1,17 +1,20 @@
1
1
  require 'rubygems'
2
+ require 'pathname'
2
3
  require 'fileutils'
3
4
  require 'forwardable'
4
5
  require 'tempfile'
5
6
  require 'spec/expectations'
6
7
  require 'timeout'
7
- require 'spork'
8
8
 
9
9
  require(File.dirname(__FILE__) + '/background_job.rb')
10
10
 
11
+ SPORK_ROOT = Pathname.new(File.expand_path('../../', File.dirname(__FILE__)))
11
12
  class SporkWorld
12
- BINARY = File.expand_path(File.dirname(__FILE__) + '/../../bin/spork')
13
13
  RUBY_BINARY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
14
- SANDBOX_DIR = File.expand_path(File.join(File.dirname(__FILE__), '../../tmp/sandbox'))
14
+ BINARY = SPORK_ROOT + 'bin/spork'
15
+ SANDBOX_DIR = SPORK_ROOT + "tmp/sandbox"
16
+ GEMFILES_ROOT = SPORK_ROOT + "features/gemfiles"
17
+ SPORK_LIBDIR = SPORK_ROOT + "lib"
15
18
 
16
19
  extend Forwardable
17
20
  def_delegators SporkWorld, :sandbox_dir, :spork_lib_dir
@@ -70,7 +73,7 @@ class SporkWorld
70
73
  stderr_file = Tempfile.new('spork')
71
74
  stderr_file.close
72
75
  in_current_dir do
73
- @last_stdout = `#{command} 2> #{stderr_file.path}`
76
+ @last_stdout = `env RUBYOPT= bundle exec #{command} 2> #{stderr_file.path}`
74
77
  @last_exit_status = $?.exitstatus
75
78
  end
76
79
  @last_stderr = IO.read(stderr_file.path)
@@ -78,7 +81,7 @@ class SporkWorld
78
81
 
79
82
  def run_in_background(command)
80
83
  in_current_dir do
81
- @background_job = BackgroundJob.run(command)
84
+ @background_job = BackgroundJob.run("env RUBYOPT= bundle exec " + command)
82
85
  end
83
86
  @background_jobs << @background_job
84
87
  @background_job
@@ -93,9 +96,12 @@ class SporkWorld
93
96
  @background_jobs.clear
94
97
  @background_job = nil
95
98
  end
96
-
97
99
  end
98
100
 
101
+ require(SPORK_ROOT + "features/support/bundler_helpers.rb")
102
+ BundlerHelpers.set_gemfile(ENV["GEMFILE"])
103
+
104
+
99
105
  World do
100
106
  SporkWorld.new
101
107
  end
@@ -30,7 +30,7 @@ module Spork
30
30
  # * +prevent_double_run+ - Pass false to disable double run prevention
31
31
  def each_run(prevent_double_run = true, &block)
32
32
  return if prevent_double_run && already_ran?(caller.first)
33
- if @state == :using_spork
33
+ if state == :prefork
34
34
  each_run_procs << block
35
35
  else
36
36
  yield
@@ -49,14 +49,13 @@ module Spork
49
49
 
50
50
  # Used by the server. Sets the state to activate spork. Otherwise, prefork and each_run are run in passive mode, allowing specs without a Spork server.
51
51
  def using_spork!
52
- @state = :using_spork
52
+ @using_spork = true
53
53
  end
54
54
 
55
55
  def using_spork?
56
- @state == :using_spork
56
+ @using_spork
57
57
  end
58
58
 
59
- # Used by the server. Returns the current state of Spork.
60
59
  def state
61
60
  @state ||= :not_using_spork
62
61
  end
@@ -64,11 +63,13 @@ module Spork
64
63
  # Used by the server. Called when loading the prefork blocks of the code.
65
64
  def exec_prefork(&block)
66
65
  using_spork!
66
+ @state = :prefork
67
67
  yield
68
68
  end
69
69
 
70
70
  # Used by the server. Called to run all of the prefork blocks.
71
71
  def exec_each_run(&block)
72
+ @state = :run
72
73
  activate_after_each_run_at_exit_hook
73
74
  each_run_procs.each { |p| p.call }
74
75
  each_run_procs.clear
@@ -88,9 +89,9 @@ module Spork
88
89
 
89
90
  klass.class_eval <<-EOF, __FILE__, __LINE__ + 1
90
91
  alias :#{method_name_without_spork} :#{method_name} unless method_defined?(:#{method_name_without_spork})
91
- def #{method_name}(*args)
92
+ def #{method_name}(*args, &block)
92
93
  Spork.each_run(false) do
93
- #{method_name_without_spork}(*args)
94
+ #{method_name_without_spork}(*args, &block)
94
95
  end
95
96
  end
96
97
  EOF
@@ -9,7 +9,10 @@ class Spork::AppFramework
9
9
  File.exist?("config/boot.rb") && File.read("config/boot.rb").include?('PADRINO')
10
10
  },
11
11
  :Rails => lambda {
12
- File.exist?("config/environment.rb") && File.read("config/environment.rb").include?('RAILS_GEM_VERSION')
12
+ File.exist?("config/environment.rb") && (
13
+ File.read("config/environment.rb").include?('RAILS_GEM_VERSION') ||
14
+ (File.exist?("config/application.rb") && File.read("config/application.rb").include?("Rails::Application"))
15
+ )
13
16
  }
14
17
  } unless defined? SUPPORTED_FRAMEWORKS
15
18
 
@@ -1,118 +1,5 @@
1
1
  class Spork::AppFramework::Rails < Spork::AppFramework
2
2
 
3
- # TODO - subclass this out to handle different versions of rails
4
- # Also... this is the nastiest duck punch ever. Clean this up.
5
- module NinjaPatcher
6
- def self.included(klass)
7
- klass.class_eval do
8
- unless method_defined?(:load_environment_without_spork)
9
- alias :load_environment_without_spork :load_environment
10
- alias :load_environment :load_environment_with_spork
11
- end
12
-
13
- def self.run_with_spork(*args, &block) # it's all fun and games until someone gets an eye poked out
14
- if ENV['RAILS_ENV']
15
- Object.send(:remove_const, :RAILS_ENV)
16
- Object.const_set(:RAILS_ENV, ENV['RAILS_ENV'].dup)
17
- end
18
- run_without_spork(*args, &block)
19
- end
20
-
21
- class << self
22
- unless method_defined?(:run_without_spork)
23
- alias :run_without_spork :run
24
- alias :run :run_with_spork
25
- end
26
- end
27
- end
28
- end
29
-
30
- def load_environment_with_spork
31
- result = load_environment_without_spork
32
- install_hooks
33
- result
34
- end
35
-
36
- def install_hooks
37
- auto_reestablish_db_connection
38
- delay_observer_loading
39
- delay_app_preload
40
- delay_application_controller_loading
41
- delay_route_loading
42
- delay_eager_view_loading
43
- end
44
-
45
- def reset_rails_env
46
- return unless ENV['RAILS_ENV']
47
- Object.send(:remove_const, :RAILS_ENV)
48
- Object.const_set(:RAILS_ENV, ENV['RAILS_ENV'].dup)
49
- end
50
-
51
- def delay_observer_loading
52
- if ::Rails::Initializer.instance_methods.map(&:to_sym).include?(:load_observers)
53
- Spork.trap_method(::Rails::Initializer, :load_observers)
54
- end
55
- if Object.const_defined?(:ActionController)
56
- require "action_controller/dispatcher.rb"
57
- Spork.trap_class_method(::ActionController::Dispatcher, :define_dispatcher_callbacks) if ActionController::Dispatcher.respond_to?(:define_dispatcher_callbacks)
58
- end
59
- end
60
-
61
- def delay_app_preload
62
- if ::Rails::Initializer.instance_methods.map(&:to_sym).include?(:load_application_classes)
63
- Spork.trap_method(::Rails::Initializer, :load_application_classes)
64
- end
65
- end
66
-
67
- def delay_application_controller_loading
68
- if application_controller_source = ["#{Dir.pwd}/app/controllers/application.rb", "#{Dir.pwd}/app/controllers/application_controller.rb"].find { |f| File.exist?(f) }
69
- application_helper_source = "#{Dir.pwd}/app/helpers/application_helper.rb"
70
- load_paths = (::ActiveSupport.const_defined?(:Dependencies) ? ::ActiveSupport::Dependencies : ::Dependencies).load_paths
71
- load_paths.unshift(File.expand_path('rails_stub_files', File.dirname(__FILE__)))
72
- Spork.each_run do
73
- require application_controller_source
74
- require application_helper_source if File.exist?(application_helper_source)
75
- # update the rails magic to refresh the module
76
- ApplicationController.send(:helper, ApplicationHelper)
77
- end
78
- end
79
- end
80
-
81
- def auto_reestablish_db_connection
82
- if Object.const_defined?(:ActiveRecord)
83
- Spork.each_run do
84
- # rails lib/test_help.rb is very aggressive about overriding RAILS_ENV and will switch it back to test after the cucumber env was loaded
85
- reset_rails_env
86
- ActiveRecord::Base.establish_connection
87
- end
88
- end
89
- end
90
-
91
- def delay_route_loading
92
- if ::Rails::Initializer.instance_methods.map(&:to_sym).include?(:initialize_routing)
93
- Spork.trap_method(::Rails::Initializer, :initialize_routing)
94
- end
95
- end
96
-
97
- def delay_eager_view_loading
98
- # So, in testing mode it seems it would be optimal to not eager load
99
- # views (as your may only run a test that uses one or two views).
100
- # However, I decided to delay eager loading rather than force it to
101
- # disable because you may wish to eager load your views (I.E. you're
102
- # testing concurrency)
103
-
104
- # Rails 2.3.x +
105
- if defined?(::ActionView::Template::EagerPath)
106
- Spork.trap_method(::ActionView::Template::EagerPath, :load!)
107
- end
108
- # Rails 2.2.x
109
- if defined?(::ActionView::PathSet::Path)
110
- Spork.trap_method(::ActionView::PathSet::Path, :load)
111
- end
112
- # Rails 2.0.5 - 2.1.x don't appear to eager cache views.
113
- end
114
- end
115
-
116
3
  def preload(&block)
117
4
  STDERR.puts "Preloading Rails environment"
118
5
  STDERR.flush
@@ -131,6 +18,10 @@ class Spork::AppFramework::Rails < Spork::AppFramework
131
18
  @boot_file ||= File.join(File.dirname(environment_file), 'boot')
132
19
  end
133
20
 
21
+ def application_file
22
+ @application_file ||= File.join(File.dirname(environment_file), 'application')
23
+ end
24
+
134
25
  def environment_contents
135
26
  @environment_contents ||= File.read(environment_file)
136
27
  end
@@ -139,7 +30,7 @@ class Spork::AppFramework::Rails < Spork::AppFramework
139
30
  @vendor ||= File.expand_path("vendor/rails", Dir.pwd)
140
31
  end
141
32
 
142
- def version
33
+ def deprecated_version
143
34
  @version ||= (
144
35
  if /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/.match(environment_contents)
145
36
  $1
@@ -150,9 +41,42 @@ class Spork::AppFramework::Rails < Spork::AppFramework
150
41
  end
151
42
 
152
43
  def preload_rails
153
- Object.const_set(:RAILS_GEM_VERSION, version) if version
154
- require boot_file
155
- ::Rails::Initializer.send(:include, Spork::AppFramework::Rails::NinjaPatcher)
44
+ if deprecated_version && (not deprecated_version.match?(/^3/))
45
+ puts "This version of spork only supports Rails 3.0. To use spork with rails 2.3.x, downgrade to spork 0.8.x."
46
+ exit 1
47
+ end
48
+ require application_file
49
+ ::Rails.application
50
+ ::Rails::Engine.class_eval do
51
+ def eager_load!
52
+ # turn off eager_loading, all together
53
+ end
54
+ end
55
+ # Spork.trap_method(::AbstractController::Helpers::ClassMethods, :helper)
56
+ Spork.trap_method(::ActiveModel::Observing::ClassMethods, :instantiate_observers)
57
+ Spork.each_run { ActiveRecord::Base.establish_connection } if Object.const_defined?(:ActiveRecord)
58
+
59
+
60
+ AbstractController::Helpers::ClassMethods.module_eval do
61
+ def helper(*args, &block)
62
+ ([args].flatten - [:all]).each do |arg|
63
+ next unless arg.is_a?(String)
64
+ filename = arg + "_helper"
65
+ unless ::ActiveSupport::Dependencies.search_for_file(filename)
66
+ # this error message must raise in the format such that LoadError#path returns the filename
67
+ raise LoadError.new("Missing helper file helpers/%s.rb" % filename)
68
+ end
69
+ end
70
+
71
+ Spork.each_run(false) do
72
+ modules_for_helpers(args).each do |mod|
73
+ add_template_helper(mod)
74
+ end
75
+
76
+ _helpers.module_eval(&block) if block_given?
77
+ end
78
+ end
79
+ end
156
80
  end
157
81
 
158
82
  end
@@ -3,15 +3,7 @@
3
3
  # as they come in
4
4
  require 'drb'
5
5
  require 'rinda/ring'
6
- if RUBY_PLATFORM =~ /mswin|mingw/ and RUBY_VERSION < '1.9.1'
7
- begin
8
- require 'win32/process'
9
- rescue LoadError
10
- puts "The 'win32-process' gem is required for windows Spork support with ruby 1.9.1 and lower. Install it, or if using bundler, add it to your Gemfile."
11
- end
12
- end
13
-
14
- require 'rubygems' # used for Gem.ruby
6
+ require 'win32/process' if RUBY_PLATFORM =~ /mswin|mingw/ and RUBY_VERSION < '1.9.1'
15
7
 
16
8
  $:.unshift(File.dirname(__FILE__))
17
9
  require 'magazine/magazine_slave'
@@ -1,4 +1,5 @@
1
1
  require 'optparse'
2
+ require 'stringio'
2
3
 
3
4
  module Spork
4
5
  # This is used by bin/spork. It's wrapped in a class because it's easier to test that way.
@@ -118,7 +118,7 @@ class Spork::TestFramework
118
118
 
119
119
  def preload
120
120
  Spork.exec_prefork do
121
- unless bootstrapped?
121
+ if not bootstrapped?
122
122
  stderr.puts "#{helper_file} has not been bootstrapped. Run spork --bootstrap to do so."
123
123
  stderr.flush
124
124
 
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spork
3
3
  version: !ruby/object:Gem::Version
4
- hash: 53
5
- prerelease:
4
+ hash: 7712082
5
+ prerelease: true
6
6
  segments:
7
7
  - 0
8
- - 8
9
- - 5
10
- version: 0.8.5
8
+ - 9
9
+ - 0
10
+ - rc
11
+ version: 0.9.0.rc
11
12
  platform: ruby
12
13
  authors:
13
14
  - Tim Harper
@@ -16,7 +17,7 @@ autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2011-05-26 00:00:00 -06:00
20
+ date: 2010-09-12 00:00:00 -06:00
20
21
  default_executable: spork
21
22
  dependencies: []
22
23
 
@@ -25,12 +26,13 @@ email:
25
26
  - timcharper+spork@gmail.com
26
27
  executables:
27
28
  - spork
28
- extensions: []
29
-
29
+ extensions:
30
+ - ext/mkrf_conf.rb
30
31
  extra_rdoc_files:
31
32
  - MIT-LICENSE
32
33
  - README.rdoc
33
34
  files:
35
+ - Gemfile
34
36
  - README.rdoc
35
37
  - MIT-LICENSE
36
38
  - lib/spork/app_framework/padrino.rb
@@ -61,6 +63,8 @@ files:
61
63
  - features/at_exit_during_each_run.feature
62
64
  - features/cucumber_rails_integration.feature
63
65
  - features/diagnostic_mode.feature
66
+ - features/gemfiles/rails3.0/Gemfile
67
+ - features/gemfiles/rails3.0/Gemfile.lock
64
68
  - features/rails_delayed_loading_workarounds.feature
65
69
  - features/rspec_rails_integration.feature
66
70
  - features/spork_debugger.feature
@@ -68,6 +72,7 @@ files:
68
72
  - features/steps/rails_steps.rb
69
73
  - features/steps/sandbox_steps.rb
70
74
  - features/support/background_job.rb
75
+ - features/support/bundler_helpers.rb
71
76
  - features/support/env.rb
72
77
  - features/unknown_app_framework.feature
73
78
  - spec/spec_helper.rb
@@ -86,6 +91,7 @@ files:
86
91
  - spec/support/fake_framework.rb
87
92
  - spec/support/fake_run_strategy.rb
88
93
  - bin/spork
94
+ - ext/mkrf_conf.rb
89
95
  has_rdoc: true
90
96
  homepage: http://github.com/timcharper/spork
91
97
  licenses: []
@@ -117,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
123
  requirements: []
118
124
 
119
125
  rubyforge_project: spork
120
- rubygems_version: 1.5.0
126
+ rubygems_version: 1.3.7
121
127
  signing_key:
122
128
  specification_version: 3
123
129
  summary: spork
@@ -125,6 +131,8 @@ test_files:
125
131
  - features/at_exit_during_each_run.feature
126
132
  - features/cucumber_rails_integration.feature
127
133
  - features/diagnostic_mode.feature
134
+ - features/gemfiles/rails3.0/Gemfile
135
+ - features/gemfiles/rails3.0/Gemfile.lock
128
136
  - features/rails_delayed_loading_workarounds.feature
129
137
  - features/rspec_rails_integration.feature
130
138
  - features/spork_debugger.feature
@@ -132,6 +140,7 @@ test_files:
132
140
  - features/steps/rails_steps.rb
133
141
  - features/steps/sandbox_steps.rb
134
142
  - features/support/background_job.rb
143
+ - features/support/bundler_helpers.rb
135
144
  - features/support/env.rb
136
145
  - features/unknown_app_framework.feature
137
146
  - spec/spec_helper.rb