spork 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'spork'
3
3
 
4
4
  Spork.prefork do
5
- # Loading more in this block will cause your specs to run faster. However,
5
+ # Loading more in this block will cause your tests to run faster. However,
6
6
  # if you change any configuration or code from libraries loaded here, you'll
7
7
  # need to restart spork for it take effect.
8
8
 
@@ -12,6 +12,10 @@ Feature: Cucumber integration with rails
12
12
  require 'spork'
13
13
 
14
14
  Spork.prefork do
15
+ # Loading more in this block will cause your tests to run faster. However,
16
+ # if you change any configuration or code from libraries loaded here, you'll
17
+ # need to restart spork for it take effect.
18
+
15
19
  # Sets up the Rails environment for Cucumber
16
20
  ENV['RAILS_ENV'] = "cucumber"
17
21
  require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
@@ -23,18 +27,14 @@ Feature: Cucumber integration with rails
23
27
  end
24
28
 
25
29
  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...
30
+ require 'cucumber'
27
31
  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...
32
+ require 'spec/rails'
29
33
  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
- ($loaded_stuff ||= []) << 'prefork block'
34
+
35
+ # ---- this is for this test only ----
36
+ $loaded_stuff << 'prefork block'
37
+ # ---- end test stuff ----
38
38
  end
39
39
 
40
40
  Spork.each_run do
@@ -43,7 +43,10 @@ Feature: Cucumber integration with rails
43
43
  Cucumber::Rails.use_transactional_fixtures
44
44
  Cucumber::Rails.bypass_rescue # Comment out this line if you want Rails own error handling
45
45
  # (e.g. rescue_action_in_public / rescue_responses / rescue_from)
46
- ($loaded_stuff ||= []) << 'each_run block'
46
+
47
+ # ---- this is for this test only ----
48
+ $loaded_stuff << 'each_run block'
49
+ # ---- end test stuff ----
47
50
  end
48
51
  """
49
52
  And a file named "features/cucumber_rails.feature" with:
@@ -54,14 +57,25 @@ Feature: Cucumber integration with rails
54
57
  """
55
58
  And a file named "features/support/cucumber_rails_helper.rb" with:
56
59
  """
57
- ($loaded_stuff ||= []) << 'features/support/cucumber_rails_helper.rb'
60
+ $loaded_stuff << 'features/support/cucumber_rails_helper.rb'
61
+ """
62
+ And a file named "config/environments/cucumber.rb" with:
63
+ """
64
+ # your cucumber env here
65
+ """
66
+ And a file named "config/database.yml" with:
67
+ """
68
+ cucumber:
69
+ adapter: sqlite3
70
+ database: db/cucumber.sqlite3
71
+ timeout: 5000
58
72
  """
59
73
  And a file named "features/step_definitions/cucumber_rails_steps.rb" with:
60
74
  """
61
75
  Then "it should work" do
62
76
  Spork.state.should == :using_spork
63
77
  RAILS_ENV.should == 'cucumber'
64
- $loaded_stuff.should include('establish_connection')
78
+ $loaded_stuff.should include('ActiveRecord::Base.establish_connection')
65
79
  $loaded_stuff.should include('User')
66
80
  $loaded_stuff.should include('UserObserver')
67
81
  $loaded_stuff.should include('ApplicationHelper')
@@ -72,17 +86,6 @@ Feature: Cucumber integration with rails
72
86
  puts "It worked!"
73
87
  end
74
88
  """
75
- And a file named "config/environments/cucumber.rb" with:
76
- """
77
- $cucumber_used = true
78
- """
79
- And a file named "config/database.yml" with:
80
- """
81
- cucumber:
82
- adapter: sqlite3
83
- database: db/cucumber.sqlite3
84
- timeout: 5000
85
- """
86
89
  Scenario: Analyzing files were preloaded
87
90
  When I run spork --diagnose
88
91
  Then the output should not contain "user_observer.rb"
@@ -0,0 +1,71 @@
1
+ Feature: Rails Delayed Work arounds
2
+ To allow a rails developer to update as many parts of his application as possible without needing to restart Spork
3
+ Spork automatically tells rails to delay loading certain parts of the application until after the fork occurs
4
+ Providing work arounds
5
+
6
+ Background: Rails App with RSpec and Spork
7
+
8
+ Given I am in a fresh rails project named "test_rails_project"
9
+ And a file named "spec/spec_helper.rb" with:
10
+ """
11
+ require 'rubygems'
12
+ require 'spork'
13
+
14
+ Spork.prefork do
15
+ require File.dirname(__FILE__) + '/../config/environment.rb'
16
+ require 'spec'
17
+ require 'spec/rails'
18
+ end
19
+
20
+ Spork.each_run do
21
+ end
22
+ """
23
+ And the application has a model, observer, route, and application helper
24
+ Scenario: within a view, calling helper methods from an included module in ApplicationHelper
25
+ Given a file named "app/helpers/application_helper.rb" with:
26
+ """
27
+ module ApplicationHelper
28
+ include Reverseatron
29
+ end
30
+ """
31
+ Given a file named "lib/reverseatron.rb" with:
32
+ """
33
+ module Reverseatron
34
+ def reverse_text(txt)
35
+ txt.reverse
36
+ end
37
+ end
38
+ """
39
+ Given a file named "app/controllers/users_controller.rb" with:
40
+ """
41
+ class UsersController < ApplicationController
42
+ $loaded_stuff << 'UsersController'
43
+ def index
44
+ @users = []
45
+ end
46
+ end
47
+ """
48
+ Given a file named "app/controllers/users_helper.rb" with:
49
+ """
50
+ module UsersHelper
51
+ end
52
+ """
53
+ Given a file named "app/views/users/index.html.erb" with:
54
+ """
55
+ <%= reverse_text('listing users'.reverse) %>
56
+ """
57
+ Given a file named "spec/controllers/users_controller_spec.rb" with:
58
+ """
59
+ describe UsersController do
60
+ integrate_views
61
+ it "renders a page, using a method inherited from ApplicationController" do
62
+ get :index
63
+ response.body.should include('listing users')
64
+ puts "Controller stack is functioning"
65
+ end
66
+ end
67
+ """
68
+ When I fire up a spork instance with "spork rspec"
69
+ And I run spec --drb spec/controllers/users_controller_spec.rb
70
+ Then the output should contain "Controller stack is functioning"
71
+
@@ -0,0 +1,64 @@
1
+ Feature: Rails Integration
2
+ To get a developer up and running quickly
3
+ Spork automatically integrates with rails
4
+ Providing default hooks and behaviors
5
+
6
+ Background: Rails App with RSpec and Spork
7
+
8
+ Given I am in a fresh rails project named "test_rails_project"
9
+ And a file named "spec/spec_helper.rb" with:
10
+ """
11
+ require 'rubygems'
12
+ require 'spork'
13
+
14
+ Spork.prefork do
15
+ # Loading more in this block will cause your specs to run faster. However,
16
+ # if you change any configuration or code from libraries loaded here, you'll
17
+ # need to restart spork for it take effect.
18
+ require File.dirname(__FILE__) + '/../config/environment.rb'
19
+ require 'spec'
20
+ require 'spec/rails'
21
+
22
+ # ---- this is for this test only ----
23
+ $loaded_stuff << 'prefork block'
24
+ # ---- end test stuff ----
25
+ end
26
+
27
+ Spork.each_run do
28
+ # This code will be run each time you run your specs.
29
+
30
+ # ---- this is for this test only ----
31
+ $loaded_stuff << 'each_run block'
32
+ # ---- end test stuff ----
33
+ end
34
+ """
35
+ And the application has a model, observer, route, and application helper
36
+ Scenario: Analyzing files were preloaded
37
+ When I run spork --diagnose
38
+ Then the output should not contain "user_observer.rb"
39
+ Then the output should not contain "user.rb"
40
+ Then the output should not contain "app/controllers/application.rb"
41
+ Then the output should not contain "app/controllers/application_controller.rb"
42
+ Then the output should not contain "app/controllers/application_helper.rb"
43
+ Then the output should not contain "config/routes.rb"
44
+
45
+ Scenario: Running spork with a rails app and observers
46
+ Given a file named "spec/did_it_work_spec.rb" with:
47
+ """
48
+ describe "Did it work?" do
49
+ it "checks to see if all worked" do
50
+ Spork.state.should == :using_spork
51
+ $loaded_stuff.should include('ActiveRecord::Base.establish_connection')
52
+ $loaded_stuff.should include('User')
53
+ $loaded_stuff.should include('UserObserver')
54
+ $loaded_stuff.should include('ApplicationHelper')
55
+ $loaded_stuff.should include('config/routes.rb')
56
+ $loaded_stuff.should include('each_run block')
57
+ $loaded_stuff.should include('prefork block')
58
+ puts "Specs successfully run within spork, and all initialization files were loaded"
59
+ end
60
+ end
61
+ """
62
+ When I fire up a spork instance with "spork rspec"
63
+ And I run spec --drb spec/did_it_work_spec.rb
64
+ Then the output should contain "Specs successfully run within spork, and all initialization files were loaded"
@@ -11,20 +11,19 @@ Given "the application has a model, observer, route, and application helper" do
11
11
  Given 'a file named "app/models/user.rb" with:',
12
12
  """
13
13
  class User < ActiveRecord::Base
14
- ($loaded_stuff ||= []) << 'User'
14
+ $loaded_stuff << 'User'
15
15
  end
16
16
  """
17
-
18
- Given 'a file named "app/helpers/application_helper.rb" with:',
17
+ Given 'a file named "app/models/user_observer.rb" with:',
19
18
  """
20
- module ApplicationHelper
21
- ($loaded_stuff ||= []) << 'ApplicationHelper'
19
+ class UserObserver < ActiveRecord::Observer
20
+ $loaded_stuff << 'UserObserver'
22
21
  end
23
22
  """
24
- Given 'a file named "app/models/user_observer.rb" with:',
23
+ Given 'a file named "app/helpers/application_helper.rb" with:',
25
24
  """
26
- class UserObserver < ActiveRecord::Observer
27
- ($loaded_stuff ||= []) << 'UserObserver'
25
+ module ApplicationHelper
26
+ $loaded_stuff << 'ApplicationHelper'
28
27
  end
29
28
  """
30
29
  Given 'the following code appears in "config/environment.rb" after /Rails::Initializer.run/:',
@@ -33,6 +32,22 @@ Given "the application has a model, observer, route, and application helper" do
33
32
  """
34
33
  Given 'the following code appears in "config/routes.rb" after /^end/:',
35
34
  """
36
- ($loaded_stuff ||= []) << 'config/routes.rb'
35
+ $loaded_stuff << 'config/routes.rb'
36
+ """
37
+ Given 'a file named "config/initializers/initialize_loaded_stuff.rb" with:',
38
+ """
39
+ $loaded_stuff ||= []
40
+ """
41
+ Given 'a file named "config/initializers/log_establish_connection_calls.rb" with:',
42
+ """
43
+ class ActiveRecord::Base
44
+ class << self
45
+ def establish_connection_with_load_logging(*args)
46
+ establish_connection_without_load_logging(*args)
47
+ $loaded_stuff << 'ActiveRecord::Base.establish_connection'
48
+ end
49
+ alias_method_chain :establish_connection, :load_logging
50
+ end
51
+ end
37
52
  """
38
53
  end
@@ -56,6 +56,8 @@ class Spork::AppFramework::Rails < Spork::AppFramework
56
56
  Spork.each_run do
57
57
  require application_controller_source
58
58
  require application_helper_source if File.exist?(application_helper_source)
59
+ # update the rails magic to refresh the module
60
+ ApplicationController.send(:helper, ApplicationHelper)
59
61
  end
60
62
  end
61
63
  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.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Harper
@@ -29,7 +29,8 @@ files:
29
29
  - assets/bootstrap.rb
30
30
  - features/cucumber_rails_integration.feature
31
31
  - features/diagnostic_mode.feature
32
- - features/rails_integration.feature
32
+ - features/rails_delayed_loading_workarounds.feature
33
+ - features/rspec_rails_integration.feature
33
34
  - features/steps/rails_steps.rb
34
35
  - features/steps/sandbox_steps.rb
35
36
  - features/support/env.rb
@@ -1,78 +0,0 @@
1
- Feature: Rails Integration
2
- To get a developer up and running quickly
3
- Spork automatically integrates with rails
4
- Providing default hooks and behaviors
5
-
6
- Background: Rails App with RSpec and Spork
7
-
8
- Given I am in a fresh rails project named "test_rails_project"
9
- And a file named "spec/spec_helper.rb" with:
10
- """
11
- require 'rubygems'
12
- require 'spork'
13
- require 'spec'
14
-
15
- Spork.prefork do
16
- ENV["RAILS_ENV"] = "testeroni"
17
- $run_phase = :prefork
18
- ($loaded_stuff ||= []) << 'prefork block'
19
- require File.dirname(__FILE__) + '/../config/environment.rb'
20
- end
21
-
22
- Spork.each_run do
23
- $run_phase = :each_run
24
- ($loaded_stuff ||= []) << 'each_run block'
25
- puts "I'm loading the stuff just for this run..."
26
- end
27
-
28
- class ActiveRecord::Base
29
- class << self
30
- def establish_connection
31
- ($loaded_stuff ||= []) << 'establish_connection'
32
- end
33
- end
34
- end
35
- """
36
- And the application has a model, observer, route, and application helper
37
- And a file named "config/environments/testeroni.rb" with:
38
- """
39
- $testeroni_used = true
40
- """
41
- And a file named "config/database.yml" with:
42
- """
43
- testeroni:
44
- adapter: sqlite3
45
- database: db/testeroni.sqlite3
46
- timeout: 5000
47
- """
48
- And a file named "spec/did_it_work_spec.rb" with:
49
- """
50
- describe "Did it work?" do
51
- it "checks to see if all worked" do
52
- Spork.state.should == :using_spork
53
- RAILS_ENV.should == 'testeroni'
54
- $loaded_stuff.should include('establish_connection')
55
- $loaded_stuff.should include('User')
56
- $loaded_stuff.should include('UserObserver')
57
- $loaded_stuff.should include('ApplicationHelper')
58
- $loaded_stuff.should include('config/routes.rb')
59
- $loaded_stuff.should include('each_run block')
60
- $loaded_stuff.should include('prefork block')
61
- puts "Specs successfully run within spork, and all initialization files were loaded"
62
- end
63
- end
64
- """
65
- Scenario: Analyzing files were preloaded
66
- When I run spork --diagnose
67
- Then the output should not contain "user_observer.rb"
68
- Then the output should not contain "user.rb"
69
- Then the output should not contain "app/controllers/application.rb"
70
- Then the output should not contain "app/controllers/application_controller.rb"
71
- Then the output should not contain "app/controllers/application_helper.rb"
72
- Then the output should not contain "config/routes.rb"
73
-
74
- Scenario: Running spork with a rails app and observers
75
-
76
- When I fire up a spork instance with "spork rspec"
77
- And I run spec --drb spec/did_it_work_spec.rb
78
- Then the output should contain "Specs successfully run within spork, and all initialization files were loaded"